private bool CanMatchRuleScopeAttribute(string x, string y) { if (enclosingRule == null) { return(false); } Grammar.LabelElementPair label = enclosingRule.GetRuleLabel(x); string ruleName = label != null ? label.referencedRuleName : x; string attributeName = y; return((label != null || IsRuleRefInAlt(x)) && GetRuleLabelAttribute(ruleName, attributeName) != null); }
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 bool CanMatchSetRuleScopeAttribute(string x, string y) { // This asserts that if it's a label or a ref to a rule proceed but only if the attribute // is valid for that rule's scope if (enclosingRule == null || input.LA(1) == '=') { return(false); } Grammar.LabelElementPair label = enclosingRule.GetRuleLabel(x); string ruleName = label != null ? label.referencedRuleName : x; string attributeName = y; return((label != null || IsRuleRefInAlt(x)) && GetRuleLabelAttribute(ruleName, attributeName) != null); }
private void HandleLabelReference(string label) { StringTemplate st; Grammar.LabelElementPair pair = GetElementLabel(label); if (pair.type == Tool.LabelType.RuleList || pair.type == Tool.LabelType.TokenList || pair.type == Tool.LabelType.WildcardTreeList) { st = Template("listLabelRef"); } else { st = Template("tokenLabelRef"); } st.SetAttribute("label", label); }
public bool IsListLabel(string label) { bool hasListLabel = false; if (label != null) { Rule r = grammar.GetRule(currentRuleName); //String stName = null; if (r != null) { Grammar.LabelElementPair pair = r.GetLabel(label); if (pair != null && (pair.type == LabelType.TokenList || pair.type == LabelType.RuleList || pair.type == LabelType.WildcardTreeList)) { hasListLabel = true; } } } return(hasListLabel); }