NOT eval was messed up; handles java lexer now (slowly)

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6905]
This commit is contained in:
parrt 2010-06-08 16:34:07 -08:00
parent 98bddc4446
commit a017bb8feb
8 changed files with 179 additions and 116 deletions

View File

@ -32,6 +32,7 @@ import org.antlr.runtime.IntStream;
import org.antlr.runtime.Token;
import org.antlr.runtime.TokenSource;
import org.antlr.v4.runtime.misc.QStack;
import org.antlr.v4.runtime.pda.Bytecode;
import org.antlr.v4.runtime.pda.PDA;
import java.util.EmptyStackException;
@ -104,7 +105,19 @@ public abstract class Lexer implements TokenSource {
eof.setCharPositionInLine(getCharPositionInLine());
return eof;
}
int ttype = modeToPDA[state.mode].execThompson(state.input);
int ttype = 0;
try {
ttype = modeToPDA[state.mode].execThompson(state.input);
}
catch (PDA.InvalidElement re) {
CharStream cs = (CharStream)state.input;
System.err.println("!!!!! no match for char "+
Bytecode.quotedCharLiteral(state.input.LA(1))+
" at "+state.input.index()+
" line "+cs.getLine()+":"+cs.getCharPositionInLine());
state.input.consume();
continue;
}
if ( state.type == Token.INVALID_TOKEN_TYPE ) state.type = ttype;
if ( state.type==SKIP ) {
continue outer;

View File

@ -1,5 +1,7 @@
package org.antlr.v4.runtime.pda;
import org.antlr.runtime.Token;
import java.util.ArrayList;
import java.util.List;
@ -133,7 +135,7 @@ public class Bytecode {
case NONE:
break;
case BYTE:
if ( operandsAreChars ) operands.add(quotedCharLiteral(code[ip]));
if ( operandsAreChars ) operands.add(quotedCharLiteral((char)code[ip]));
else operands.add(String.valueOf(code[ip]));
break;
case CHAR :
@ -193,6 +195,7 @@ public class Bytecode {
* as unicode.
*/
public static String quotedCharLiteral(int c) {
if ( c== Token.EOF ) return "'<EOF>'";
if ( c<LiteralCharValueEscape.length && LiteralCharValueEscape[c]!=null ) {
return '\''+LiteralCharValueEscape[c]+'\'';
}

View File

@ -15,6 +15,9 @@ import java.util.List;
* and a stack for rule invocation.
*/
public class PDA {
public static class InvalidElement extends RuntimeException {}
public static final InvalidElement INVALID_ELEMENT = new InvalidElement();
public interface action_fptr { void exec(int action); }
public interface sempred_fptr { boolean eval(int predIndex); }
@ -30,7 +33,7 @@ public class PDA {
boolean notNextMatch;
public PDA(byte[] code, int[] altToAddr, int nLabels) {
System.out.println("code="+Arrays.toString(code));
//System.out.println("code="+Arrays.toString(code));
this.code = code;
this.altToAddr = altToAddr;
this.nLabels = nLabels;
@ -41,17 +44,17 @@ public class PDA {
int m = input.mark();
Arrays.fill(labelValues, null);
int ttype = execThompson(input, 0, false);
System.out.println("first attempt ttype="+ttype);
// System.out.println("first attempt ttype="+ttype);
if ( bypassedAction ) {
input.rewind(m);
System.out.println("Bypassed action; rewinding to "+input.index()+" doing with feeling");
//System.out.println("Bypassed action; rewinding to "+input.index()+" doing with feeling");
bypassedAction = false;
Arrays.fill(labelValues, null);
int ttype2 = execThompson(input, altToAddr[ttype], true);
if ( ttype!=ttype2 ) {
System.err.println("eh? token diff with action(s)");
}
else System.out.println("types are same");
//else System.out.println("types are same");
}
else input.release(m);
return ttype;
@ -72,15 +75,14 @@ public class PDA {
c = input.LA(1);
int i = 0;
boolean accepted = false;
System.out.println("input["+input.index()+"]=="+(char)c);
// System.out.println("input["+input.index()+"]=="+Bytecode.quotedCharLiteral(c)+
// " closure="+closure);
processOneChar:
while ( i<closure.size() ) {
ThreadState t = closure.get(i);
ip = t.addr;
NFAStack context = t.context;
int alt = t.alt;
//System.out.println("input["+input.index()+"]=="+(char)c+" closure="+closure+", i="+i+", reach="+ reach);
trace(ip);
short opcode = code[ip];
boolean matched;
ip++; // move to next instruction or first byte of operand
@ -89,28 +91,28 @@ processOneChar:
notNextMatch = true;
break;
case Bytecode.MATCH8 :
if ( c == code[ip] || (notNextMatch && c != code[ip]) ) {
if ( (!notNextMatch && c == code[ip]) || (notNextMatch && c != code[ip] && c != Token.EOF) ) {
addToClosure(reach, ip+1, alt, context);
}
notNextMatch = false;
break;
case Bytecode.MATCH16 :
matched = c == getShort(code, ip);
if ( matched || (notNextMatch && matched) ) {
if ( (!notNextMatch && matched) || (notNextMatch && matched && c != Token.EOF) ) {
addToClosure(reach, ip+2, alt, context);
}
notNextMatch = false;
break;
case Bytecode.RANGE8 :
matched = c >= code[ip] && c <= code[ip + 1];
if ( matched || (notNextMatch && matched) ) {
if ( (!notNextMatch && matched) || (notNextMatch && matched && c != Token.EOF) ) {
addToClosure(reach, ip+2, alt, context);
}
notNextMatch = false;
break;
case Bytecode.RANGE16 :
matched = c >= getShort(code, ip) && c <= getShort(code, ip + 2);
if ( matched || (notNextMatch && matched) ) {
if ( (!notNextMatch && matched) || (notNextMatch && matched && c != Token.EOF) ) {
addToClosure(reach, ip+4, alt, context);
}
notNextMatch = false;
@ -143,11 +145,11 @@ processOneChar:
int tokenLastCharIndex = input.index() - 1;
int ttype = getShort(code, ip);
ANTLRStringStream is = (ANTLRStringStream)input;
System.out.println("ACCEPT "+is.substring(firstCharIndex,tokenLastCharIndex)+" as type "+ttype);
// System.out.println("ACCEPT "+is.substring(firstCharIndex,tokenLastCharIndex)+" as type "+ttype);
if ( tokenLastCharIndex > prevAccept.inputIndex ) {
prevAccept.inputIndex = tokenLastCharIndex;
// choose longest match so far regardless of rule priority
System.out.println("replacing old best match @ "+prevAccept.addr);
// System.out.println("replacing old best match @ "+prevAccept.addr);
prevAccept.addr = ip-1;
prevAccept.inputMarker = input.mark();
if ( firstAccept==null ) firstAccept = prevAccept;
@ -155,7 +157,7 @@ processOneChar:
else if ( tokenLastCharIndex == prevAccept.inputIndex ) {
// choose first rule matched if match is of same length
if ( ip-1 < prevAccept.addr ) { // it will see both accepts for ambig rules
System.out.println("replacing old best match @ "+prevAccept.addr);
// System.out.println("replacing old best match @ "+prevAccept.addr);
prevAccept.addr = ip-1;
prevAccept.inputMarker = input.mark();
}
@ -182,14 +184,14 @@ processOneChar:
throw new RuntimeException("invalid instruction @ "+ip+": "+opcode);
}
i++;
// trace(t,reach);
}
// if reach is empty, we didn't match anything but might have accepted
if ( reach.size()>0 ) { // if we reached other states, consume and process them
input.consume();
}
else if ( !accepted && c!=Token.EOF ) {
System.err.println("!!!!! no match for char "+(char)c+" at "+input.index());
input.consume();
throw INVALID_ELEMENT;
}
// else reach.size==0 && matched, don't consume: accepted
@ -450,9 +452,10 @@ processOneChar:
public void action(int ruleIndex, int actionIndex) {
}
void trace(int ip) {
void trace(ThreadState t, List<ThreadState> reach) {
int ip = t.addr;
String instr = Bytecode.disassembleInstruction(code, ip, true);
System.out.println(instr);
System.out.println(instr+"\t\t reach="+reach);
}
void traceDFA(int ip) {

View File

@ -4,7 +4,6 @@ import org.antlr.runtime.Token;
import org.antlr.v4.codegen.pda.CallInstr;
import org.antlr.v4.codegen.pda.Instr;
import org.antlr.v4.codegen.pda.MatchInstr;
import org.antlr.v4.codegen.pda.NotInstr;
import org.antlr.v4.misc.CharSupport;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.tool.Rule;
@ -76,9 +75,8 @@ public class PDABytecodeGenerator {
return obj.set8table.size()-1;
}
public void emitString(Token t, boolean not) {
public void emitString(Token t) {
String chars = CharSupport.getStringFromGrammarStringLiteral(t.getText());
if ( not && chars.length()==1 ) emit(new NotInstr());
for (char c : chars.toCharArray()) {
emit(new MatchInstr(t, c));
}

View File

@ -161,17 +161,17 @@ atom
| ^(BANG notSet)
| notSet
| range
| ^(DOT ID terminal[false])
| ^(DOT ID terminal)
| ^(DOT ID ruleref)
| ^(WILDCARD .) {gen.emit(new WildcardInstr($WILDCARD.token));}
| WILDCARD {gen.emit(new WildcardInstr($WILDCARD.token));}
| terminal[false]
| terminal
| ruleref
;
notSet
: ^(NOT terminal[true])
| ^(NOT block)
: ^(NOT {gen.emit(new NotInstr());} terminal)
| ^(NOT {gen.emit(new NotInstr());} block)
;
ruleref
@ -185,12 +185,12 @@ range
{gen.emit(new RangeInstr($a.token, $b.token));}
;
terminal[boolean not]
: ^(STRING_LITERAL .) {gen.emitString($STRING_LITERAL.token, $not);}
| STRING_LITERAL {gen.emitString($STRING_LITERAL.token, $not);}
terminal
: ^(STRING_LITERAL .) {gen.emitString($STRING_LITERAL.token);}
| STRING_LITERAL {gen.emitString($STRING_LITERAL.token);}
| ^(TOKEN_REF ARG_ACTION .) {gen.emit(new CallInstr($TOKEN_REF.token));}
| ^(TOKEN_REF .) {gen.emit(new CallInstr($TOKEN_REF.token));}
| TOKEN_REF {gen.emit(new CallInstr($TOKEN_REF.token));}
| ^(ROOT terminal[false])
| ^(BANG terminal[false])
| ^(ROOT terminal)
| ^(BANG terminal)
;

View File

@ -1,4 +1,4 @@
// $ANTLR 3.2.1-SNAPSHOT May 24, 2010 15:02:05 PDABytecodeTriggers.g 2010-06-05 16:34:04
// $ANTLR 3.2.1-SNAPSHOT May 24, 2010 15:02:05 PDABytecodeTriggers.g 2010-06-08 17:24:31
package org.antlr.v4.codegen;
@ -901,13 +901,13 @@ public class PDABytecodeTriggers extends TreeParser {
// $ANTLR start "atom"
// PDABytecodeTriggers.g:157:1: atom : ( ^( ROOT range ) | ^( BANG range ) | ^( ROOT notSet ) | ^( BANG notSet ) | notSet | range | ^( DOT ID terminal[false] ) | ^( DOT ID ruleref ) | ^( WILDCARD . ) | WILDCARD | terminal[false] | ruleref );
// PDABytecodeTriggers.g:157:1: atom : ( ^( ROOT range ) | ^( BANG range ) | ^( ROOT notSet ) | ^( BANG notSet ) | notSet | range | ^( DOT ID terminal ) | ^( DOT ID ruleref ) | ^( WILDCARD . ) | WILDCARD | terminal | ruleref );
public final void atom() throws RecognitionException {
GrammarAST WILDCARD5=null;
GrammarAST WILDCARD6=null;
try {
// PDABytecodeTriggers.g:158:2: ( ^( ROOT range ) | ^( BANG range ) | ^( ROOT notSet ) | ^( BANG notSet ) | notSet | range | ^( DOT ID terminal[false] ) | ^( DOT ID ruleref ) | ^( WILDCARD . ) | WILDCARD | terminal[false] | ruleref )
// PDABytecodeTriggers.g:158:2: ( ^( ROOT range ) | ^( BANG range ) | ^( ROOT notSet ) | ^( BANG notSet ) | notSet | range | ^( DOT ID terminal ) | ^( DOT ID ruleref ) | ^( WILDCARD . ) | WILDCARD | terminal | ruleref )
int alt10=12;
alt10 = dfa10.predict(input);
switch (alt10) {
@ -998,14 +998,14 @@ public class PDABytecodeTriggers extends TreeParser {
}
break;
case 7 :
// PDABytecodeTriggers.g:164:4: ^( DOT ID terminal[false] )
// PDABytecodeTriggers.g:164:4: ^( DOT ID terminal )
{
match(input,DOT,FOLLOW_DOT_in_atom583);
match(input, Token.DOWN, null);
match(input,ID,FOLLOW_ID_in_atom585);
pushFollow(FOLLOW_terminal_in_atom587);
terminal(false);
terminal();
state._fsp--;
@ -1017,11 +1017,11 @@ public class PDABytecodeTriggers extends TreeParser {
case 8 :
// PDABytecodeTriggers.g:165:4: ^( DOT ID ruleref )
{
match(input,DOT,FOLLOW_DOT_in_atom597);
match(input,DOT,FOLLOW_DOT_in_atom596);
match(input, Token.DOWN, null);
match(input,ID,FOLLOW_ID_in_atom599);
pushFollow(FOLLOW_ruleref_in_atom601);
match(input,ID,FOLLOW_ID_in_atom598);
pushFollow(FOLLOW_ruleref_in_atom600);
ruleref();
state._fsp--;
@ -1034,7 +1034,7 @@ public class PDABytecodeTriggers extends TreeParser {
case 9 :
// PDABytecodeTriggers.g:166:7: ^( WILDCARD . )
{
WILDCARD5=(GrammarAST)match(input,WILDCARD,FOLLOW_WILDCARD_in_atom613);
WILDCARD5=(GrammarAST)match(input,WILDCARD,FOLLOW_WILDCARD_in_atom612);
match(input, Token.DOWN, null);
matchAny(input);
@ -1047,16 +1047,16 @@ public class PDABytecodeTriggers extends TreeParser {
case 10 :
// PDABytecodeTriggers.g:167:7: WILDCARD
{
WILDCARD6=(GrammarAST)match(input,WILDCARD,FOLLOW_WILDCARD_in_atom629);
WILDCARD6=(GrammarAST)match(input,WILDCARD,FOLLOW_WILDCARD_in_atom628);
gen.emit(new WildcardInstr(WILDCARD6.token));
}
break;
case 11 :
// PDABytecodeTriggers.g:168:9: terminal[false]
// PDABytecodeTriggers.g:168:9: terminal
{
pushFollow(FOLLOW_terminal_in_atom644);
terminal(false);
pushFollow(FOLLOW_terminal_in_atom643);
terminal();
state._fsp--;
@ -1066,7 +1066,7 @@ public class PDABytecodeTriggers extends TreeParser {
case 12 :
// PDABytecodeTriggers.g:169:9: ruleref
{
pushFollow(FOLLOW_ruleref_in_atom659);
pushFollow(FOLLOW_ruleref_in_atom656);
ruleref();
state._fsp--;
@ -1089,10 +1089,10 @@ public class PDABytecodeTriggers extends TreeParser {
// $ANTLR start "notSet"
// PDABytecodeTriggers.g:172:1: notSet : ( ^( NOT terminal[true] ) | ^( NOT block ) );
// PDABytecodeTriggers.g:172:1: notSet : ( ^( NOT terminal ) | ^( NOT block ) );
public final void notSet() throws RecognitionException {
try {
// PDABytecodeTriggers.g:173:5: ( ^( NOT terminal[true] ) | ^( NOT block ) )
// PDABytecodeTriggers.g:173:5: ( ^( NOT terminal ) | ^( NOT block ) )
int alt11=2;
int LA11_0 = input.LA(1);
@ -1130,13 +1130,15 @@ public class PDABytecodeTriggers extends TreeParser {
}
switch (alt11) {
case 1 :
// PDABytecodeTriggers.g:173:7: ^( NOT terminal[true] )
// PDABytecodeTriggers.g:173:7: ^( NOT terminal )
{
match(input,NOT,FOLLOW_NOT_in_notSet682);
match(input,NOT,FOLLOW_NOT_in_notSet679);
gen.emit(new NotInstr());
match(input, Token.DOWN, null);
pushFollow(FOLLOW_terminal_in_notSet684);
terminal(true);
pushFollow(FOLLOW_terminal_in_notSet683);
terminal();
state._fsp--;
@ -1148,7 +1150,9 @@ public class PDABytecodeTriggers extends TreeParser {
case 2 :
// PDABytecodeTriggers.g:174:7: ^( NOT block )
{
match(input,NOT,FOLLOW_NOT_in_notSet695);
match(input,NOT,FOLLOW_NOT_in_notSet693);
gen.emit(new NotInstr());
match(input, Token.DOWN, null);
pushFollow(FOLLOW_block_in_notSet697);
@ -1208,10 +1212,10 @@ public class PDABytecodeTriggers extends TreeParser {
case 1 :
// PDABytecodeTriggers.g:178:7: ^( ROOT ^( RULE_REF ( ARG_ACTION )? ) )
{
match(input,ROOT,FOLLOW_ROOT_in_ruleref719);
match(input,ROOT,FOLLOW_ROOT_in_ruleref716);
match(input, Token.DOWN, null);
match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref722);
match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref719);
if ( input.LA(1)==Token.DOWN ) {
match(input, Token.DOWN, null);
@ -1226,7 +1230,7 @@ public class PDABytecodeTriggers extends TreeParser {
case 1 :
// PDABytecodeTriggers.g:178:25: ARG_ACTION
{
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref724);
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref721);
}
break;
@ -1244,10 +1248,10 @@ public class PDABytecodeTriggers extends TreeParser {
case 2 :
// PDABytecodeTriggers.g:179:7: ^( BANG ^( RULE_REF ( ARG_ACTION )? ) )
{
match(input,BANG,FOLLOW_BANG_in_ruleref737);
match(input,BANG,FOLLOW_BANG_in_ruleref734);
match(input, Token.DOWN, null);
match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref740);
match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref737);
if ( input.LA(1)==Token.DOWN ) {
match(input, Token.DOWN, null);
@ -1262,7 +1266,7 @@ public class PDABytecodeTriggers extends TreeParser {
case 1 :
// PDABytecodeTriggers.g:179:25: ARG_ACTION
{
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref742);
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref739);
}
break;
@ -1280,7 +1284,7 @@ public class PDABytecodeTriggers extends TreeParser {
case 3 :
// PDABytecodeTriggers.g:180:7: ^( RULE_REF ( ARG_ACTION )? )
{
match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref755);
match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref752);
if ( input.LA(1)==Token.DOWN ) {
match(input, Token.DOWN, null);
@ -1295,7 +1299,7 @@ public class PDABytecodeTriggers extends TreeParser {
case 1 :
// PDABytecodeTriggers.g:180:18: ARG_ACTION
{
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref757);
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleref754);
}
break;
@ -1332,11 +1336,11 @@ public class PDABytecodeTriggers extends TreeParser {
// PDABytecodeTriggers.g:184:5: ( ^( RANGE a= STRING_LITERAL b= STRING_LITERAL ) )
// PDABytecodeTriggers.g:184:7: ^( RANGE a= STRING_LITERAL b= STRING_LITERAL )
{
match(input,RANGE,FOLLOW_RANGE_in_range780);
match(input,RANGE,FOLLOW_RANGE_in_range777);
match(input, Token.DOWN, null);
a=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range784);
b=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range788);
a=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range781);
b=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_range785);
match(input, Token.UP, null);
gen.emit(new RangeInstr(a.token, b.token));
@ -1356,8 +1360,8 @@ public class PDABytecodeTriggers extends TreeParser {
// $ANTLR start "terminal"
// PDABytecodeTriggers.g:188:1: terminal[boolean not] : ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal[false] ) | ^( BANG terminal[false] ) );
public final void terminal(boolean not) throws RecognitionException {
// PDABytecodeTriggers.g:188:1: terminal : ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal ) | ^( BANG terminal ) );
public final void terminal() throws RecognitionException {
GrammarAST STRING_LITERAL7=null;
GrammarAST STRING_LITERAL8=null;
GrammarAST TOKEN_REF9=null;
@ -1365,38 +1369,38 @@ public class PDABytecodeTriggers extends TreeParser {
GrammarAST TOKEN_REF11=null;
try {
// PDABytecodeTriggers.g:189:5: ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal[false] ) | ^( BANG terminal[false] ) )
// PDABytecodeTriggers.g:189:5: ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal ) | ^( BANG terminal ) )
int alt16=7;
alt16 = dfa16.predict(input);
switch (alt16) {
case 1 :
// PDABytecodeTriggers.g:189:8: ^( STRING_LITERAL . )
{
STRING_LITERAL7=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal816);
STRING_LITERAL7=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal812);
match(input, Token.DOWN, null);
matchAny(input);
match(input, Token.UP, null);
gen.emitString(STRING_LITERAL7.token, not);
gen.emitString(STRING_LITERAL7.token);
}
break;
case 2 :
// PDABytecodeTriggers.g:190:7: STRING_LITERAL
{
STRING_LITERAL8=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal831);
gen.emitString(STRING_LITERAL8.token, not);
STRING_LITERAL8=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal827);
gen.emitString(STRING_LITERAL8.token);
}
break;
case 3 :
// PDABytecodeTriggers.g:191:7: ^( TOKEN_REF ARG_ACTION . )
{
TOKEN_REF9=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal845);
TOKEN_REF9=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal841);
match(input, Token.DOWN, null);
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_terminal847);
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_terminal843);
matchAny(input);
match(input, Token.UP, null);
@ -1407,7 +1411,7 @@ public class PDABytecodeTriggers extends TreeParser {
case 4 :
// PDABytecodeTriggers.g:192:7: ^( TOKEN_REF . )
{
TOKEN_REF10=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal861);
TOKEN_REF10=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal857);
match(input, Token.DOWN, null);
matchAny(input);
@ -1420,19 +1424,19 @@ public class PDABytecodeTriggers extends TreeParser {
case 5 :
// PDABytecodeTriggers.g:193:7: TOKEN_REF
{
TOKEN_REF11=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal877);
TOKEN_REF11=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal873);
gen.emit(new CallInstr(TOKEN_REF11.token));
}
break;
case 6 :
// PDABytecodeTriggers.g:194:7: ^( ROOT terminal[false] )
// PDABytecodeTriggers.g:194:7: ^( ROOT terminal )
{
match(input,ROOT,FOLLOW_ROOT_in_terminal892);
match(input,ROOT,FOLLOW_ROOT_in_terminal888);
match(input, Token.DOWN, null);
pushFollow(FOLLOW_terminal_in_terminal894);
terminal(false);
pushFollow(FOLLOW_terminal_in_terminal890);
terminal();
state._fsp--;
@ -1442,13 +1446,13 @@ public class PDABytecodeTriggers extends TreeParser {
}
break;
case 7 :
// PDABytecodeTriggers.g:195:7: ^( BANG terminal[false] )
// PDABytecodeTriggers.g:195:7: ^( BANG terminal )
{
match(input,BANG,FOLLOW_BANG_in_terminal908);
match(input,BANG,FOLLOW_BANG_in_terminal900);
match(input, Token.DOWN, null);
pushFollow(FOLLOW_terminal_in_terminal910);
terminal(false);
pushFollow(FOLLOW_terminal_in_terminal902);
terminal();
state._fsp--;
@ -1682,7 +1686,7 @@ public class PDABytecodeTriggers extends TreeParser {
this.transition = DFA10_transition;
}
public String getDescription() {
return "157:1: atom : ( ^( ROOT range ) | ^( BANG range ) | ^( ROOT notSet ) | ^( BANG notSet ) | notSet | range | ^( DOT ID terminal[false] ) | ^( DOT ID ruleref ) | ^( WILDCARD . ) | WILDCARD | terminal[false] | ruleref );";
return "157:1: atom : ( ^( ROOT range ) | ^( BANG range ) | ^( ROOT notSet ) | ^( BANG notSet ) | notSet | range | ^( DOT ID terminal ) | ^( DOT ID ruleref ) | ^( WILDCARD . ) | WILDCARD | terminal | ruleref );";
}
}
static final String DFA16_eotS =
@ -1748,7 +1752,7 @@ public class PDABytecodeTriggers extends TreeParser {
this.transition = DFA16_transition;
}
public String getDescription() {
return "188:1: terminal[boolean not] : ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal[false] ) | ^( BANG terminal[false] ) );";
return "188:1: terminal : ( ^( STRING_LITERAL . ) | STRING_LITERAL | ^( TOKEN_REF ARG_ACTION . ) | ^( TOKEN_REF . ) | TOKEN_REF | ^( ROOT terminal ) | ^( BANG terminal ) );";
}
}
@ -1806,37 +1810,37 @@ public class PDABytecodeTriggers extends TreeParser {
public static final BitSet FOLLOW_DOT_in_atom583 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_atom585 = new BitSet(new long[]{0x8021000000000000L,0x0000000000000010L});
public static final BitSet FOLLOW_terminal_in_atom587 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_DOT_in_atom597 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_atom599 = new BitSet(new long[]{0xA1A1000000000000L,0x0000000200000011L});
public static final BitSet FOLLOW_ruleref_in_atom601 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_WILDCARD_in_atom613 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_WILDCARD_in_atom629 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_terminal_in_atom644 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ruleref_in_atom659 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_NOT_in_notSet682 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_terminal_in_notSet684 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_NOT_in_notSet695 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_DOT_in_atom596 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_atom598 = new BitSet(new long[]{0xA1A1000000000000L,0x0000000200000011L});
public static final BitSet FOLLOW_ruleref_in_atom600 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_WILDCARD_in_atom612 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_WILDCARD_in_atom628 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_terminal_in_atom643 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ruleref_in_atom656 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_NOT_in_notSet679 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_terminal_in_notSet683 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_NOT_in_notSet693 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_block_in_notSet697 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ROOT_in_ruleref719 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_RULE_REF_in_ruleref722 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref724 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_BANG_in_ruleref737 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_RULE_REF_in_ruleref740 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref742 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_RULE_REF_in_ruleref755 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref757 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_RANGE_in_range780 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_STRING_LITERAL_in_range784 = new BitSet(new long[]{0x0000000000000000L,0x0000000000000010L});
public static final BitSet FOLLOW_STRING_LITERAL_in_range788 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_STRING_LITERAL_in_terminal816 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_STRING_LITERAL_in_terminal831 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal845 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_terminal847 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF0L,0x0000007FFFFFFFFFL});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal861 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal877 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ROOT_in_terminal892 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_terminal_in_terminal894 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_BANG_in_terminal908 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_terminal_in_terminal910 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ROOT_in_ruleref716 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_RULE_REF_in_ruleref719 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref721 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_BANG_in_ruleref734 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_RULE_REF_in_ruleref737 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref739 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_RULE_REF_in_ruleref752 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleref754 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_RANGE_in_range777 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_STRING_LITERAL_in_range781 = new BitSet(new long[]{0x0000000000000000L,0x0000000000000010L});
public static final BitSet FOLLOW_STRING_LITERAL_in_range785 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_STRING_LITERAL_in_terminal812 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_STRING_LITERAL_in_terminal827 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal841 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_terminal843 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF0L,0x0000007FFFFFFFFFL});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal857 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal873 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ROOT_in_terminal888 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_terminal_in_terminal890 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_BANG_in_terminal900 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_terminal_in_terminal902 = new BitSet(new long[]{0x0000000000000008L});
}

View File

@ -54,6 +54,38 @@ public class TestPDABytecodeGeneration extends BaseTest {
checkBytecode(g, expecting);
}
@Test public void testNotBlock() throws Exception {
LexerGrammar g = new LexerGrammar(
"lexer grammar L;\n"+
"A : ~('a'|'b') ;");
String expecting =
"0000:\tsplit 5\n" +
"0005:\tnot \n" + // not's next match/range
"0006:\tsplit 13, 18\n" +
"0013:\tmatch8 'a'\n" +
"0015:\tjmp 20\n" +
"0018:\tmatch8 'b'\n" +
"0020:\taccept 4\n";
checkBytecode(g, expecting);
}
@Test public void testNotStarBlock() throws Exception {
LexerGrammar g = new LexerGrammar(
"lexer grammar L;\n"+
"A : ~('a'|'b')* ;");
String expecting =
"0000:\tsplit 5\n" +
"0005:\tsplit 12, 30\n" +
"0012:\tnot \n" +
"0013:\tsplit 20, 25\n" +
"0020:\tmatch8 'a'\n" +
"0022:\tjmp 27\n" +
"0025:\tmatch8 'b'\n" +
"0027:\tjmp 5\n" +
"0030:\taccept 4\n";
checkBytecode(g, expecting);
}
@Test public void testIDandIntandKeyword() throws Exception {
LexerGrammar g = new LexerGrammar(
"lexer grammar L;\n" +

View File

@ -53,6 +53,16 @@ public class TestPDABytecodeInterp extends BaseTest {
checkMatches(g, "ab32abc", expecting);
}
@Test public void testSLComment() throws Exception {
LexerGrammar g = new LexerGrammar(
"lexer grammar L;\n" +
"\n" +
"CMT : '//' ~('\r'|'\n')* '\r'? '\n' ;\n" +
"ID : 'ab' ;\n");
String expecting = "ID, CMT, ID, EOF";
checkMatches(g, "ab// foo\nab", expecting);
}
@Test public void testNonGreedy() throws Exception {
LexerGrammar g = new LexerGrammar(
"lexer grammar L;\n" +