Make lexer abstract
This commit is contained in:
parent
dbb4a2ca6c
commit
bb83c283bb
|
@ -136,6 +136,10 @@
|
||||||
<replaceregexp match="public ((interface|class) \Q@{grammar}\E\w+)" replace="\1" encoding="UTF-8">
|
<replaceregexp match="public ((interface|class) \Q@{grammar}\E\w+)" replace="\1" encoding="UTF-8">
|
||||||
<fileset refid="grammar.fileset"/>
|
<fileset refid="grammar.fileset"/>
|
||||||
</replaceregexp>
|
</replaceregexp>
|
||||||
|
<!-- make the lexer abstract -->
|
||||||
|
<replaceregexp match="(class \Q@{grammar}\ELexer)" replace="abstract \1" encoding="UTF-8">
|
||||||
|
<fileset refid="grammar.fileset"/>
|
||||||
|
</replaceregexp>
|
||||||
<!-- nuke timestamps/filenames in generated files -->
|
<!-- nuke timestamps/filenames in generated files -->
|
||||||
<replaceregexp match="\Q// Generated from \E.*" replace="\/\/ ANTLR GENERATED CODE: DO NOT EDIT" encoding="UTF-8">
|
<replaceregexp match="\Q// Generated from \E.*" replace="\/\/ ANTLR GENERATED CODE: DO NOT EDIT" encoding="UTF-8">
|
||||||
<fileset refid="grammar.fileset"/>
|
<fileset refid="grammar.fileset"/>
|
||||||
|
|
|
@ -23,12 +23,19 @@ lexer grammar PainlessLexer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@members{
|
@members{
|
||||||
protected boolean isSimpleType(String name) {
|
/**
|
||||||
throw new UnsupportedOperationException("Must be implemented in a subclass");
|
* Check against the current whitelist to determine whether a token is a type
|
||||||
}
|
* or not. Called by the {@code TYPE} token defined in {@code PainlessLexer.g4}.
|
||||||
protected boolean slashIsRegex() {
|
* See also
|
||||||
throw new UnsupportedOperationException("Must be implemented in a subclass");
|
* <a href="https://en.wikipedia.org/wiki/The_lexer_hack">The lexer hack</a>.
|
||||||
}
|
*/
|
||||||
|
protected abstract boolean isSimpleType(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the preceding {@code /} a the beginning of a regex (true) or a division
|
||||||
|
* (false).
|
||||||
|
*/
|
||||||
|
protected abstract boolean slashIsRegex();
|
||||||
}
|
}
|
||||||
|
|
||||||
WS: [ \t\n\r]+ -> skip;
|
WS: [ \t\n\r]+ -> skip;
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.antlr.v4.runtime.dfa.DFA;
|
||||||
import org.antlr.v4.runtime.misc.*;
|
import org.antlr.v4.runtime.misc.*;
|
||||||
|
|
||||||
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
|
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
|
||||||
class PainlessLexer extends Lexer {
|
abstract class PainlessLexer extends Lexer {
|
||||||
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
|
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
|
||||||
|
|
||||||
protected static final DFA[] _decisionToDFA;
|
protected static final DFA[] _decisionToDFA;
|
||||||
|
@ -105,12 +105,19 @@ class PainlessLexer extends Lexer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected boolean isSimpleType(String name) {
|
/**
|
||||||
throw new UnsupportedOperationException("Must be implemented in a subclass");
|
* Check against the current whitelist to determine whether a token is a type
|
||||||
}
|
* or not. Called by the {@code TYPE} token defined in {@code PainlessLexer.g4}.
|
||||||
protected boolean slashIsRegex() {
|
* See also
|
||||||
throw new UnsupportedOperationException("Must be implemented in a subclass");
|
* <a href="https://en.wikipedia.org/wiki/The_lexer_hack">The lexer hack</a>.
|
||||||
}
|
*/
|
||||||
|
protected abstract boolean isSimpleType(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the preceding {@code /} a the beginning of a regex (true) or a division
|
||||||
|
* (false).
|
||||||
|
*/
|
||||||
|
protected abstract boolean slashIsRegex();
|
||||||
|
|
||||||
|
|
||||||
public PainlessLexer(CharStream input) {
|
public PainlessLexer(CharStream input) {
|
||||||
|
|
Loading…
Reference in New Issue