Exemple #1
0
        public static ParseNode[] GetFieldIdentifier(this ParseNode declaration)
        {
            ParseNode content = declaration.ChildrenSkipUnnamed().FirstOrDefault(n => n.RuleType == "plus" && n.RuleName == "declaration_content");

            if (content == null)
            {
                return(Array.Empty <ParseNode>());
            }

            return(content.ChildrenSkipUnnamed()
                   .TakeWhile(n => !EqualsMatch.IsMatch(n.ToString()))
                   .Select(Identifier)
                   .Where(n => n != null)
                   .ToArray());

            ParseNode Identifier(ParseNode parent)
            {
                if (parent.RuleType == "choice" && parent.RuleName == "node")
                {
                    ParseNode result = parent.FirstOrDefault();
                    if (result?.RuleName == "identifier" || result?.RuleName == "generic")
                    {
                        return(result);
                    }
                }

                return(null);
            }
        }
Exemple #2
0
        public static ParseNode[] GetFieldValue(this ParseNode declaration)
        {
            ParseNode content = declaration.ChildrenSkipUnnamed().FirstOrDefault(n => n.RuleType == "plus" && n.RuleName == "declaration_content");

            if (content == null)
            {
                return(Array.Empty <ParseNode>());
            }

            return(content.ChildrenSkipUnnamed()
                   .SkipWhile(n => !EqualsMatch.IsMatch(n.ToString()))
                   .Skip(1)
                   .Where(n => n.ToString() != ";")
                   .ToArray());
        }
Exemple #3
0
        public static bool IsValidFieldDeclaration(this ParseNode declaration)
        {
            return(!declaration.GetHierarchy().Any(IsForbiddenParanthesisGroup) &&
                   declaration.GetHierarchy().All(n => n.RuleName != "typedef_decl") &&
                   declaration.GetHierarchy().All(n => n.RuleName != "pp_directive"));

            bool IsForbiddenParanthesisGroup(ParseNode n)
            {
                if (n.RuleName != "paran_group")
                {
                    return(false);
                }

                ParseNode parent = n.GetParent();

                while (parent.Count(c => c.RuleName != "comment_set") == 1)
                {
                    n      = parent;
                    parent = n.GetParent();
                }

                return(parent.TakeWhile(c => c != n).All(c => !EqualsMatch.IsMatch(c.ToString())));
            }
        }