tweaked LA(1) var
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6854]
This commit is contained in:
parent
883a00a4b0
commit
2384c42698
|
@ -46,8 +46,8 @@ switch ( <expr> ) {
|
|||
}
|
||||
>>
|
||||
|
||||
LL1OptionalBlockSingleAlt(choice, expr, alts, decls) ::= <<
|
||||
<decls>
|
||||
LL1OptionalBlockSingleAlt(choice, expr, alts, preamble) ::= <<
|
||||
<preamble>
|
||||
if ( <expr> ) {
|
||||
<alts; separator="\n">
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ TestSet(s) ::= <<
|
|||
>>
|
||||
|
||||
TestSetInline(s) ::= <<
|
||||
<s.ttypes:{ttype | <first(choice.decls).varName>==<ttype>}; separator=" || ">
|
||||
<s.ttypes:{ttype | <s.nextToken.varName>==<ttype>}; separator=" || ">
|
||||
>>
|
||||
|
||||
cases(look) ::= <<
|
||||
|
@ -78,7 +78,7 @@ MatchToken(m) ::= <<
|
|||
<if(m.label)><m.label> = <endif>match(<m.name>, <m.follow.name>);
|
||||
>>
|
||||
|
||||
NextTokenDecl(d) ::= "Token <d.varName> = input.LA(1);"
|
||||
CaptureNextToken(d) ::= "Token <d.varName> = input.LA(1);"
|
||||
|
||||
codeFileExtension() ::= ".java"
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package org.antlr.v4.codegen.src;
|
||||
|
||||
public class CaptureNextToken extends SrcOp {
|
||||
public String varName;
|
||||
public CaptureNextToken(String varName) { this.varName = varName; }
|
||||
}
|
|
@ -11,7 +11,7 @@ import java.util.List;
|
|||
public abstract class Choice extends SrcOp {
|
||||
public int decision;
|
||||
public List<CodeBlock> alts;
|
||||
public List<Decl> decls;
|
||||
public List<SrcOp> preamble;
|
||||
|
||||
public Choice(CodeGenerator gen, GrammarAST blkOrEbnfRootAST, List<CodeBlock> alts) {
|
||||
this.gen = gen;
|
||||
|
@ -20,9 +20,14 @@ public abstract class Choice extends SrcOp {
|
|||
this.decision = ((BlockStartState)blkOrEbnfRootAST.nfaState).decision;
|
||||
}
|
||||
|
||||
public void addPreambleOp(SrcOp op) {
|
||||
preamble = new ArrayList<SrcOp>();
|
||||
preamble.add(op);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChildren() {
|
||||
final List<String> sup = super.getChildren();
|
||||
return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("alts"); add("decls"); }};
|
||||
return new ArrayList<String>() {{ if ( sup!=null ) addAll(sup); add("alts"); add("preamble"); }};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,7 @@ public class LL1OptionalBlockSingleAlt extends LL1OptionalBlock {
|
|||
super(gen, blkAST, alts);
|
||||
IntervalSet look = altLookSets[1];
|
||||
if ( look.size() < gen.target.getInlineTestsVsBitsetThreshold() ) {
|
||||
expr = new TestSetInline(gen, blkAST, look);
|
||||
decls = new ArrayList<Decl>();
|
||||
decls.add(new NextTokenDecl("la34"));
|
||||
expr = new TestSetInline(gen, this, blkAST, look);
|
||||
}
|
||||
else {
|
||||
expr = new TestSet(gen, blkAST, look);
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
package org.antlr.v4.codegen.src;
|
||||
|
||||
/** */
|
||||
public class NextTokenDecl extends Decl {
|
||||
public NextTokenDecl(String varName) { super(varName); }
|
||||
}
|
|
@ -1,12 +1,14 @@
|
|||
package org.antlr.v4.codegen.src;
|
||||
|
||||
import org.antlr.v4.codegen.CodeGenerator;
|
||||
import org.antlr.v4.tool.GrammarAST;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** */
|
||||
public abstract class OutputModelObject {
|
||||
public CodeGenerator gen;
|
||||
public GrammarAST ast;
|
||||
|
||||
/** If the output model object encloses some other model objects,
|
||||
* we need to be able to walk them. Rather than make each class
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package org.antlr.v4.codegen.src;
|
||||
|
||||
import org.antlr.v4.tool.GrammarAST;
|
||||
|
||||
/** */
|
||||
public abstract class SrcOp extends OutputModelObject {
|
||||
public GrammarAST ast;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,14 @@ import org.antlr.v4.tool.GrammarAST;
|
|||
/** */
|
||||
public class TestSetInline extends OutputModelObject {
|
||||
public String[] ttypes;
|
||||
public TestSetInline(CodeGenerator gen, GrammarAST blkAST, IntervalSet set) {
|
||||
public CaptureNextToken nextToken;
|
||||
public Choice choice;
|
||||
public TestSetInline(CodeGenerator gen, Choice choice, GrammarAST blkAST, IntervalSet set) {
|
||||
this.gen = gen;
|
||||
this.ast = blkAST;
|
||||
this.ttypes = gen.target.getTokenTypeAsTargetLabel(gen.g, set.toArray());
|
||||
this.choice = choice;
|
||||
nextToken = new CaptureNextToken("la"+blkAST.token.getTokenIndex());
|
||||
choice.addPreambleOp(nextToken);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue