示例#1
0
        /// <summary>To test changes to the meta grammar.</summary>
        private static CodeDocument TestMetaGrammarDoc()
        {
            CodeDocument grammar = new CodeDocument(new List <CodeElement>(), MetaParser.Grammar);

            // grammar   = {rule}
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "Grammar"),
                                        new HardElement("sequence", string.Empty,
                                                        new HardElement("identifier", "rule")),
                                        new HardElement("optional", string.Empty,
                                                        new HardElement("identifier", MetaParser.Settings___))));

            // rule = identifier '=' expression ';'
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "rule"),
                                        new HardElement("identifier", "identifier"),
                                        new HardElement("symbol", "="),
                                        new HardElement("identifier", "expression"),
                                        new HardElement("symbol", ";")));

            // expression = element {[or] element};
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "expression"),
                                        new HardElement("identifier", MetaParser.Element____),
                                        new HardElement("sequence", string.Empty,
                                                        new HardElement("optional", string.Empty,
                                                                        new HardElement("identifier", MetaParser.Or_________)),
                                                        new HardElement("identifier", MetaParser.Element____))));

            // element    = identifier | symbol | block; Husk ny block
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", MetaParser.Element____),
                                        new HardElement("identifier", "identifier"),
                                        new HardElement(MetaParser.Or_________, string.Empty),
                                        new HardElement("identifier", "symbol"),
                                        new HardElement(MetaParser.Or_________, string.Empty),
                                        new HardElement("identifier", "sequence"),
                                        new HardElement(MetaParser.Or_________, string.Empty),
                                        new HardElement("identifier", "optional"),
                                        new HardElement("or", string.Empty),
                                        new HardElement("identifier", "parentheses")));

            // sequence      = '{' expression '}';
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "sequence"),
                                        new HardElement("symbol", "{"),
                                        new HardElement("identifier", "expression"),
                                        new HardElement("symbol", "}")));

            // optional     = '[' expression ']';
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "optional"),
                                        new HardElement("symbol", "["),
                                        new HardElement("identifier", "expression"),
                                        new HardElement("symbol", "]")));

            // parentheses      = '(' expression ')';
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "parentheses"),
                                        new HardElement("symbol", "("),
                                        new HardElement("identifier", "expression"),
                                        new HardElement("symbol", ")")));

            // or         = '|';
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "or"),
                                        new HardElement("symbol", "|")));

            //// ruleId      > identifier;
            //grammar.AddElement(new HardElement("rule", string.Empty,
            //    new HardElement("identifier", "ruleId"),
            //    new HardElement("identifier", "identifier")));

            // symbol     = string;
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "symbol"),
                                        new HardElement("identifier", "string")));

            // settings    = 'settings' {setter};
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "settings"),
                                        new HardElement("symbol", "settings"),
                                        new HardElement("sequence", string.Empty,
                                                        new HardElement("identifier", MetaParser.Setter_____))));

            // setter      = identifier assignment {',' assignment} ';';
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "setter"),
                                        new HardElement("identifier", "identifier"),
                                        new HardElement("identifier", "assignment"),
                                        new HardElement("sequence", string.Empty,
                                                        new HardElement("symbol", ","),
                                                        new HardElement("identifier", "assignment")),
                                        new HardElement("symbol", ";")));

            // assignment  = property ['=' value];
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "assignment"),
                                        new HardElement("identifier", MetaParser.Property___),
                                        new HardElement("optional", string.Empty,
                                                        new HardElement("symbol", "="),
                                                        new HardElement("identifier", MetaParser.Value______))));

            // property    = identifier;
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "property"),
                                        new HardElement("identifier", "identifier")));

            // value       = string;
            grammar.Add(new HardElement("rule", string.Empty,
                                        new HardElement("identifier", "value"),
                                        new HardElement("identifier", "string")));

            // settings
            // expression collapse;
            grammar.Add(new HardElement("setter", string.Empty,
                                        new HardElement("identifier", "rule"),
                                        new HardElement("assignment", string.Empty,
                                                        new HardElement("property", "comment"))));

            // expression collapse;
            grammar.Add(new HardElement("setter", string.Empty,
                                        new HardElement("identifier", "expression"),
                                        new HardElement("assignment", string.Empty,
                                                        new HardElement("property", "collapse"))));

            // element    collapse;
            grammar.Add(new HardElement("setter", string.Empty,
                                        new HardElement("identifier", "element"),
                                        new HardElement("assignment", string.Empty,
                                                        new HardElement("property", "collapse"))));

            // settings collapse;
            grammar.Add(new HardElement("setter", string.Empty,
                                        new HardElement("identifier", "settings"),
                                        new HardElement("assignment", string.Empty,
                                                        new HardElement("property", "collapse"))));

            return(grammar);
        }