protected virtual void HandleOptionSetArg(string arg) { int eq = arg.IndexOf('='); if (eq > 0 && arg.Length > 3) { string option = arg.Substring("-D".Length, eq - "-D".Length); string value = arg.Substring(eq + 1); if (value.Length == 0) { errMgr.ToolError(ErrorType.BAD_OPTION_SET_SYNTAX, arg); return; } if (Grammar.parserOptions.Contains(option) || Grammar.lexerOptions.Contains(option)) { if (grammarOptions == null) { grammarOptions = new Dictionary <string, string>(); } grammarOptions[option] = value; } else { errMgr.GrammarError(ErrorType.ILLEGAL_OPTION, null, null, option); } } else { errMgr.ToolError(ErrorType.BAD_OPTION_SET_SYNTAX, arg); } }
private void HandleSetElementTokenReference(IIntSet elements, GrammarAST t) { int ttype; if (grammar.type == GrammarType.Lexer) { // recursively will invoke this rule to match elements in target rule ref IIntSet ruleSet = grammar.GetSetFromRule(this, t.Text); if (ruleSet == null) { ErrorManager.GrammarError(ErrorManager.MSG_RULE_INVALID_SET, grammar, t.Token, t.Text); } else { elements.AddAll(ruleSet); } } else { ttype = grammar.GetTokenType(t.Text); if (elements.Contains(ttype)) { ErrorManager.GrammarError(ErrorManager.MSG_DUPLICATE_SET_ENTRY, grammar, t.Token, t.Text); } elements.Add(ttype); } }
private StateCluster HandleNotAtomCharLiteral(GrammarAST notNode, GrammarAST charLiteral) { int ttype = 0; if (grammar.type == GrammarType.Lexer) { ttype = Grammar.GetCharValueFromGrammarCharLiteral(charLiteral.Text); } else { ttype = grammar.GetTokenType(charLiteral.Text); } IIntSet notAtom = grammar.Complement(ttype); if (notAtom.IsNil) { ErrorManager.GrammarError( ErrorManager.MSG_EMPTY_COMPLEMENT, grammar, charLiteral.Token, charLiteral.Text); } return(factory.BuildSet(notAtom, notNode)); }
private void HandleSetElementStringLiteral(IIntSet elements, GrammarAST s) { int ttype = grammar.GetTokenType(s.Text); if (elements.Contains(ttype)) ErrorManager.GrammarError(ErrorManager.MSG_DUPLICATE_SET_ENTRY, grammar, s.Token, s.Text); elements.Add(ttype); }
private void HandleSetElementCharLiteral(IIntSet elements, GrammarAST c) { int ttype; if (grammar.type == GrammarType.Lexer) ttype = Grammar.GetCharValueFromGrammarCharLiteral(c.Text); else ttype = grammar.GetTokenType(c.Text); if (elements.Contains(ttype)) ErrorManager.GrammarError(ErrorManager.MSG_DUPLICATE_SET_ENTRY, grammar, c.Token, c.Text); elements.Add(ttype); }
private void HandleRuleScopeSpecUses(Rule r, GrammarAST uses) { if (grammar.GetGlobalScope(uses.Text) == null) { ErrorManager.GrammarError(ErrorManager.MSG_UNKNOWN_DYNAMIC_SCOPE, grammar, uses.Token, uses.Text); } else { if (r.UseScopes == null) { r.UseScopes = new List <string>(); } r.UseScopes.Add(uses.Text); } }
private StateCluster HandleNotAtomSet(GrammarAST notNode, GrammarAST setNode) { //IIntSet notSet = grammar.Complement(stNode.SetValue); // let code generator complement the sets IIntSet s = setNode.SetValue; setNode.SetValue = s; // let code gen do the complement again; here we compute // for NFA construction s = grammar.Complement(s); if (s.IsNil) { ErrorManager.GrammarError( ErrorManager.MSG_EMPTY_COMPLEMENT, grammar, notNode.Token); } return factory.BuildSet(s, notNode); }
private StateCluster HandleNotAtomTokenReference(GrammarAST notNode, GrammarAST tokenReference) { int ttype = 0; IIntSet notAtom = null; if (grammar.type == GrammarType.Lexer) { notAtom = grammar.GetSetFromRule(this, tokenReference.Text); if (notAtom == null) { ErrorManager.GrammarError( ErrorManager.MSG_RULE_INVALID_SET, grammar, tokenReference.Token, tokenReference.Text); } else { notAtom = grammar.Complement(notAtom); } } else { ttype = grammar.GetTokenType(tokenReference.Text); notAtom = grammar.Complement(ttype); } if (notAtom == null || notAtom.IsNil) { ErrorManager.GrammarError( ErrorManager.MSG_EMPTY_COMPLEMENT, grammar, tokenReference.Token, tokenReference.Text); } return(factory.BuildSet(notAtom, notNode)); }
// LISTENER METHODS // $x.y public virtual void QualifiedAttr(string expr, IToken x, IToken y) { if (g.IsLexer()) { errMgr.GrammarError(ErrorType.ATTRIBUTE_IN_LEXER_ACTION, g.fileName, x, x.Text + "." + y.Text, expr); return; } if (node.resolver.ResolveToAttribute(x.Text, node) != null) { // must be a member access to a predefined attribute like $ctx.foo Attr(expr, x); return; } if (node.resolver.ResolveToAttribute(x.Text, y.Text, node) == null) { Rule rref = IsolatedRuleRef(x.Text); if (rref != null) { if (rref.args != null && rref.args.Get(y.Text) != null) { g.tool.errMgr.GrammarError(ErrorType.INVALID_RULE_PARAMETER_REF, g.fileName, y, y.Text, rref.name, expr); } else { errMgr.GrammarError(ErrorType.UNKNOWN_RULE_ATTRIBUTE, g.fileName, y, y.Text, rref.name, expr); } } else if (!node.resolver.ResolvesToAttributeDict(x.Text, node)) { errMgr.GrammarError(ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE, g.fileName, x, x.Text, expr); } else { errMgr.GrammarError(ErrorType.UNKNOWN_ATTRIBUTE_IN_SCOPE, g.fileName, y, y.Text, expr); } } }
public virtual void CheckActionRedefinitions(IList <GrammarAST> actions) { if (actions == null) { return; } string scope = g.GetDefaultActionScope(); string name; GrammarAST nameNode; foreach (GrammarAST ampersandAST in actions) { nameNode = (GrammarAST)ampersandAST.GetChild(0); if (ampersandAST.ChildCount == 2) { name = nameNode.Text; } else { scope = nameNode.Text; name = ampersandAST.GetChild(1).Text; } ISet <string> scopeActions; if (!actionScopeToActionNames.TryGetValue(scope, out scopeActions) || scopeActions == null) { // init scope scopeActions = new HashSet <string>(); actionScopeToActionNames[scope] = scopeActions; } if (!scopeActions.Contains(name)) { scopeActions.Add(name); } else { errMgr.GrammarError(ErrorType.ACTION_REDEFINITION, g.fileName, nameNode.Token, name); } } }