RulePropertyRef getRulePropertyRef(Token prop) { try { Class<? extends RulePropertyRef> c = thisRulePropToModelMap.get(prop.getText()); Constructor<? extends RulePropertyRef> ctor = c.getConstructor(StructDecl.class, String.class); RulePropertyRef ref = ctor.newInstance(nodeContext, getRuleLabel(prop.getText())); return ref; } catch (Exception e) { factory.getGrammar().tool.errMgr.toolError(ErrorType.INTERNAL_ERROR, e); } return null; }
TokenPropertyRef getTokenPropertyRef(Token x, Token y) { try { Class<? extends TokenPropertyRef> c = tokenPropToModelMap.get(y.getText()); Constructor<? extends TokenPropertyRef> ctor = c.getConstructor(StructDecl.class, String.class); TokenPropertyRef ref = ctor.newInstance(nodeContext, getTokenLabel(x.getText())); return ref; } catch (Exception e) { factory.getGrammar().tool.errMgr.toolError(ErrorType.INTERNAL_ERROR, e); } return null; }
public Action(OutputModelFactory factory, ActionAST ast) { super(factory,ast); RuleFunction rf = factory.getCurrentRuleFunction(); if (ast != null) { chunks = ActionTranslator.translateAction(factory, rf, ast.token, ast); } else { chunks = new ArrayList<ActionChunk>(); } //System.out.println("actions="+chunks); }
if ( node.resolver.resolveToAttribute(x.getText(), node)!=null ) { attr(expr, x); chunks.add(new ActionText(nodeContext, "."+y.getText())); return; case ARG: chunks.add(new ArgRef(nodeContext,y.getText())); break; // has to be current rule case RET: chunks.add(new QRetValueRef(nodeContext, getRuleLabel(x.getText()), y.getText())); break; case PREDEFINED_RULE: chunks.add(getRulePropertyRef(x, y)); break; case TOKEN: chunks.add(getTokenPropertyRef(x, y)); break;
@Override public void attr(String expr, Token x) { gen.g.tool.log("action-translator", "attr "+x); Attribute a = node.resolver.resolveToAttribute(x.getText(), node); if ( a!=null ) { switch ( a.dict.type ) { case ARG: chunks.add(new ArgRef(nodeContext,x.getText())); break; case RET: chunks.add(new RetValueRef(rf.ruleCtx, x.getText())); break; case LOCAL: chunks.add(new LocalRef(nodeContext,x.getText())); break; case PREDEFINED_RULE: chunks.add(getRulePropertyRef(x)); break; } } if ( node.resolver.resolvesToToken(x.getText(), node) ) { chunks.add(new TokenRef(nodeContext,getTokenLabel(x.getText()))); // $label return; } if ( node.resolver.resolvesToLabel(x.getText(), node) ) { chunks.add(new LabelRef(nodeContext,getTokenLabel(x.getText()))); // $x for x=ID etc... return; } if ( node.resolver.resolvesToListLabel(x.getText(), node) ) { chunks.add(new ListLabelRef(nodeContext,x.getText())); // $ids for ids+=ID etc... return; } Rule r = factory.getGrammar().getRule(x.getText()); if ( r!=null ) { chunks.add(new LabelRef(nodeContext,getRuleLabel(x.getText()))); // $r for r rule ref } }
public static List<ActionChunk> translateAction(OutputModelFactory factory, RuleFunction rf, Token tokenWithinAction, ActionAST node) { String action = tokenWithinAction.getText(); if ( action!=null && action.length()>0 && action.charAt(0)=='{' ) { int firstCurly = action.indexOf('{'); int lastCurly = action.lastIndexOf('}'); if ( firstCurly>=0 && lastCurly>=0 ) { action = action.substring(firstCurly+1, lastCurly); // trim {...} } } return translateActionChunk(factory, rf, action, node); }
public static List<ActionChunk> translateActionChunk(OutputModelFactory factory, RuleFunction rf, String action, ActionAST node) { Token tokenWithinAction = node.token; ActionTranslator translator = new ActionTranslator(factory, node); translator.rf = rf; factory.getGrammar().tool.log("action-translator", "translate " + action); String altLabel = node.getAltLabel(); if ( rf!=null ) translator.nodeContext = rf.ruleCtx; if ( altLabel!=null ) translator.nodeContext = rf.altLabelCtxs.get(altLabel); ANTLRStringStream in = new ANTLRStringStream(action); in.setLine(tokenWithinAction.getLine()); in.setCharPositionInLine(tokenWithinAction.getCharPositionInLine()); ActionSplitter trigger = new ActionSplitter(in, translator); // forces eval, triggers listener methods trigger.getActionTokens(); return translator.chunks; }
if ( node.resolver.resolveToAttribute(x.getText(), node)!=null ) { attr(expr, x); chunks.add(new ActionText(nodeContext, "."+y.getText())); return; case ARG: chunks.add(new ArgRef(nodeContext,y.getText())); break; // has to be current rule case RET: chunks.add(new QRetValueRef(nodeContext, getRuleLabel(x.getText()), y.getText())); break; case PREDEFINED_RULE: chunks.add(getRulePropertyRef(x, y)); break; case TOKEN: chunks.add(getTokenPropertyRef(x, y)); break;
@Override public void attr(String expr, Token x) { gen.g.tool.log("action-translator", "attr "+x); Attribute a = node.resolver.resolveToAttribute(x.getText(), node); if ( a!=null ) { switch ( a.dict.type ) { case ARG: chunks.add(new ArgRef(nodeContext,x.getText())); break; case RET: chunks.add(new RetValueRef(rf.ruleCtx, x.getText())); break; case LOCAL: chunks.add(new LocalRef(nodeContext,x.getText())); break; case PREDEFINED_RULE: chunks.add(getRulePropertyRef(x)); break; } } if ( node.resolver.resolvesToToken(x.getText(), node) ) { chunks.add(new TokenRef(nodeContext,getTokenLabel(x.getText()))); // $label return; } if ( node.resolver.resolvesToLabel(x.getText(), node) ) { chunks.add(new LabelRef(nodeContext,getTokenLabel(x.getText()))); // $x for x=ID etc... return; } if ( node.resolver.resolvesToListLabel(x.getText(), node) ) { chunks.add(new ListLabelRef(nodeContext,x.getText())); // $ids for ids+=ID etc... return; } Rule r = factory.getGrammar().getRule(x.getText()); if ( r!=null ) { chunks.add(new LabelRef(nodeContext,getRuleLabel(x.getText()))); // $r for r rule ref } }
public static List<ActionChunk> translateAction(OutputModelFactory factory, RuleFunction rf, Token tokenWithinAction, ActionAST node) { String action = tokenWithinAction.getText(); if ( action!=null && action.length()>0 && action.charAt(0)=='{' ) { int firstCurly = action.indexOf('{'); int lastCurly = action.lastIndexOf('}'); if ( firstCurly>=0 && lastCurly>=0 ) { action = action.substring(firstCurly+1, lastCurly); // trim {...} } } return translateActionChunk(factory, rf, action, node); }
public static List<ActionChunk> translateActionChunk(OutputModelFactory factory, RuleFunction rf, String action, ActionAST node) { Token tokenWithinAction = node.token; ActionTranslator translator = new ActionTranslator(factory, node); translator.rf = rf; factory.getGrammar().tool.log("action-translator", "translate " + action); String altLabel = node.getAltLabel(); if ( rf!=null ) { translator.nodeContext = rf.ruleCtx; if ( altLabel!=null ) translator.nodeContext = rf.altLabelCtxs.get(altLabel); } ANTLRStringStream in = new ANTLRStringStream(action); in.setLine(tokenWithinAction.getLine()); in.setCharPositionInLine(tokenWithinAction.getCharPositionInLine()); ActionSplitter trigger = new ActionSplitter(in, translator); // forces eval, triggers listener methods trigger.getActionTokens(); return translator.chunks; }
if ( node.resolver.resolveToAttribute(x.getText(), node)!=null ) { attr(expr, x); chunks.add(new ActionText(nodeContext, "."+y.getText())); return; case ARG: chunks.add(new ArgRef(nodeContext,y.getText())); break; // has to be current rule case RET: chunks.add(new QRetValueRef(nodeContext, getRuleLabel(x.getText()), y.getText())); break; case PREDEFINED_RULE: chunks.add(getRulePropertyRef(x, y)); break; case TOKEN: chunks.add(getTokenPropertyRef(x, y)); break;
@Override public void attr(String expr, Token x) { gen.g.tool.log("action-translator", "attr "+x); Attribute a = node.resolver.resolveToAttribute(x.getText(), node); if ( a!=null ) { switch ( a.dict.type ) { case ARG: chunks.add(new ArgRef(nodeContext,x.getText())); break; case RET: chunks.add(new RetValueRef(rf.ruleCtx, x.getText())); break; case LOCAL: chunks.add(new LocalRef(nodeContext,x.getText())); break; case PREDEFINED_RULE: chunks.add(getRulePropertyRef(x)); break; } } if ( node.resolver.resolvesToToken(x.getText(), node) ) { chunks.add(new TokenRef(nodeContext,getTokenLabel(x.getText()))); // $label return; } if ( node.resolver.resolvesToLabel(x.getText(), node) ) { chunks.add(new LabelRef(nodeContext,getTokenLabel(x.getText()))); // $x for x=ID etc... return; } if ( node.resolver.resolvesToListLabel(x.getText(), node) ) { chunks.add(new ListLabelRef(nodeContext,x.getText())); // $ids for ids+=ID etc... return; } Rule r = factory.getGrammar().getRule(x.getText()); if ( r!=null ) { chunks.add(new LabelRef(nodeContext,getRuleLabel(x.getText()))); // $r for r rule ref } }
public static List<ActionChunk> translateAction(OutputModelFactory factory, RuleFunction rf, Token tokenWithinAction, ActionAST node) { String action = tokenWithinAction.getText(); if ( action!=null && action.length()>0 && action.charAt(0)=='{' ) { int firstCurly = action.indexOf('{'); int lastCurly = action.lastIndexOf('}'); if ( firstCurly>=0 && lastCurly>=0 ) { action = action.substring(firstCurly+1, lastCurly); // trim {...} } } return translateActionChunk(factory, rf, action, node); }
public Action(OutputModelFactory factory, ActionAST ast) { super(factory,ast); RuleFunction rf = factory.getCurrentRuleFunction(); if (ast != null) { chunks = ActionTranslator.translateAction(factory, rf, ast.token, ast); } else { chunks = new ArrayList<ActionChunk>(); } //System.out.println("actions="+chunks); }
RulePropertyRef getRulePropertyRef(Token prop) { try { Class<? extends RulePropertyRef> c = thisRulePropToModelMap.get(prop.getText()); Constructor<? extends RulePropertyRef> ctor = c.getConstructor(StructDecl.class, String.class); RulePropertyRef ref = ctor.newInstance(nodeContext, getRuleLabel(prop.getText())); return ref; } catch (Exception e) { factory.getGrammar().tool.errMgr.toolError(ErrorType.INTERNAL_ERROR, e); } return null; }
TokenPropertyRef getTokenPropertyRef(Token x, Token y) { try { Class<? extends TokenPropertyRef> c = tokenPropToModelMap.get(y.getText()); Constructor<? extends TokenPropertyRef> ctor = c.getConstructor(StructDecl.class, String.class); TokenPropertyRef ref = ctor.newInstance(nodeContext, getTokenLabel(x.getText())); return ref; } catch (Exception e) { factory.getGrammar().tool.errMgr.toolError(ErrorType.INTERNAL_ERROR, e); } return null; }
public static List<ActionChunk> translateActionChunk(OutputModelFactory factory, RuleFunction rf, String action, ActionAST node) { Token tokenWithinAction = node.token; ActionTranslator translator = new ActionTranslator(factory, node); translator.rf = rf; factory.getGrammar().tool.log("action-translator", "translate " + action); String altLabel = node.getAltLabel(); if ( rf!=null ) { translator.nodeContext = rf.ruleCtx; if ( altLabel!=null ) translator.nodeContext = rf.altLabelCtxs.get(altLabel); } ANTLRStringStream in = new ANTLRStringStream(action); in.setLine(tokenWithinAction.getLine()); in.setCharPositionInLine(tokenWithinAction.getCharPositionInLine()); ActionSplitter trigger = new ActionSplitter(in, translator); // forces eval, triggers listener methods trigger.getActionTokens(); return translator.chunks; }
if ( node.resolver.resolveToAttribute(x.getText(), node)!=null ) { attr(expr, x); chunks.add(new ActionText(nodeContext, "."+y.getText())); return; chunks.add(new QRetValueRef(nodeContext, getRuleLabel(x.getText()), y.getText())); break; factory.getCurrentRuleFunction().name.equals(x.getText()) ) chunks.add(getRulePropertyRef(y)); chunks.add(getRulePropertyRef(x, y)); chunks.add(getTokenPropertyRef(x, y)); break;
@Override public void attr(String expr, Token x) { gen.g.tool.log("action-translator", "attr "+x); Attribute a = node.resolver.resolveToAttribute(x.getText(), node); if ( a!=null ) { switch ( a.dict.type ) { case ARG: chunks.add(new ArgRef(nodeContext,x.getText())); break; case RET: chunks.add(new RetValueRef(rf.ruleCtx, x.getText())); break; case LOCAL: chunks.add(new LocalRef(nodeContext,x.getText())); break; case PREDEFINED_RULE: chunks.add(getRulePropertyRef(x)); break; } } if ( node.resolver.resolvesToToken(x.getText(), node) ) { chunks.add(new TokenRef(nodeContext,getTokenLabel(x.getText()))); // $label return; } if ( node.resolver.resolvesToLabel(x.getText(), node) ) { chunks.add(new LabelRef(nodeContext,getTokenLabel(x.getText()))); // $x for x=ID etc... return; } if ( node.resolver.resolvesToListLabel(x.getText(), node) ) { chunks.add(new ListLabelRef(nodeContext,x.getText())); // $ids for ids+=ID etc... return; } Rule r = factory.getGrammar().getRule(x.getText()); if ( r!=null ) { chunks.add(new LabelRef(nodeContext,getRuleLabel(x.getText()))); // $r for r rule ref } }