public AltLabelStructDecl(OutputModelFactory factory, Rule r, String label) { super(factory, r); this.name = // override name set in super to the label ctx factory.getTarget().getAltLabelContextStructName(label); derivedFromName = label; }
public StarBlock(OutputModelFactory factory, GrammarAST blkOrEbnfRootAST, List<CodeBlockForAlt> alts) { super(factory, blkOrEbnfRootAST, alts); loopLabel = factory.getTarget().getLoopLabel(blkOrEbnfRootAST); StarLoopEntryState star = (StarLoopEntryState)blkOrEbnfRootAST.atnState; loopBackStateNumber = star.loopBackState.stateNumber; decision = star.decision; } }
public String[][] getSegments() { List<String[]> segments = new ArrayList<String[]>(); int segmentLimit = factory.getTarget().getSerializedATNSegmentLimit(); for (int i = 0; i < serialized.size(); i += segmentLimit) { List<String> currentSegment = serialized.subList(i, Math.min(i + segmentLimit, serialized.size())); segments.add(currentSegment.toArray(new String[currentSegment.size()])); } return segments.toArray(new String[segments.size()][]); } }
protected static String translateTokenStringToTarget(String tokenName, OutputModelFactory factory) { if (tokenName == null) { return null; } if (tokenName.charAt(0) == '\'') { boolean addQuotes = false; String targetString = factory.getTarget().getTargetStringLiteralFromANTLRStringLiteral(factory.getGenerator(), tokenName, addQuotes); return "\"'" + targetString + "'\""; } else { return factory.getTarget().getTargetStringLiteralFromString(tokenName, true); } }
public List<String[]> getAltLookaheadAsStringLists(IntervalSet[] altLookSets) { List<String[]> altLook = new ArrayList<String[]>(); for (IntervalSet s : altLookSets) { altLook.add(factory.getTarget().getTokenTypesAsTargetLabels(factory.getGrammar(), s.toArray())); } return altLook; }
public String getTokenLabel(String x) { if ( node.resolver.resolvesToLabel(x, node) ) return x; return factory.getTarget().getImplicitTokenLabel(x); }
public String getRuleLabel(String x) { if ( node.resolver.resolvesToLabel(x, node) ) return x; return factory.getTarget().getImplicitRuleLabel(x); }
private static Bitset[] createBitsets(OutputModelFactory factory, IntervalSet set, int wordSize, boolean useZeroOffset) { List<Bitset> bitsetList = new ArrayList<Bitset>(); for (int ttype : set.toArray()) { Bitset current = !bitsetList.isEmpty() ? bitsetList.get(bitsetList.size() - 1) : null; if (current == null || ttype > (current.shift + wordSize-1)) { current = new Bitset(); if (useZeroOffset && ttype >= 0 && ttype < wordSize-1) { current.shift = 0; } else { current.shift = ttype; } bitsetList.add(current); } current.ttypes.add(factory.getTarget().getTokenTypeAsTargetLabel(factory.getGrammar(), ttype)); } return bitsetList.toArray(new Bitset[bitsetList.size()]); }
public SerializedATN(OutputModelFactory factory, ATN atn, List<String> ruleNames) { super(factory); IntegerList data = ATNSerializer.getSerialized(atn, ruleNames); serialized = new ArrayList<String>(data.size()); for (int c : data.toArray()) { String encoded = factory.getTarget().encodeIntAsCharEscape(c == -1 ? Character.MAX_VALUE : c); serialized.add(encoded); } // System.out.println(ATNSerializer.getDecoded(factory.getGrammar(), atn)); }
public StructDecl(OutputModelFactory factory, Rule r) { super(factory, factory.getTarget().getRuleFunctionContextStructName(r)); addDispatchMethods(r); derivedFromName = r.name; provideCopyFrom = r.hasAltSpecificContexts(); }
public void buildLexerRuleActions(Lexer lexer, final Rule r) { if (r.actions.isEmpty()) { return; } CodeGenerator gen = delegate.getGenerator(); Grammar g = delegate.getGrammar(); String ctxType = delegate.getTarget().getRuleFunctionContextStructName(r); RuleActionFunction raf = lexer.actionFuncs.get(r); if ( raf==null ) { raf = new RuleActionFunction(delegate, r, ctxType); } for (ActionAST a : r.actions) { if ( a instanceof PredAST ) { PredAST p = (PredAST)a; RuleSempredFunction rsf = lexer.sempredFuncs.get(r); if ( rsf==null ) { rsf = new RuleSempredFunction(delegate, r, ctxType); lexer.sempredFuncs.put(r, rsf); } rsf.actions.put(g.sempreds.get(p), new Action(delegate, p)); } else if ( a.getType()== ANTLRParser.ACTION ) { raf.actions.put(g.lexerActions.get(a), new Action(delegate, a)); } } if (!raf.actions.isEmpty() && !lexer.actionFuncs.containsKey(r)) { // only add to lexer if the function actually contains actions lexer.actionFuncs.put(r, raf); } }
if ( t.getType()==RULE_REF ) { Rule rref = factory.getGrammar().getRule(t.getText()); String ctxName = factory.getTarget() .getRuleFunctionContextStructName(rref); if ( needList) { if(factory.getTarget().supportsOverloadedMethods()) decls.add( new ContextRuleListGetterDecl(factory, refLabelName, ctxName) ); decls.add( new ContextRuleListIndexedGetterDecl(factory, refLabelName, ctxName) ); if(factory.getTarget().supportsOverloadedMethods()) decls.add( new ContextTokenListGetterDecl(factory, refLabelName) ); decls.add( new ContextTokenListIndexedGetterDecl(factory, refLabelName) );
public MatchToken(OutputModelFactory factory, TerminalAST ast) { super(factory, ast); Grammar g = factory.getGrammar(); ttype = g.getTokenType(ast.getText()); name = factory.getTarget().getTokenTypeAsTargetLabel(g, ttype); }
public SemPred(OutputModelFactory factory, @NotNull ActionAST ast) { super(factory,ast); assert ast.atnState != null && ast.atnState.getNumberOfTransitions() == 1 && ast.atnState.transition(0) instanceof AbstractPredicateTransition; GrammarAST failNode = ast.getOptionAST("fail"); predicate = ast.getText(); if (predicate.startsWith("{") && predicate.endsWith("}?")) { predicate = predicate.substring(1, predicate.length() - 2); } predicate = factory.getTarget().getTargetStringLiteralFromString(predicate); if ( failNode==null ) return; if ( failNode instanceof ActionAST ) { ActionAST failActionNode = (ActionAST)failNode; RuleFunction rf = factory.getCurrentRuleFunction(); failChunks = ActionTranslator.translateAction(factory, rf, failActionNode.token, failActionNode); } else { msg = factory.getTarget().getTargetStringLiteralFromANTLRStringLiteral(factory.getGenerator(), failNode.getText(), true); } } }
Target target = delegate.getTarget(); STGroup codegenTemplates = target.getTemplates();
public void buildNormalRuleFunction(Rule r, RuleFunction function) { CodeGenerator gen = delegate.getGenerator(); // TRIGGER factory functions for rule alts, elements GrammarASTAdaptor adaptor = new GrammarASTAdaptor(r.ast.token.getInputStream()); GrammarAST blk = (GrammarAST)r.ast.getFirstChildWithType(ANTLRParser.BLOCK); CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor,blk); walker = new SourceGenTriggers(nodes, this); try { // walk AST of rule alts/elements function.code = DefaultOutputModelFactory.list(walker.block(null, null)); function.hasLookaheadBlock = walker.hasLookaheadBlock; } catch (org.antlr.runtime.RecognitionException e){ e.printStackTrace(System.err); } function.ctxType = delegate.getTarget().getRuleFunctionContextStructName(function); function.postamble = rulePostamble(function, r); }
if ( rrefAST.getType() == ANTLRParser.RULE_REF ) { Rule targetRule = factory.getGrammar().getRule(rrefAST.getText()); String ctxName = factory.getTarget().getRuleFunctionContextStructName(targetRule); RuleContextDecl d; if (idAST.getParent().getType() == ANTLRParser.ASSIGN) {