Skip to content

Commit

Permalink
implement painless error reporting in monaco
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Dec 1, 2020
1 parent 3958cdd commit 9321231
Show file tree
Hide file tree
Showing 24 changed files with 9,326 additions and 9 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ snapshots.js
/packages/kbn-ui-framework/doc_site/build
/packages/kbn-ui-framework/generator-kui/*/templates/
/packages/kbn-ui-shared-deps/flot_charts
/packages/kbn-monaco/src/painless/antlr
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"angular-resource": "1.8.0",
"angular-sanitize": "^1.8.0",
"angular-ui-ace": "0.2.3",
"antlr4ts": "^0.5.0-alpha.3",
"apollo-cache-inmemory": "1.6.2",
"apollo-client": "^2.3.8",
"apollo-link-http": "^1.5.16",
Expand Down Expand Up @@ -576,6 +577,7 @@
"angular-recursion": "^1.0.5",
"angular-route": "^1.8.0",
"angular-sortable-view": "^0.0.17",
"antlr4ts-cli": "^0.5.0-alpha.3",
"apidoc": "^0.25.0",
"apidoc-markdown": "^5.1.8",
"apollo-link": "^1.2.3",
Expand Down
122 changes: 122 additions & 0 deletions packages/kbn-monaco/PainlessLexer.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

lexer grammar PainlessLexer;

WS: [ \t\n\r]+ -> skip;
COMMENT: ( '//' .*? [\n\r] | '/*' .*? '*/' ) -> skip;

LBRACK: '{';
RBRACK: '}';
LBRACE: '[';
RBRACE: ']';
LP: '(';
RP: ')';
// We switch modes after a dot to ensure there are not conflicts
// between shortcuts and decimal values. Without the mode switch
// shortcuts such as id.0.0 will fail because 0.0 will be interpreted
// as a decimal value instead of two individual list-style shortcuts.
DOT: '.' -> mode(AFTER_DOT);
NSDOT: '?.' -> mode(AFTER_DOT);
COMMA: ',';
SEMICOLON: ';';
IF: 'if';
IN: 'in';
ELSE: 'else';
WHILE: 'while';
DO: 'do';
FOR: 'for';
CONTINUE: 'continue';
BREAK: 'break';
RETURN: 'return';
NEW: 'new';
TRY: 'try';
CATCH: 'catch';
THROW: 'throw';
THIS: 'this';
INSTANCEOF: 'instanceof';

BOOLNOT: '!';
BWNOT: '~';
MUL: '*';
DIV: '/' { this.isSlashRegex() == false }?;
REM: '%';
ADD: '+';
SUB: '-';
LSH: '<<';
RSH: '>>';
USH: '>>>';
LT: '<';
LTE: '<=';
GT: '>';
GTE: '>=';
EQ: '==';
EQR: '===';
NE: '!=';
NER: '!==';
BWAND: '&';
XOR: '^';
BWOR: '|';
BOOLAND: '&&';
BOOLOR: '||';
COND: '?';
COLON: ':';
ELVIS: '?:';
REF: '::';
ARROW: '->';
FIND: '=~';
MATCH: '==~';
INCR: '++';
DECR: '--';

ASSIGN: '=';
AADD: '+=';
ASUB: '-=';
AMUL: '*=';
ADIV: '/=';
AREM: '%=';
AAND: '&=';
AXOR: '^=';
AOR: '|=';
ALSH: '<<=';
ARSH: '>>=';
AUSH: '>>>=';

OCTAL: '0' [0-7]+ [lL]?;
HEX: '0' [xX] [0-9a-fA-F]+ [lL]?;
INTEGER: ( '0' | [1-9] [0-9]* ) [lLfFdD]?;
DECIMAL: ( '0' | [1-9] [0-9]* ) (DOT [0-9]+)? ( [eE] [+\-]? [0-9]+ )? [fFdD]?;

STRING: ( '"' ( '\\"' | '\\\\' | ~[\\"] )*? '"' ) | ( '\'' ( '\\\'' | '\\\\' | ~[\\'] )*? '\'' );
REGEX: '/' ( '\\' ~'\n' | ~('/' | '\n') )+? '/' [cilmsUux]* { this.isSlashRegex() }?;

TRUE: 'true';
FALSE: 'false';

NULL: 'null';

PRIMITIVE: 'boolean' | 'byte' | 'short' | 'char' | 'int' | 'long' | 'float' | 'double';
DEF: 'def';

ID: [_a-zA-Z] [_a-zA-Z0-9]*;

mode AFTER_DOT;

DOTINTEGER: ( '0' | [1-9] [0-9]* ) -> mode(DEFAULT_MODE);
DOTID: [_a-zA-Z] [_a-zA-Z0-9]* -> mode(DEFAULT_MODE);
158 changes: 158 additions & 0 deletions packages/kbn-monaco/PainlessLexer.tokens
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
WS=1
COMMENT=2
LBRACK=3
RBRACK=4
LBRACE=5
RBRACE=6
LP=7
RP=8
DOT=9
NSDOT=10
COMMA=11
SEMICOLON=12
IF=13
IN=14
ELSE=15
WHILE=16
DO=17
FOR=18
CONTINUE=19
BREAK=20
RETURN=21
NEW=22
TRY=23
CATCH=24
THROW=25
THIS=26
INSTANCEOF=27
BOOLNOT=28
BWNOT=29
MUL=30
DIV=31
REM=32
ADD=33
SUB=34
LSH=35
RSH=36
USH=37
LT=38
LTE=39
GT=40
GTE=41
EQ=42
EQR=43
NE=44
NER=45
BWAND=46
XOR=47
BWOR=48
BOOLAND=49
BOOLOR=50
COND=51
COLON=52
ELVIS=53
REF=54
ARROW=55
FIND=56
MATCH=57
INCR=58
DECR=59
ASSIGN=60
AADD=61
ASUB=62
AMUL=63
ADIV=64
AREM=65
AAND=66
AXOR=67
AOR=68
ALSH=69
ARSH=70
AUSH=71
OCTAL=72
HEX=73
INTEGER=74
DECIMAL=75
STRING=76
REGEX=77
TRUE=78
FALSE=79
NULL=80
PRIMITIVE=81
DEF=82
ID=83
DOTINTEGER=84
DOTID=85
'{'=3
'}'=4
'['=5
']'=6
'('=7
')'=8
'.'=9
'?.'=10
','=11
';'=12
'if'=13
'in'=14
'else'=15
'while'=16
'do'=17
'for'=18
'continue'=19
'break'=20
'return'=21
'new'=22
'try'=23
'catch'=24
'throw'=25
'this'=26
'instanceof'=27
'!'=28
'~'=29
'*'=30
'/'=31
'%'=32
'+'=33
'-'=34
'<<'=35
'>>'=36
'>>>'=37
'<'=38
'<='=39
'>'=40
'>='=41
'=='=42
'==='=43
'!='=44
'!=='=45
'&'=46
'^'=47
'|'=48
'&&'=49
'||'=50
'?'=51
':'=52
'?:'=53
'::'=54
'->'=55
'=~'=56
'==~'=57
'++'=58
'--'=59
'='=60
'+='=61
'-='=62
'*='=63
'/='=64
'%='=65
'&='=66
'^='=67
'|='=68
'<<='=69
'>>='=70
'>>>='=71
'true'=78
'false'=79
'null'=80
'def'=82
Loading

0 comments on commit 9321231

Please sign in to comment.