@Override public CodeBlockForAlt epsilon(Alternative alt, boolean outerMost) { return alternative(alt, outerMost); }
@Override public List<SrcOp> wildcard(GrammarAST ast, GrammarAST labelAST) { Wildcard wild = new Wildcard(this, ast); // TODO: dup with tokenRef if ( labelAST!=null ) { String label = labelAST.getText(); Decl d = getTokenLabelDecl(label); wild.labels.add(d); getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), d); if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) { TokenListDecl l = getTokenListLabelDecl(label); getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), l); } } if ( controller.needsImplicitLabel(ast, wild) ) defineImplicitLabel(ast, wild); AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(wild, labelAST); return list(wild, listLabelOp); }
@Override public List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) { InvokeRule invokeOp = new InvokeRule(this, ID, label); // If no manual label and action refs as token/rule not label, we need to define implicit label if ( controller.needsImplicitLabel(ID, invokeOp) ) defineImplicitLabel(ID, invokeOp); AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(invokeOp, label); return list(invokeOp, listLabelOp); }
CodeGenerator gen = factory.getGenerator(); Rule r = factory.getGrammar().getRule(name); ctxName = gen.getTarget().getRuleFunctionContextStructName(r); RuleFunction rf = factory.getCurrentRuleFunction(); if ( labelAST!=null ) { factory.defineImplicitLabel(ast, this); String listLabel = gen.getTarget().getListLabel(label); RuleContextListDecl l = new RuleContextListDecl(factory, listLabel, ctxName); if ( factory.getCurrentOuterMostAlt().ruleRefsInActions.containsKey(ast.getText()) ) { String label = gen.getTarget().getImplicitRuleLabel(ast.getText()); RuleContextDecl d = new RuleContextDecl(factory,label,ctxName);
@Override public Choice getChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts, GrammarAST labelAST) { int decision = ((DecisionState)blkAST.atnState).decision; Choice c; if ( !g.tool.force_atn && AnalysisPipeline.disjoint(g.decisionLOOK.get(decision)) ) { c = getLL1ChoiceBlock(blkAST, alts); } else { c = getComplexChoiceBlock(blkAST, alts); } if ( labelAST!=null ) { // for x=(...), define x or x_list String label = labelAST.getText(); Decl d = getTokenLabelDecl(label); c.label = d; getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), d); if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) { String listLabel = getTarget().getListLabel(label); TokenListDecl l = new TokenListDecl(this, listLabel); getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), l); } } return c; }
Rule r = factory.getGrammar().getRule(name); ctxName = factory.getTarget().getRuleFunctionContextStructName(r); RuleFunction rf = factory.getCurrentRuleFunction(); if ( labelAST!=null ) { factory.defineImplicitLabel(ast, this); String listLabel = factory.getTarget().getListLabel(label); RuleContextListDecl l = new RuleContextListDecl(factory, listLabel, ctxName); rf.addContextDecl(ast.getAltLabel(), l); if ( factory.getCurrentOuterMostAlt().ruleRefsInActions.containsKey(ast.getText()) ) { String label = factory.getTarget().getImplicitRuleLabel(ast.getText()); RuleContextDecl d = new RuleContextDecl(factory,label,ctxName); labels.add(d);
@Override public Choice getEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) { if (!g.tool.force_atn) { int decision; if ( ebnfRoot.getType()==ANTLRParser.POSITIVE_CLOSURE ) { decision = ((PlusLoopbackState)ebnfRoot.atnState).decision; } else if ( ebnfRoot.getType()==ANTLRParser.CLOSURE ) { decision = ((StarLoopEntryState)ebnfRoot.atnState).decision; } else { decision = ((DecisionState)ebnfRoot.atnState).decision; } if ( AnalysisPipeline.disjoint(g.decisionLOOK.get(decision)) ) { return getLL1EBNFBlock(ebnfRoot, alts); } } return getComplexEBNFBlock(ebnfRoot, alts); }
public void defineImplicitLabel(GrammarAST ast, LabeledOp op) { Decl d; if ( ast.getType()==ANTLRParser.SET || ast.getType()==ANTLRParser.WILDCARD ) { String implLabel = gen.getTarget().getImplicitSetLabel(String.valueOf(ast.token.getTokenIndex())); d = getTokenLabelDecl(implLabel); ((TokenDecl)d).isImplicit = true; } else if ( ast.getType()==ANTLRParser.RULE_REF ) { // a rule reference? Rule r = g.getRule(ast.getText()); String implLabel = gen.getTarget().getImplicitRuleLabel(ast.getText()); String ctxName = gen.getTarget().getRuleFunctionContextStructName(r); d = new RuleContextDecl(this, implLabel, ctxName); ((RuleContextDecl)d).isImplicit = true; } else { String implLabel = gen.getTarget().getImplicitTokenLabel(ast.getText()); d = getTokenLabelDecl(implLabel); ((TokenDecl)d).isImplicit = true; } op.getLabels().add(d); // all labels must be in scope struct in case we exec action out of context getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), d); }
public void defineImplicitLabel(GrammarAST ast, LabeledOp op) { Decl d; if ( ast.getType()==ANTLRParser.SET || ast.getType()==ANTLRParser.WILDCARD ) { String implLabel = getTarget().getImplicitSetLabel(String.valueOf(ast.token.getTokenIndex())); d = getTokenLabelDecl(implLabel); ((TokenDecl)d).isImplicit = true; } else if ( ast.getType()==ANTLRParser.RULE_REF ) { // a rule reference? Rule r = g.getRule(ast.getText()); String implLabel = getTarget().getImplicitRuleLabel(ast.getText()); String ctxName = getTarget().getRuleFunctionContextStructName(r); d = new RuleContextDecl(this, implLabel, ctxName); ((RuleContextDecl)d).isImplicit = true; } else { String implLabel = getTarget().getImplicitTokenLabel(ast.getText()); d = getTokenLabelDecl(implLabel); ((TokenDecl)d).isImplicit = true; } op.getLabels().add(d); // all labels must be in scope struct in case we exec action out of context getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), d); }
@Override public boolean needsImplicitLabel(GrammarAST ID, LabeledOp op) { Alternative currentOuterMostAlt = getCurrentOuterMostAlt(); boolean actionRefsAsToken = currentOuterMostAlt.tokenRefsInActions.containsKey(ID.getText()); boolean actionRefsAsRule = currentOuterMostAlt.ruleRefsInActions.containsKey(ID.getText()); return op.getLabels().isEmpty() && (actionRefsAsToken || actionRefsAsRule); }
private OutputModelController createController() { OutputModelFactory factory = new ParserFactory(this); OutputModelController controller = new OutputModelController(factory); factory.setController(controller); return controller; }
@Override public Choice getLL1EBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) { int ebnf = 0; if ( ebnfRoot!=null ) ebnf = ebnfRoot.getType(); Choice c = null; switch ( ebnf ) { case ANTLRParser.OPTIONAL : if ( alts.size()==1 ) c = new LL1OptionalBlockSingleAlt(this, ebnfRoot, alts); else c = new LL1OptionalBlock(this, ebnfRoot, alts); break; case ANTLRParser.CLOSURE : if ( alts.size()==1 ) c = new LL1StarBlockSingleAlt(this, ebnfRoot, alts); else c = getComplexEBNFBlock(ebnfRoot, alts); break; case ANTLRParser.POSITIVE_CLOSURE : if ( alts.size()==1 ) c = new LL1PlusBlockSingleAlt(this, ebnfRoot, alts); else c = getComplexEBNFBlock(ebnfRoot, alts); break; } return c; }
CodeGenerator gen = factory.getGenerator(); Rule r = factory.getGrammar().getRule(name); ctxName = gen.getTarget().getRuleFunctionContextStructName(r); RuleFunction rf = factory.getCurrentRuleFunction(); if ( labelAST!=null ) { factory.defineImplicitLabel(ast, this); String listLabel = gen.getTarget().getListLabel(label); RuleContextListDecl l = new RuleContextListDecl(factory, listLabel, ctxName); if ( factory.getCurrentOuterMostAlt().ruleRefsInActions.containsKey(ast.getText()) ) { String label = gen.getTarget().getImplicitRuleLabel(ast.getText()); RuleContextDecl d = new RuleContextDecl(factory,label,ctxName);
@Override public Choice getChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts, GrammarAST labelAST) { int decision = ((DecisionState)blkAST.atnState).decision; Choice c; if ( !g.tool.force_atn && AnalysisPipeline.disjoint(g.decisionLOOK.get(decision)) ) { c = getLL1ChoiceBlock(blkAST, alts); } else { c = getComplexChoiceBlock(blkAST, alts); } if ( labelAST!=null ) { // for x=(...), define x or x_list String label = labelAST.getText(); Decl d = getTokenLabelDecl(label); c.label = d; getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), d); if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) { String listLabel = gen.getTarget().getListLabel(label); TokenListDecl l = new TokenListDecl(this, listLabel); getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), l); } } return c; }
@Override public List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) { InvokeRule invokeOp = new InvokeRule(this, ID, label); // If no manual label and action refs as token/rule not label, we need to define implicit label if ( controller.needsImplicitLabel(ID, invokeOp) ) defineImplicitLabel(ID, invokeOp); AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(invokeOp, label); return list(invokeOp, listLabelOp); }
@Override public Choice getEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) { if (!g.tool.force_atn) { int decision; if ( ebnfRoot.getType()==ANTLRParser.POSITIVE_CLOSURE ) { decision = ((PlusLoopbackState)ebnfRoot.atnState).decision; } else if ( ebnfRoot.getType()==ANTLRParser.CLOSURE ) { decision = ((StarLoopEntryState)ebnfRoot.atnState).decision; } else { decision = ((DecisionState)ebnfRoot.atnState).decision; } if ( AnalysisPipeline.disjoint(g.decisionLOOK.get(decision)) ) { return getLL1EBNFBlock(ebnfRoot, alts); } } return getComplexEBNFBlock(ebnfRoot, alts); }
public void defineImplicitLabel(GrammarAST ast, LabeledOp op) { Decl d; if ( ast.getType()==ANTLRParser.SET || ast.getType()==ANTLRParser.WILDCARD ) { String implLabel = gen.getTarget().getImplicitSetLabel(String.valueOf(ast.token.getTokenIndex())); d = getTokenLabelDecl(implLabel); ((TokenDecl)d).isImplicit = true; } else if ( ast.getType()==ANTLRParser.RULE_REF ) { // a rule reference? Rule r = g.getRule(ast.getText()); String implLabel = gen.getTarget().getImplicitRuleLabel(ast.getText()); String ctxName = gen.getTarget().getRuleFunctionContextStructName(r); d = new RuleContextDecl(this, implLabel, ctxName); ((RuleContextDecl)d).isImplicit = true; } else { String implLabel = gen.getTarget().getImplicitTokenLabel(ast.getText()); d = getTokenLabelDecl(implLabel); ((TokenDecl)d).isImplicit = true; } op.getLabels().add(d); // all labels must be in scope struct in case we exec action out of context getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), d); }
@Override public boolean needsImplicitLabel(GrammarAST ID, LabeledOp op) { Alternative currentOuterMostAlt = getCurrentOuterMostAlt(); boolean actionRefsAsToken = currentOuterMostAlt.tokenRefsInActions.containsKey(ID.getText()); boolean actionRefsAsRule = currentOuterMostAlt.ruleRefsInActions.containsKey(ID.getText()); return op.getLabels().isEmpty() && (actionRefsAsToken || actionRefsAsRule); }
private OutputModelController createController() { OutputModelFactory factory = new ParserFactory(this); OutputModelController controller = new OutputModelController(factory); factory.setController(controller); return controller; }
@Override public Choice getLL1EBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) { int ebnf = 0; if ( ebnfRoot!=null ) ebnf = ebnfRoot.getType(); Choice c = null; switch ( ebnf ) { case ANTLRParser.OPTIONAL : if ( alts.size()==1 ) c = new LL1OptionalBlockSingleAlt(this, ebnfRoot, alts); else c = new LL1OptionalBlock(this, ebnfRoot, alts); break; case ANTLRParser.CLOSURE : if ( alts.size()==1 ) c = new LL1StarBlockSingleAlt(this, ebnfRoot, alts); else c = getComplexEBNFBlock(ebnfRoot, alts); break; case ANTLRParser.POSITIVE_CLOSURE : if ( alts.size()==1 ) c = new LL1PlusBlockSingleAlt(this, ebnfRoot, alts); else c = getComplexEBNFBlock(ebnfRoot, alts); break; } return c; }