private void HandleLocalAttribute(string name) { StringTemplate st; AttributeScope scope = enclosingRule.GetLocalAttributeScope(name); if (scope.IsPredefinedRuleScope) { st = Template("rulePropertyRef_" + name); grammar.ReferenceRuleLabelPredefinedAttribute(enclosingRule.Name); st.SetAttribute("scope", enclosingRule.Name); st.SetAttribute("attr", name); } else if (scope.IsPredefinedLexerRuleScope) { st = Template("lexerRulePropertyRef_" + name); st.SetAttribute("scope", enclosingRule.Name); st.SetAttribute("attr", name); } else if (scope.IsParameterScope) { st = Template("parameterAttributeRef"); st.SetAttribute("attr", scope.GetAttribute(name)); } else { st = Template("returnAttributeRef"); st.SetAttribute("ruleDescriptor", enclosingRule); st.SetAttribute("attr", scope.GetAttribute(name)); } }
private bool CanMatchDynamicScopeAttribute(string x, string y) { AttributeScope dynamicScope = ResolveDynamicScope(x); return(dynamicScope != null && dynamicScope.GetAttribute(y) != null); }
private void HandleSetLocalAttribute(string attributeName, string expr) { StringTemplate st; AttributeScope scope = enclosingRule.GetLocalAttributeScope(attributeName); if (scope.IsPredefinedRuleScope) { if (attributeName.Equals("tree") || attributeName.Equals("st")) { st = Template("ruleSetPropertyRef_" + attributeName); grammar.ReferenceRuleLabelPredefinedAttribute(enclosingRule.Name); st.SetAttribute("scope", enclosingRule.Name); st.SetAttribute("attr", attributeName); st.SetAttribute("expr", TranslateAction(expr)); } else { ErrorManager.GrammarError(ErrorManager.MSG_WRITE_TO_READONLY_ATTR, grammar, actionToken, attributeName, ""); } } else if (scope.IsParameterScope) { st = Template("parameterSetAttributeRef"); st.SetAttribute("attr", scope.GetAttribute(attributeName)); st.SetAttribute("expr", TranslateAction(expr)); } else { st = Template("returnSetAttributeRef"); st.SetAttribute("ruleDescriptor", enclosingRule); st.SetAttribute("attr", scope.GetAttribute(attributeName)); st.SetAttribute("expr", TranslateAction(expr)); } }
private void HandleEnclosingRuleScopeAttribute(string x, string y) { if (IsRuleRefInAlt(x)) { ErrorManager.GrammarError(ErrorManager.MSG_RULE_REF_AMBIG_WITH_RULE_IN_ALT, grammar, actionToken, x); } StringTemplate st = null; AttributeScope scope = enclosingRule.GetLocalAttributeScope(y); if (scope.IsPredefinedRuleScope) { st = Template("rulePropertyRef_" + y); grammar.ReferenceRuleLabelPredefinedAttribute(x); st.SetAttribute("scope", x); st.SetAttribute("attr", y); } else if (scope.IsPredefinedLexerRuleScope) { // perhaps not the most precise error message to use, but... ErrorManager.GrammarError(ErrorManager.MSG_RULE_HAS_NO_ARGS, grammar, actionToken, x); } else if (scope.IsParameterScope) { st = Template("parameterAttributeRef"); st.SetAttribute("attr", scope.GetAttribute(y)); } else { // must be return value st = Template("returnAttributeRef"); st.SetAttribute("ruleDescriptor", enclosingRule); st.SetAttribute("attr", scope.GetAttribute(y)); } }
/** For \$rulelabel.name, return the Attribute found for name. It * will be a predefined property or a return value. */ public Attribute GetRuleLabelAttribute(string ruleName, string attrName) { Rule r = grammar.GetRule(ruleName); AttributeScope scope = r.GetLocalAttributeScope(attrName); if (scope != null && !scope.IsParameterScope) { return(scope.GetAttribute(attrName)); } return(null); }
private void HandleDynamicScopeAttribute(string x, string y) { AttributeScope scope = ResolveDynamicScope(x); if (scope != null) { StringTemplate st = Template("scopeAttributeRef"); st.SetAttribute("scope", x); st.SetAttribute("attr", scope.GetAttribute(y)); } else { // error: invalid dynamic attribute } }
private void HandleRuleScopeAttribute(string x, string y) { Grammar.LabelElementPair pair = enclosingRule.GetRuleLabel(x); string refdRuleName = pair != null ? pair.referencedRuleName : x; string label = x; if (pair == null) { // $ruleref.attr gotta get old label or compute new one CheckElementRefUniqueness(x, false); label = enclosingRule.GetElementLabel(x, outerAltNum, generator); if (label == null) { ErrorManager.GrammarError(ErrorManager.MSG_FORWARD_ELEMENT_REF, grammar, actionToken, "$" + x + "." + y); label = x; } } StringTemplate st; Rule refdRule = grammar.GetRule(refdRuleName); AttributeScope scope = refdRule.GetLocalAttributeScope(y); if (scope.IsPredefinedRuleScope) { st = Template("ruleLabelPropertyRef_" + y); grammar.ReferenceRuleLabelPredefinedAttribute(refdRuleName); st.SetAttribute("scope", label); st.SetAttribute("attr", y); } else if (scope.IsPredefinedLexerRuleScope) { st = Template("lexerRuleLabelPropertyRef_" + y); grammar.ReferenceRuleLabelPredefinedAttribute(refdRuleName); st.SetAttribute("scope", label); st.SetAttribute("attr", y); } else if (scope.IsParameterScope) { // TODO: error! } else { st = Template("ruleLabelRef"); st.SetAttribute("referencedRule", refdRule); st.SetAttribute("scope", label); st.SetAttribute("attr", scope.GetAttribute(y)); } }
private void HandleSetEnclosingRuleScopeAttribute(string x, string y, string expr) { StringTemplate st = null; AttributeScope scope = enclosingRule.GetLocalAttributeScope(y); if (scope.IsPredefinedRuleScope) { if (y.Equals("st") || y.Equals("tree")) { st = Template("ruleSetPropertyRef_" + y); grammar.ReferenceRuleLabelPredefinedAttribute(x); st.SetAttribute("scope", x); st.SetAttribute("attr", y); st.SetAttribute("expr", TranslateAction(expr)); } else { ErrorManager.GrammarError(ErrorManager.MSG_WRITE_TO_READONLY_ATTR, grammar, actionToken, x, y); } } else if (scope.IsPredefinedLexerRuleScope) { // this is a better message to emit than the previous one... ErrorManager.GrammarError(ErrorManager.MSG_WRITE_TO_READONLY_ATTR, grammar, actionToken, x, y); } else if (scope.IsParameterScope) { st = Template("parameterSetAttributeRef"); st.SetAttribute("attr", scope.GetAttribute(y)); st.SetAttribute("expr", TranslateAction(expr)); } else { // must be return value st = Template("returnSetAttributeRef"); st.SetAttribute("ruleDescriptor", enclosingRule); st.SetAttribute("attr", scope.GetAttribute(y)); st.SetAttribute("expr", TranslateAction(expr)); } }