public SemPred(OutputModelFactory factory, [NotNull] ActionAST ast) : base(factory, ast) { Debug.Assert(ast.atnState != null && ast.atnState.NumberOfTransitions == 1 && ast.atnState.Transition(0) is AbstractPredicateTransition); GrammarAST failNode = ast.GetOptionAST("fail"); predicate = ast.Text; if (predicate.StartsWith("{") && predicate.EndsWith("}?")) { predicate = predicate.Substring(1, predicate.Length - 3); } predicate = factory.GetTarget().GetTargetStringLiteralFromString(predicate); if (failNode == null) return; if (failNode is 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.Text, true); } }
/** Build a file with a parser containing rule functions. Use the * controller as factory in SourceGenTriggers so it triggers code generation * extensions too, not just the factory functions in this factory. */ public virtual OutputModelObject BuildParserOutputModel(bool header) { CodeGenerator gen = @delegate.GetGenerator(); ParserFile file = ParserFile(gen.GetRecognizerFileName(header)); SetRoot(file); file.parser = Parser(file); Grammar g = @delegate.GetGrammar(); foreach (Rule r in g.rules.Values) { BuildRuleFunction(file.parser, r); } return(file); }
public MatchSet(OutputModelFactory factory, GrammarAST ast) : base(factory, ast) { SetTransition st = (SetTransition)ast.atnState.Transition(0); int wordSize = factory.GetGenerator().GetTarget().GetInlineTestSetWordSize(); expr = new TestSetInline(factory, null, st.set, wordSize); Decl.Decl d = new TokenTypeDecl(factory, expr.varName); factory.GetCurrentRuleFunction().AddLocalDecl(d); capture = new CaptureNextTokenType(factory, expr.varName); }
protected static string TranslateTokenStringToTarget(string tokenName, OutputModelFactory factory) { if (tokenName == null) { return(null); } if (tokenName[0] == '\'') { bool addQuotes = false; string targetString = factory.GetTarget().GetTargetStringLiteralFromANTLRStringLiteral(factory.GetGenerator(), tokenName, addQuotes); return("\"'" + targetString + "'\""); } else { return(factory.GetTarget().GetTargetStringLiteralFromString(tokenName, true)); } }
public ActionTranslator(OutputModelFactory factory, ActionAST node) { this.factory = factory; this.node = node; this.gen = factory.GetGenerator(); }
public SemPred(OutputModelFactory factory, [NotNull] ActionAST ast) : base(factory, ast) { Debug.Assert(ast.atnState != null && ast.atnState.NumberOfTransitions == 1 && ast.atnState.Transition(0) is AbstractPredicateTransition); GrammarAST failNode = ast.GetOptionAST("fail"); predicate = ast.Text; if (predicate.StartsWith("{") && predicate.EndsWith("}?")) { predicate = predicate.Substring(1, predicate.Length - 3); } predicate = factory.GetTarget().GetTargetStringLiteralFromString(predicate); if (failNode == null) { return; } if (failNode is 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.Text, true); } }
protected static string TranslateTokenStringToTarget(string tokenName, OutputModelFactory factory) { if (tokenName == null) { return null; } if (tokenName[0] == '\'') { bool addQuotes = false; string targetString = factory.GetTarget().GetTargetStringLiteralFromANTLRStringLiteral(factory.GetGenerator(), tokenName, addQuotes); return "\"'" + targetString + "'\""; } else { return factory.GetTarget().GetTargetStringLiteralFromString(tokenName, true); } }