Пример #1
0
        /**  $x		Attribute: rule arguments, return values, predefined rule prop.
         */
        public virtual Attribute ResolveToAttribute(string x, ActionAST node)
        {
            if (args != null)
            {
                Attribute a = args.Get(x);
                if (a != null)
                {
                    return(a);
                }
            }
            if (retvals != null)
            {
                Attribute a = retvals.Get(x);
                if (a != null)
                {
                    return(a);
                }
            }
            if (locals != null)
            {
                Attribute a = locals.Get(x);
                if (a != null)
                {
                    return(a);
                }
            }
            AttributeDict properties = GetPredefinedScope(LabelType.RULE_LABEL);

            return(properties.Get(x));
        }
Пример #2
0
        /** $x.y, x can be surrounding rule, token/rule/label ref. y is visible
         *  attr in that dictionary.  Can't see args on rule refs.
         */
        public virtual Attribute ResolveToAttribute(string x, string y, ActionAST node)
        {
            if (tokenRefs.ContainsKey(x) && tokenRefs[x] != null)
            {
                // token ref in this alt?
                return(rule.GetPredefinedScope(LabelType.TOKEN_LABEL).Get(y));
            }

            if (ruleRefs.ContainsKey(x) && ruleRefs[x] != null)
            {
                // rule ref in this alt?
                // look up rule, ask it to resolve y (must be retval or predefined)
                return(rule.g.GetRule(x).ResolveRetvalOrProperty(y));
            }

            LabelElementPair anyLabelDef = GetAnyLabelDef(x);

            if (anyLabelDef != null && anyLabelDef.type == LabelType.RULE_LABEL)
            {
                return(rule.g.GetRule(anyLabelDef.element.Text).ResolveRetvalOrProperty(y));
            }
            else if (anyLabelDef != null)
            {
                AttributeDict scope = rule.GetPredefinedScope(anyLabelDef.type);
                if (scope == null)
                {
                    return(null);
                }

                return(scope.Get(y));
            }
            return(null);
        }
Пример #3
0
        public ISet <string> Intersection([Nullable] AttributeDict other)
        {
            if (other == null || other.Size() == 0 || Size() == 0)
            {
                return(new HashSet <string>());
            }

            ISet <string> result = new HashSet <string>(attributes.Keys);

            result.IntersectWith(other.attributes.Keys);
            return(result);
        }
Пример #4
0
        public virtual Attribute ResolveRetvalOrProperty(string y)
        {
            if (retvals != null)
            {
                Attribute a = retvals.Get(y);
                if (a != null)
                {
                    return(a);
                }
            }
            AttributeDict d = GetPredefinedScope(LabelType.RULE_LABEL);

            return(d.Get(y));
        }
Пример #5
0
 public static AttributeDict Parse([Nullable] ActionAST action, string s, char separator, Grammar g)
 {
     AttributeDict dict = new AttributeDict();
     IList<System.Tuple<string, int>> decls = SplitDecls(s, separator);
     foreach (System.Tuple<string, int> decl in decls)
     {
         if (decl.Item1.Trim().Length > 0)
         {
             Attribute a = ParseAttributeDef(action, decl, g);
             dict.Add(a);
         }
     }
     return dict;
 }
Пример #6
0
        /** $x.y	Attribute: x is surrounding rule, label ref (in any alts) */
        public virtual Attribute ResolveToAttribute(string x, string y, ActionAST node)
        {
            LabelElementPair anyLabelDef = GetAnyLabelDef(x);

            if (anyLabelDef != null)
            {
                if (anyLabelDef.type == LabelType.RULE_LABEL)
                {
                    return(g.GetRule(anyLabelDef.element.Text).ResolveRetvalOrProperty(y));
                }
                else
                {
                    AttributeDict scope = GetPredefinedScope(anyLabelDef.type);
                    if (scope == null)
                    {
                        return(null);
                    }

                    return(scope.Get(y));
                }
            }
            return(null);
        }