diff --git a/build.bat b/build.bat new file mode 100644 index 0000000000..9cc6754065 --- /dev/null +++ b/build.bat @@ -0,0 +1 @@ +node tools/build.js -t browser diff --git a/src/languages/csharp.js b/src/languages/csharp.js index 5201903356..b652bff9b1 100644 --- a/src/languages/csharp.js +++ b/src/languages/csharp.js @@ -124,6 +124,7 @@ export default function(hljs) { 'descending', 'dynamic', 'equals', + 'field', 'file', 'from', 'get', @@ -152,7 +153,13 @@ export default function(hljs) { 'when', 'where', 'with', - 'yield' + 'yield', + '__arglist', + '__makeref', + '__reftype', + '__refvalue', + 'module', + 'assembly' ]; const KEYWORDS = { @@ -266,10 +273,7 @@ export default function(hljs) { return { name: 'C#', - aliases: [ - 'cs', - 'c#' - ], + aliases: ['cs', 'c#'], keywords: KEYWORDS, illegal: /::/, contains: [ diff --git a/src/languages/gold.js b/src/languages/gold.js new file mode 100644 index 0000000000..c2a8dc0c4c --- /dev/null +++ b/src/languages/gold.js @@ -0,0 +1,153 @@ +/* +Language: Gold +Author: Carlo Kok +Contributor: Stephan Kountso aka StepLg , Evgeny Stepanischev +Description: Gold is RemObjects Software's Go-compatible language for the Elements compiler. +Website: https://www.elementscompiler.com/elements/gold/ +*/ + +export default function(hljs) { + const LITERALS = [ + "true", + "false", + "iota", + "nil" + ]; + const BUILT_INS = [ + "append", + "cap", + "close", + "complex", + "copy", + "imag", + "len", + "make", + "new", + "panic", + "print", + "println", + "real", + "recover", + "delete" + ]; + const TYPES = [ + "bool", + "byte", + "complex64", + "complex128", + "error", + "float32", + "float64", + "int8", + "int16", + "int32", + "int64", + "string", + "uint8", + "uint16", + "uint32", + "uint64", + "int", + "uint", + "uintptr", + "rune" + ]; + const KWS = [ + "break", + "case", + "chan", + "const", + "continue", + "default", + "defer", + "else", + "fallthrough", + "for", + "func", + "go", + "goto", + "if", + "import", + "interface", + "map", + "package", + "range", + "return", + "select", + "struct", + "switch", + "type", + "var", + ]; + const KEYWORDS = { + keyword: KWS, + type: TYPES, + literal: LITERALS, + built_in: BUILT_INS + }; + return { + name: 'Gold', + aliases: ['gold'], + keywords: KEYWORDS, + illegal: ' +Contributor: Jason Diamond , Nicolas LLOBERA , Pieter Vantorre , David Pine +Description: Hydrogene is RemObjects Software's C#-compatible language for the Elements compiler, with additional platform-specific extensions. +Website: https://www.elementscompiler.com/elements/hydrogene/ +*/ + +/** @type LanguageFn */ +export default function(hljs) { + const BUILT_IN_KEYWORDS = [ + 'bool', + 'byte', + 'char', + 'decimal', + 'delegate', + 'double', + 'dynamic', + 'enum', + 'float', + 'int', + 'long', + 'nint', + 'nuint', + 'object', + 'sbyte', + 'short', + 'string', + 'ulong', + 'uint', + 'ushort' + ]; + const FUNCTION_MODIFIERS = [ + 'public', + 'private', + 'protected', + 'static', + 'internal', + 'protected', + 'abstract', + 'async', + 'extern', + 'override', + 'unsafe', + 'virtual', + 'new', + 'sealed', + 'partial' + ]; + const LITERAL_KEYWORDS = [ + 'default', + 'false', + 'null', + 'true' + ]; + const NORMAL_KEYWORDS = [ + 'abstract', + 'as', + 'base', + 'break', + 'case', + 'catch', + 'class', + 'const', + 'continue', + 'do', + 'else', + 'event', + 'explicit', + 'extern', + 'finally', + 'fixed', + 'for', + 'foreach', + 'goto', + 'if', + 'implicit', + 'in', + 'interface', + 'internal', + 'is', + 'lock', + 'namespace', + 'new', + 'operator', + 'out', + 'override', + 'params', + 'private', + 'protected', + 'public', + 'readonly', + 'record', + 'ref', + 'return', + 'scoped', + 'sealed', + 'sizeof', + 'stackalloc', + 'static', + 'struct', + 'switch', + 'this', + 'throw', + 'try', + 'typeof', + 'unchecked', + 'unsafe', + 'using', + 'virtual', + 'void', + 'volatile', + 'while' + ]; + const CONTEXTUAL_KEYWORDS = [ + 'add', + 'alias', + 'and', + 'ascending', + 'args', + 'async', + 'await', + 'by', + 'descending', + 'dynamic', + 'equals', + 'field', + 'file', + 'from', + 'get', + 'global', + 'group', + 'init', + 'into', + 'join', + 'let', + 'nameof', + 'not', + 'notnull', + 'on', + 'or', + 'orderby', + 'partial', + 'record', + 'remove', + 'required', + 'scoped', + 'select', + 'set', + 'unmanaged', + 'value|0', + 'var', + 'when', + 'where', + 'with', + 'yield', + '__arglist', + '__makeref', + '__reftype', + '__refvalue', + 'module', + 'assembly' + ]; + // RemObjects Elements-specific extensions + const ELEMENTS_KEYWORDS = [ + '__autoreleasepool', + '__selector', + '__weak', + '__strong', + '__unretained', + '__aspect', + '__mapped', + '__inline', + '__extension', + '__require', + '__ensure', + '__result', + '__old', + '__invariants' + ]; + + const KEYWORDS = { + keyword: NORMAL_KEYWORDS.concat(CONTEXTUAL_KEYWORDS).concat(ELEMENTS_KEYWORDS), + built_in: BUILT_IN_KEYWORDS, + literal: LITERAL_KEYWORDS + }; + const TITLE_MODE = hljs.inherit(hljs.TITLE_MODE, { + begin: '[a-zA-Z](\\.?\\w)*' + }); + const NUMBERS = { + className: 'number', + variants: [ + { + begin: '\\b(0b[01\']+)' + }, + { + begin: '(-?)\\b([\\d\']+(\\.[\\d\']*)?|\\.[\\d\']+)(u|U|l|L|ul|UL|f|F|b|B)' + }, + { + begin: '(-?)(\\b0[xX][a-fA-F0-9\']+|(\\b[\\d\']+(\\.[\\d\']*)?|\\.[\\d\']+)([eE][-+]?[\\d\']+)?)' + } + ], + relevance: 0 + }; + const RAW_STRING = { + className: 'string', + begin: /"""("*)(?!")(.|\n)*?"""\1/, + relevance: 1 + }; + const VERBATIM_STRING = { + className: 'string', + begin: '@"', + end: '"', + contains: [ + { + begin: '""' + } + ] + }; + const VERBATIM_STRING_NO_LF = hljs.inherit(VERBATIM_STRING, { + illegal: /\n/ + }); + const SUBST = { + className: 'subst', + begin: /\{/, + end: /\}/, + keywords: KEYWORDS + }; + const SUBST_NO_LF = hljs.inherit(SUBST, { + illegal: /\n/ + }); + const INTERPOLATED_STRING = { + className: 'string', + begin: /\$"/, + end: '"', + illegal: /\n/, + contains: [ + { + begin: /\{\{/ + }, + { + begin: /\}\}/ + }, + hljs.BACKSLASH_ESCAPE, + SUBST_NO_LF + ] + }; + const INTERPOLATED_VERBATIM_STRING = { + className: 'string', + begin: /\$@"/, + end: '"', + contains: [ + { + begin: /\{\{/ + }, + { + begin: /\}\}/ + }, + { + begin: '""' + }, + SUBST + ] + }; + const INTERPOLATED_VERBATIM_STRING_NO_LF = hljs.inherit(INTERPOLATED_VERBATIM_STRING, { + illegal: /\n/, + contains: [ + { + begin: /\{\{/ + }, + { + begin: /\}\}/ + }, + { + begin: '""' + }, + SUBST_NO_LF + ] + }); + SUBST.contains = [ + INTERPOLATED_VERBATIM_STRING, + INTERPOLATED_STRING, + VERBATIM_STRING, + hljs.APOS_STRING_MODE, + hljs.QUOTE_STRING_MODE, + NUMBERS, + hljs.C_BLOCK_COMMENT_MODE + ]; + SUBST_NO_LF.contains = [ + INTERPOLATED_VERBATIM_STRING_NO_LF, + INTERPOLATED_STRING, + VERBATIM_STRING_NO_LF, + hljs.APOS_STRING_MODE, + hljs.QUOTE_STRING_MODE, + NUMBERS, + hljs.inherit(hljs.C_BLOCK_COMMENT_MODE, { + illegal: /\n/ + }) + ]; + const STRING = { + variants: [ + RAW_STRING, + INTERPOLATED_VERBATIM_STRING, + INTERPOLATED_STRING, + VERBATIM_STRING, + hljs.APOS_STRING_MODE, + hljs.QUOTE_STRING_MODE + ] + }; + + const GENERIC_MODIFIER = { + begin: "<", + end: ">", + contains: [ + { + beginKeywords: "in out" + }, + TITLE_MODE + ] + }; + const TYPE_IDENT_RE = hljs.IDENT_RE + '(<' + hljs.IDENT_RE + '(\\s*,\\s*' + hljs.IDENT_RE + ')*>)?(\\[\\])?'; + const AT_IDENTIFIER = { + // prevents expressions like `@class` from incorrect flagging + // `class` as a keyword + begin: "@" + hljs.IDENT_RE, + relevance: 0 + }; + + return { + name: 'Hydrogene', + aliases: ['hydrogene'], + keywords: KEYWORDS, + illegal: /::/, + contains: [ + hljs.COMMENT( + '///', + '$', + { + returnBegin: true, + contains: [ + { + className: 'doctag', + variants: [ + { + begin: '///', + relevance: 0 + }, + { + begin: '' + }, + { + begin: '' + } + ] + } + ] + } + ), + hljs.C_LINE_COMMENT_MODE, + hljs.C_BLOCK_COMMENT_MODE, + { + className: 'meta', + begin: '#', + end: '$', + keywords: { + keyword: 'if else elif endif define undef warning error line region endregion pragma checksum' + } + }, + STRING, + NUMBERS, + { + beginKeywords: 'class interface', + relevance: 0, + end: /[{;=]/, + illegal: /[^\s:,]/, + contains: [ + { + beginKeywords: "where class" + }, + TITLE_MODE, + GENERIC_MODIFIER, + hljs.C_LINE_COMMENT_MODE, + hljs.C_BLOCK_COMMENT_MODE + ] + }, + { + beginKeywords: 'namespace', + relevance: 0, + end: /[{;=]/, + illegal: /[^\s:]/, + contains: [ + TITLE_MODE, + hljs.C_LINE_COMMENT_MODE, + hljs.C_BLOCK_COMMENT_MODE + ] + }, + { + beginKeywords: 'record', + relevance: 0, + end: /[{;=]/, + illegal: /[^\s:]/, + contains: [ + TITLE_MODE, + GENERIC_MODIFIER, + hljs.C_LINE_COMMENT_MODE, + hljs.C_BLOCK_COMMENT_MODE + ] + }, + { + // [Attributes("")] + className: 'meta', + begin: '^\\s*\\[(?=[\\w])', + excludeBegin: true, + end: '\\]', + excludeEnd: true, + contains: [ + { + className: 'string', + begin: /"/, + end: /"/ + } + ] + }, + { + // Expression keywords prevent 'keyword Name(...)' from being + // recognized as a function definition + beginKeywords: 'new return throw await else', + relevance: 0 + }, + { + className: 'function', + begin: '(' + TYPE_IDENT_RE + '\\s+)+' + hljs.IDENT_RE + '\\s*(<[^=]+>\\s*)?\\(', + returnBegin: true, + end: /\s*[{;=]/, + excludeEnd: true, + keywords: KEYWORDS, + contains: [ + // prevents these from being highlighted `title` + { + beginKeywords: FUNCTION_MODIFIERS.join(" "), + relevance: 0 + }, + { + begin: hljs.IDENT_RE + '\\s*(<[^=]+>\\s*)?\\(', + returnBegin: true, + contains: [ + hljs.TITLE_MODE, + GENERIC_MODIFIER + ], + relevance: 0 + }, + { + match: /\(\)/ + }, + { + className: 'params', + begin: /\(/, + end: /\)/, + excludeBegin: true, + excludeEnd: true, + keywords: KEYWORDS, + relevance: 0, + contains: [ + STRING, + NUMBERS, + hljs.C_BLOCK_COMMENT_MODE + ] + }, + hljs.C_LINE_COMMENT_MODE, + hljs.C_BLOCK_COMMENT_MODE + ] + }, + AT_IDENTIFIER + ] + }; +} diff --git a/src/languages/iodine.js b/src/languages/iodine.js new file mode 100644 index 0000000000..2d2c731105 --- /dev/null +++ b/src/languages/iodine.js @@ -0,0 +1,284 @@ +/* +Language: Iodine +Author: Carlo Kok +Contributor: Vsevolod Solovyov +Description: Iodine is RemObjects Software's Java-compatible language for the Elements compiler. +Website: https://www.elementscompiler.com/elements/iodine/ +*/ + +import { NUMERIC as NUMBER } from "./lib/java.js"; + +/** + * Allows recursive regex expressions to a given depth + * + * ie: recurRegex("(abc~~~)", /~~~/g, 2) becomes: + * (abc(abc(abc))) + * + * @param {string} re + * @param {RegExp} substitution (should be a g mode regex) + * @param {number} depth + * @returns {string}`` + */ +function recurRegex(re, substitution, depth) { + if (depth === -1) return ""; + + return re.replace(substitution, _ => { + return recurRegex(re, substitution, depth - 1); + }); +} + +/** @type LanguageFn */ +export default function(hljs) { + const regex = hljs.regex; + const JAVA_IDENT_RE = '[\u00C0-\u02B8a-zA-Z_$][\u00C0-\u02B8a-zA-Z_$0-9]*'; + const GENERIC_IDENT_RE = JAVA_IDENT_RE + + recurRegex('(?:<' + JAVA_IDENT_RE + '~~~(?:\\s*,\\s*' + JAVA_IDENT_RE + '~~~)*>)?', /~~~/g, 2); + const MAIN_KEYWORDS = [ + 'synchronized', + 'abstract', + 'private', + 'var', + 'static', + 'if', + 'const ', + 'for', + 'while', + 'strictfp', + 'finally', + 'protected', + 'import', + 'native', + 'final', + 'void', + 'enum', + 'else', + 'break', + 'transient', + 'catch', + 'instanceof', + 'volatile', + 'case', + 'assert', + 'package', + 'default', + 'public', + 'try', + 'switch', + 'continue', + 'throws', + 'protected', + 'public', + 'private', + 'module', + 'requires', + 'exports', + 'do', + 'sealed', + 'yield', + 'permits', + 'goto', + 'when' + ]; + // RemObjects Elements-specific extensions + const ELEMENTS_KEYWORDS = [ + '__aspect', + '__assembly', + '__module', + '__extension', + '__partial', + '__out', + '__ref', + '__struct', + '__mapped', + '__get', + '__set', + '__block', + '__strong', + '__weak', + '__unretained', + '__selector', + '__require', + '__ensure', + '__result', + '__old', + '__invariants', + '__autoreleasepool', + '__event', + '__add', + '__remove' + ]; + + const BUILT_INS = [ + 'super', + 'this' + ]; + + const LITERALS = [ + 'false', + 'true', + 'null' + ]; + + const TYPES = [ + 'char', + 'boolean', + 'long', + 'float', + 'int', + 'byte', + 'short', + 'double' + ]; + + const KEYWORDS = { + keyword: MAIN_KEYWORDS.concat(ELEMENTS_KEYWORDS), + literal: LITERALS, + type: TYPES, + built_in: BUILT_INS + }; + + const ANNOTATION = { + className: 'meta', + begin: '@' + JAVA_IDENT_RE, + contains: [ + { + begin: /\(/, + end: /\)/, + contains: [ "self" ] // allow nested () inside our annotation + } + ] + }; + const PARAMS = { + className: 'params', + begin: /\(/, + end: /\)/, + keywords: KEYWORDS, + relevance: 0, + contains: [ hljs.C_BLOCK_COMMENT_MODE ], + endsParent: true + }; + + return { + name: 'Iodine', + aliases: ['iodine'], + keywords: KEYWORDS, + illegal: /<\/|#/, + contains: [ + hljs.COMMENT( + '/\\*\\*', + '\\*/', + { + relevance: 0, + contains: [ + { + // eat up @'s in emails to prevent them to be recognized as doctags + begin: /\w+@/, + relevance: 0 + }, + { + className: 'doctag', + begin: '@[A-Za-z]+' + } + ] + } + ), + // relevance boost + { + begin: /import java\.[a-z]+\./, + keywords: "import", + relevance: 2 + }, + hljs.C_LINE_COMMENT_MODE, + hljs.C_BLOCK_COMMENT_MODE, + { + begin: /"""/, + end: /"""/, + className: "string", + contains: [ hljs.BACKSLASH_ESCAPE ] + }, + hljs.APOS_STRING_MODE, + hljs.QUOTE_STRING_MODE, + { + match: [ + /\b(?:class|interface|enum|extends|implements|new)/, + /\s+/, + JAVA_IDENT_RE + ], + className: { + 1: "keyword", + 3: "title.class" + } + }, + { + // Exceptions for hyphenated keywords + match: /non-sealed/, + scope: "keyword" + }, + { + begin: [ + regex.concat(/(?!else)/, JAVA_IDENT_RE), + /\s+/, + JAVA_IDENT_RE, + /\s+/, + /=(?!=)/ + ], + className: { + 1: "type", + 3: "variable", + 5: "operator" + } + }, + { + begin: [ + /record/, + /\s+/, + JAVA_IDENT_RE + ], + className: { + 1: "keyword", + 3: "title.class" + }, + contains: [ + PARAMS, + hljs.C_LINE_COMMENT_MODE, + hljs.C_BLOCK_COMMENT_MODE + ] + }, + { + // Expression keywords prevent 'keyword Name(...)' from being + // recognized as a function definition + beginKeywords: 'new throw return else', + relevance: 0 + }, + { + begin: [ + '(?:' + GENERIC_IDENT_RE + '\\s+)', + hljs.UNDERSCORE_IDENT_RE, + /\s*(?=\()/ + ], + className: { 2: "title.function" }, + keywords: KEYWORDS, + contains: [ + { + className: 'params', + begin: /\(/, + end: /\)/, + keywords: KEYWORDS, + relevance: 0, + contains: [ + ANNOTATION, + hljs.APOS_STRING_MODE, + hljs.QUOTE_STRING_MODE, + NUMBER, + hljs.C_BLOCK_COMMENT_MODE + ] + }, + hljs.C_LINE_COMMENT_MODE, + hljs.C_BLOCK_COMMENT_MODE + ] + }, + NUMBER, + ANNOTATION + ] + }; +} diff --git a/src/languages/java.js b/src/languages/java.js index b826eb94cf..b5ed310f05 100644 --- a/src/languages/java.js +++ b/src/languages/java.js @@ -131,7 +131,7 @@ export default function(hljs) { return { name: 'Java', - aliases: [ 'jsp' ], + aliases: ['jsp'], keywords: KEYWORDS, illegal: /<\/|#/, contains: [ diff --git a/src/languages/lib/kws_swift.js b/src/languages/lib/kws_swift.js index e2932bbb90..cc89043f25 100644 --- a/src/languages/lib/kws_swift.js +++ b/src/languages/lib/kws_swift.js @@ -32,6 +32,8 @@ export const keywords = [ // strings below will be fed into the regular `keywords` engine while regex // will result in additional modes being created to scan for those keywords to // avoid conflicts with other rules + '__abstract', '__await', '__catch', '__COLUMN__', '__event', '__external', '__FILE__',, '__ensure', '__field', '__invariants', '__lock', '__old', '__reintroduce', '__require__result', '__using', + '__finally', '__FUNCTION__', '__inline', '__LINE__', '__mapped', '__out', '__partial', '__throw', '__try', '__yield', 'as', 'as!', 'as?', 'associativity', 'actor', 'any', // contextual 'associatedtype', diff --git a/src/languages/oxygene.js b/src/languages/oxygene.js index 5d2f797b9e..d680953cd1 100644 --- a/src/languages/oxygene.js +++ b/src/languages/oxygene.js @@ -6,18 +6,11 @@ Website: https://www.elementscompiler.com/elements/default.aspx Category: build-system */ -export default function(hljs) { +export default function (hljs) { const OXYGENE_KEYWORDS = { $pattern: /\.?\w+/, keyword: - 'abstract add and array as asc aspect assembly async begin break block by case class concat const copy constructor continue ' - + 'create default delegate desc distinct div do downto dynamic each else empty end ensure enum equals event except exit extension external false ' - + 'final finalize finalizer finally flags for forward from function future global group has if implementation implements implies in index inherited ' - + 'inline interface into invariants is iterator join locked locking loop matching method mod module namespace nested new nil not notify nullable of ' - + 'old on operator or order out override parallel params partial pinned private procedure property protected public queryable raise read readonly ' - + 'record reintroduce remove repeat require result reverse sealed select self sequence set shl shr skip static step soft take then to true try tuple ' - + 'type union unit unsafe until uses using var virtual raises volatile where while with write xor yield await mapped deprecated stdcall cdecl pascal ' - + 'register safecall overload library platform reference packed strict published autoreleasepool selector strong weak unretained' + "abstract add and array as asc asm aspect assembly async autoreleasepool await begin block break by case cdecl class const constructor continue copy create default delegate deprecated desc destructor distinct div do downto dynamic each else empty end ensure enum equals event except exit extension external false field final finalization finalize finalizer finally flags for forward from function future global goto group has helper if implementation implements implies in index inherited initialization inline interface into invariants is iterator join lazy library lifetimestrategy locked locking loop mapped matching method mod module namespace nested new nil not notify nullable of old on operator optional or order otherwise out overload override packed parallel param params partial pascal pinned platform private procedure property protected public published queryable raise raises read readonly record reference register reintroduce remove repeat require required result reverse safecall sealed select selector self sequence set shl shr skip soft static stdcall step strict strong take then to true try tuple type unconstrained unit unmanaged unretained unsafe until uses using var virtual volatile weak where while with write xor yield " }; const CURLY_COMMENT = hljs.COMMENT( /\{/, @@ -29,15 +22,38 @@ export default function(hljs) { '\\*\\)', { relevance: 10 } ); + const RAW_STRING = { + className: 'string', + begin: /#+"{2,}/, + end: /"{2,}/ + }; + const INTERPOLATED_DOUBLE_STRING = { + className: 'string', + begin: /\$"/, + end: '"', + contains: [{ begin: '""' }] + }; + const INTERPOLATED_SINGLE_STRING = { + className: 'string', + begin: /\$'/, + end: '\'', + contains: [{ begin: '\'\'' }] + }; + const DOUBLE_STRING = { + className: 'string', + begin: '"', + end: '"', + contains: [{ begin: '""' }] + }; const STRING = { className: 'string', begin: '\'', end: '\'', - contains: [ { begin: '\'\'' } ] + contains: [{ begin: '\'\'' }] }; const CHAR_STRING = { className: 'string', - begin: '(#\\d+)+' + begin: /(#\d+|#\$[0-9a-fA-F]+)+/ }; const FUNCTION = { beginKeywords: 'function constructor destructor procedure method', @@ -51,6 +67,10 @@ export default function(hljs) { end: '\\)', keywords: OXYGENE_KEYWORDS, contains: [ + RAW_STRING, + INTERPOLATED_DOUBLE_STRING, + INTERPOLATED_SINGLE_STRING, + DOUBLE_STRING, STRING, CHAR_STRING ] @@ -70,11 +90,15 @@ export default function(hljs) { name: 'Oxygene', case_insensitive: true, keywords: OXYGENE_KEYWORDS, - illegal: '("|\\$[G-Zg-z]|\\/\\*||->)', + illegal: '(\\$[G-Zg-z]|\\/\\*||->)', contains: [ CURLY_COMMENT, PAREN_COMMENT, hljs.C_LINE_COMMENT_MODE, + RAW_STRING, + INTERPOLATED_DOUBLE_STRING, + INTERPOLATED_SINGLE_STRING, + DOUBLE_STRING, STRING, CHAR_STRING, hljs.NUMBER_MODE, diff --git a/src/languages/swift.js b/src/languages/swift.js index ee1c43553a..50a048c43e 100644 --- a/src/languages/swift.js +++ b/src/languages/swift.js @@ -546,6 +546,7 @@ export default function(hljs) { return { name: 'Swift', + aliases: ['silver'], keywords: KEYWORDS, contains: [ ...COMMENTS, diff --git a/src/languages/vbmercury.js b/src/languages/vbmercury.js new file mode 100644 index 0000000000..e291ca4155 --- /dev/null +++ b/src/languages/vbmercury.js @@ -0,0 +1,172 @@ +/* +Language: Mercury (VB) +Author: Carlo Kok +Contributor: Poren Chiang , Jan Pilzer +Description: Mercury is RemObjects Software's Visual Basic-compatible language for the Elements compiler, with additional platform-specific extensions. +Website: https://www.elementscompiler.com/elements/mercury/ +*/ + +/** @type LanguageFn */ +export default function (hljs) { + const regex = hljs.regex; + /** + * Character Literal + * Either a single character ("a"C) or an escaped double quote (""""C). + */ + const CHARACTER = { + className: 'string', + begin: /"(""|[^/n])"C\b/ + }; + + const STRING = { + className: 'string', + begin: /"/, + end: /"/, + illegal: /\n/, + contains: [ + { + // double quote escape + begin: /""/ + } + ] + }; + + /** Date Literals consist of a date, a time, or both separated by whitespace, surrounded by # */ + const MM_DD_YYYY = /\d{1,2}\/\d{1,2}\/\d{4}/; + const YYYY_MM_DD = /\d{4}-\d{1,2}-\d{1,2}/; + const TIME_12H = /(\d|1[012])(:\d+){0,2} *(AM|PM)/; + const TIME_24H = /\d{1,2}(:\d{1,2}){1,2}/; + const DATE = { + className: 'literal', + variants: [ + { + // #YYYY-MM-DD# (ISO-Date) or #M/D/YYYY# (US-Date) + begin: regex.concat(/# */, regex.either(YYYY_MM_DD, MM_DD_YYYY), / *#/) + }, + { + // #H:mm[:ss]# (24h Time) + begin: regex.concat(/# */, TIME_24H, / *#/) + }, + { + // #h[:mm[:ss]] A# (12h Time) + begin: regex.concat(/# */, TIME_12H, / *#/) + }, + { + // date plus time + begin: regex.concat( + /# */, + regex.either(YYYY_MM_DD, MM_DD_YYYY), + / +/, + regex.either(TIME_12H, TIME_24H), + / *#/ + ) + } + ] + }; + + const NUMBER = { + className: 'number', + relevance: 0, + variants: [ + { + // Float + begin: /\b\d[\d_]*((\.[\d_]+(E[+-]?[\d_]+)?)|(E[+-]?[\d_]+))[RFD@!#]?/ + }, + { + // Integer (base 10) + begin: /\b\d[\d_]*((U?[SIL])|[%&])?/ + }, + { + // Integer (base 16) + begin: /&H[\dA-F_]+((U?[SIL])|[%&])?/ + }, + { + // Integer (base 8) + begin: /&O[0-7_]+((U?[SIL])|[%&])?/ + }, + { + // Integer (base 2) + begin: /&B[01_]+((U?[SIL])|[%&])?/ + } + ] + }; + + const LABEL = { + className: 'label', + begin: /^\w+:/ + }; + + const DOC_COMMENT = hljs.COMMENT(/'''/, /$/, { + contains: [ + { + className: 'doctag', + begin: /<\/?/, + end: />/ + } + ] + }); + + const COMMENT = hljs.COMMENT(null, /$/, { + variants: [ + { begin: /'/ }, + { + // TODO: Use multi-class for leading spaces + begin: /([\t ]|^)REM(?=\s)/ + } + ] + }); + + const DIRECTIVES = { + className: 'meta', + // TODO: Use multi-class for indentation once available + begin: /[\t ]*#(const|disable|else|elseif|enable|end|externalsource|if|region)\b/, + end: /$/, + keywords: { + keyword: + 'const disable else elseif enable end externalsource if region then' + }, + contains: [COMMENT] + }; + + return { + name: 'Mercury', + aliases: ['vbmercury'], + case_insensitive: true, + classNameAliases: { label: 'symbol' }, + keywords: { + keyword: + 'addhandler alias aggregate ansi as ascending async assembly auto autoreleasepool binary by byref byval ' /* a-b */ + + 'call case catch check class compare const continue custom declare default delegate descending dim distinct do dynamic ' /* c-d */ + + 'each ensure equals else elseif end enum erase error event exit explicit extends finally for friend from function ' /* e-f */ + + 'get global goto group handles if implements imports in index inherits interface into invariants iterator ' /* g-i */ + + 'join key lazy let lib like long loop mappedto matching me mid mod module mustinherit mustoverride mybase myclass mymapped ' /* j-m */ + + 'namespace narrowing new next notinheritable notoverridable ' /* n */ + + 'of off old on operator option optional or order orelse out overloads overridable overrides ' /* o */ + + 'paramarray partial preserve private property protected ptr public ' /* p */ + + 'raiseevent readonly record redim removehandler require resume return ' /* r */ + + 'select set shadows shared skip static step stop structure strict sub synclock ' /* s */ + + 'take text then throw to try unicode unmanaged unsafe until using when where while widening with withevents writeonly yield zip' /* t-z */, + built_in: + // Operators https://docs.microsoft.com/dotnet/visual-basic/language-reference/operators + 'addressof and andalso await directcast gettype getxmlnamespace is isfalse isnot istrue like mod nameof new not or orelse trycast typeof xor ' + // Type Conversion Functions https://docs.microsoft.com/dotnet/visual-basic/language-reference/functions/type-conversion-functions + + 'cbool cbyte cchar cdate cdbl cdec cint clng cobj csbyte cshort csng cstr cuint culng cushort', + type: + // Data types https://docs.microsoft.com/dotnet/visual-basic/language-reference/data-types + 'boolean byte char date decimal double integer long object sbyte short single string uinteger ulong ushort', + literal: 'true false nothing' + }, + illegal: + '//|\\{|\\}|endif|gosub|variant|wend|^\\$ ' /* reserved deprecated keywords */, + contains: [ + CHARACTER, + STRING, + DATE, + NUMBER, + LABEL, + DOC_COMMENT, + COMMENT, + DIRECTIVES + ] + }; +} diff --git a/src/languages/vbnet.js b/src/languages/vbnet.js index 3dcd276a62..1a649b9004 100644 --- a/src/languages/vbnet.js +++ b/src/languages/vbnet.js @@ -7,7 +7,7 @@ Category: common */ /** @type LanguageFn */ -export default function(hljs) { +export default function (hljs) { const regex = hljs.regex; /** * Character Literal @@ -26,7 +26,8 @@ export default function(hljs) { contains: [ { // double quote escape - begin: /""/ } + begin: /""/ + } ] }; @@ -40,13 +41,16 @@ export default function(hljs) { variants: [ { // #YYYY-MM-DD# (ISO-Date) or #M/D/YYYY# (US-Date) - begin: regex.concat(/# */, regex.either(YYYY_MM_DD, MM_DD_YYYY), / *#/) }, + begin: regex.concat(/# */, regex.either(YYYY_MM_DD, MM_DD_YYYY), / *#/) + }, { // #H:mm[:ss]# (24h Time) - begin: regex.concat(/# */, TIME_24H, / *#/) }, + begin: regex.concat(/# */, TIME_24H, / *#/) + }, { // #h[:mm[:ss]] A# (12h Time) - begin: regex.concat(/# */, TIME_12H, / *#/) }, + begin: regex.concat(/# */, TIME_12H, / *#/) + }, { // date plus time begin: regex.concat( @@ -55,7 +59,8 @@ export default function(hljs) { / +/, regex.either(TIME_12H, TIME_24H), / *#/ - ) } + ) + } ] }; @@ -65,19 +70,24 @@ export default function(hljs) { variants: [ { // Float - begin: /\b\d[\d_]*((\.[\d_]+(E[+-]?[\d_]+)?)|(E[+-]?[\d_]+))[RFD@!#]?/ }, + begin: /\b\d[\d_]*((\.[\d_]+(E[+-]?[\d_]+)?)|(E[+-]?[\d_]+))[RFD@!#]?/ + }, { // Integer (base 10) - begin: /\b\d[\d_]*((U?[SIL])|[%&])?/ }, + begin: /\b\d[\d_]*((U?[SIL])|[%&])?/ + }, { // Integer (base 16) - begin: /&H[\dA-F_]+((U?[SIL])|[%&])?/ }, + begin: /&H[\dA-F_]+((U?[SIL])|[%&])?/ + }, { // Integer (base 8) - begin: /&O[0-7_]+((U?[SIL])|[%&])?/ }, + begin: /&O[0-7_]+((U?[SIL])|[%&])?/ + }, { // Integer (base 2) - begin: /&B[01_]+((U?[SIL])|[%&])?/ } + begin: /&B[01_]+((U?[SIL])|[%&])?/ + } ] }; @@ -86,34 +96,41 @@ export default function(hljs) { begin: /^\w+:/ }; - const DOC_COMMENT = hljs.COMMENT(/'''/, /$/, { contains: [ - { - className: 'doctag', - begin: /<\/?/, - end: />/ - } - ] }); + const DOC_COMMENT = hljs.COMMENT(/'''/, /$/, { + contains: [ + { + className: 'doctag', + begin: /<\/?/, + end: />/ + } + ] + }); - const COMMENT = hljs.COMMENT(null, /$/, { variants: [ - { begin: /'/ }, - { - // TODO: Use multi-class for leading spaces - begin: /([\t ]|^)REM(?=\s)/ } - ] }); + const COMMENT = hljs.COMMENT(null, /$/, { + variants: [ + { begin: /'/ }, + { + // TODO: Use multi-class for leading spaces + begin: /([\t ]|^)REM(?=\s)/ + } + ] + }); const DIRECTIVES = { className: 'meta', // TODO: Use multi-class for indentation once available begin: /[\t ]*#(const|disable|else|elseif|enable|end|externalsource|if|region)\b/, end: /$/, - keywords: { keyword: - 'const disable else elseif enable end externalsource if region then' }, - contains: [ COMMENT ] + keywords: { + keyword: + 'const disable else elseif enable end externalsource if region then' + }, + contains: [COMMENT] }; return { name: 'Visual Basic .NET', - aliases: [ 'vb' ], + aliases: ['vb'], case_insensitive: true, classNameAliases: { label: 'symbol' }, keywords: {