diff --git a/modules/lang-painless/src/main/antlr/PainlessLexer.g4 b/modules/lang-painless/src/main/antlr/PainlessLexer.g4 index 18fdae751af..2d5af7c483a 100644 --- a/modules/lang-painless/src/main/antlr/PainlessLexer.g4 +++ b/modules/lang-painless/src/main/antlr/PainlessLexer.g4 @@ -20,7 +20,15 @@ lexer grammar PainlessLexer; @header { -import org.elasticsearch.painless.Definition; +} + +@members{ + protected boolean isSimpleType(String name) { + throw new UnsupportedOperationException("Must be implemented in a subclass"); + } + protected boolean slashIsRegex() { + throw new UnsupportedOperationException("Must be implemented in a subclass"); + } } WS: [ \t\n\r]+ -> skip; @@ -59,7 +67,7 @@ INSTANCEOF: 'instanceof'; BOOLNOT: '!'; BWNOT: '~'; MUL: '*'; -DIV: '/' { false == SlashStrategy.slashIsRegex(this) }?; +DIV: '/' { false == slashIsRegex() }?; REM: '%'; ADD: '+'; SUB: '-'; @@ -108,7 +116,7 @@ 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]* { SlashStrategy.slashIsRegex(this) }?; +REGEX: '/' ( ~('/' | '\n') | '\\' ~'\n' )+ '/' [cilmsUux]* { slashIsRegex() }?; TRUE: 'true'; FALSE: 'false'; @@ -121,7 +129,7 @@ NULL: 'null'; // or not. Note this works by processing one character at a time // and the rule is added or removed as this happens. This is also known // as "the lexer hack." See (https://en.wikipedia.org/wiki/The_lexer_hack). -TYPE: ID ( DOT ID )* { Definition.isSimpleType(getText()) }?; +TYPE: ID ( DOT ID )* { isSimpleType(getText()) }?; ID: [_a-zA-Z] [_a-zA-Z0-9]*; mode AFTER_DOT; diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/EnhancedPainlessLexer.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/EnhancedPainlessLexer.java index 244c2f38e62..640d9c29b20 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/EnhancedPainlessLexer.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/antlr/EnhancedPainlessLexer.java @@ -26,13 +26,15 @@ import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.TokenSource; import org.antlr.v4.runtime.misc.Interval; import org.antlr.v4.runtime.misc.Pair; +import org.elasticsearch.painless.Definition; import org.elasticsearch.painless.Location; /** * A lexer that is customized for painless. It: *