Created
March 9, 2018 18:53
-
-
Save ntotten/a3d5c69fd322091ab794d3789a6e2ad7 to your computer and use it in GitHub Desktop.
Monaco language definition for apex. Still needs inline SOQL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Language definition for Apex | |
return { | |
// Set defaultToken to invalid to see what you do not tokenize yet | |
// defaultToken: 'invalid', | |
keywords: [ | |
'abstract', 'continue', 'for', 'new', 'switch', 'assert', 'default', | |
'goto', 'package', 'synchronized', 'boolean', 'do', 'if', 'private', | |
'this', 'break', 'double', 'implements', 'protected', 'throw', 'byte', | |
'else', 'import', 'public', 'throws', 'case', 'enum', 'instanceof', 'return', | |
'transient', 'catch', 'extends', 'int', 'short', 'try', 'char', 'final', | |
'interface', 'static', 'void', 'class', 'finally', 'long', 'strictfp', | |
'volatile', 'const', 'float', 'native', 'super', 'while', 'true', 'false', | |
'with', 'sharing', 'without', 'global', 'virtual', 'override', | |
'update', 'insert', 'delete', 'upsert', 'undelete' | |
], | |
typeKeywords: [ | |
'boolean', 'double', 'byte', 'int', 'short', 'char', 'void', 'long', 'float' | |
], | |
operators: [ | |
'=', '>', '<', '!', '~', '?', ':', | |
'==', '<=', '>=', '!=', '&&', '||', '++', '--', | |
'+', '-', '*', '/', '&', '|', '^', '%', '<<', | |
'>>', '>>>', '+=', '-=', '*=', '/=', '&=', '|=', | |
'^=', '%=', '<<=', '>>=', '>>>=' | |
], | |
// we include these common regular expressions | |
symbols: /[=><!~?:&|+\-*\/\^%]+/, | |
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/, | |
// The main tokenizer for our languages | |
tokenizer: { | |
root: [ | |
// identifiers and keywords | |
[/[a-z_$][\w$]*/, { cases: { '@typeKeywords': 'keyword', | |
'@keywords': 'keyword', | |
'@default': 'identifier' } }], | |
[/[A-Z][\w\$]*/, 'type.identifier' ], // to show class names nicely | |
// whitespace | |
{ include: '@whitespace' }, | |
// delimiters and operators | |
[/[{}()\[\]]/, '@brackets'], | |
[/[<>](?!@symbols)/, '@brackets'], | |
[/@symbols/, { cases: { '@operators': 'operator', | |
'@default' : '' } } ], | |
// @ annotations. | |
// As an example, we emit a debugging log message on these tokens. | |
// Note: message are supressed during the first load -- change some lines to see them. | |
[/@\s*[a-zA-Z_\$][\w\$]*/, { token: 'annotation', log: 'annotation token: $0' }], | |
// numbers | |
[/\d*\.\d+([eE][\-+]?\d+)?[fFdD]?/, 'number.float'], | |
[/0[xX][0-9a-fA-F_]*[0-9a-fA-F][Ll]?/, 'number.hex'], | |
[/0[0-7_]*[0-7][Ll]?/, 'number.octal'], | |
[/0[bB][0-1_]*[0-1][Ll]?/, 'number.binary'], | |
[/\d+[lL]?/, 'number'], | |
// delimiter: after number because of .\d floats | |
[/[;,.]/, 'delimiter'], | |
// strings | |
[/"([^"\\]|\\.)*$/, 'string.invalid' ], // non-teminated string | |
[/'([^'\\]|\\.)*$/, 'string.invalid' ], // non-teminated string | |
[/"/, 'string', '@string."' ], | |
[/'/, 'string', '@string.\'' ], | |
], | |
whitespace: [ | |
[/[ \t\r\n]+/, 'white'], | |
[/\/\*/, 'comment', '@comment' ], | |
[/\/\/.*$/, 'comment'], | |
], | |
comment: [ | |
[/[^\/*]+/, 'comment' ], | |
// [/\/\*/, 'comment', '@push' ], // nested comment not allowed :-( | |
[/\/\*/, 'comment.invalid' ], | |
["\\*/", 'comment', '@pop' ], | |
[/[\/*]/, 'comment' ] | |
], | |
string: [ | |
[/[^\\"']+/, 'string'], | |
[/@escapes/, 'string.escape'], | |
[/\\./, 'string.escape.invalid'], | |
[/["']/, { cases: { '$#==$S2' : { token: 'string', next: '@pop' }, | |
'@default': 'string' }} ] | |
], | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cursory observations: