public OffsetGrammar(IParserSettings settings) : base(settings)
        {
            ParseAction <Chain <char, char> > action  = Grammar.Opt <char>(CharGrammar.Ch('\r')).And <char, char>(CharGrammar.Ch('\n').Or <char>(CharGrammar.ChSTX()).Or <char>(CharGrammar.ChETX()));
            ParseAction <Chain <char, char> > action2 = Grammar.Opt <char>(CharGrammar.Ch('\r')).And <char, char>(CharGrammar.Ch('\n').Or <char>(CharGrammar.ChSTX()));
            ParseAction <Chain <char, char> > cond    = Grammar.Opt <char>(CharGrammar.Ch('\r')).And <char, char>(CharGrammar.Ch('\n').Or <char>(CharGrammar.ChETX()));
            ParseAction <IndentationNode>     action4 = action2.And <Chain <char, char>, IList <char> >(Grammar.Rep <char>(CharGrammar.Ch(new char[] { ' ', '\t' }))).NotNext <Chain <Chain <char, char>, IList <char> >, Chain <char, char> >(cond).Build <Chain <Chain <char, char>, IList <char> >, IndentationNode>(hit => new IndentationNode(hit.Down));

            Grammar.Rep1 <char>(CharGrammar.Ch(new char[] { ' ', '\t' }));
            ParseAction <IList <char> >  action5  = Grammar.Rep <char>(CharGrammar.Ch(new char[] { ' ', '\t' }));
            ParseAction <Node[]>         action6  = action2.And <Chain <char, char>, IList <char> >(Grammar.Rep <char>(CharGrammar.Ch(new char[] { ' ', '\t' }))).IfNext <Chain <Chain <char, char>, IList <char> >, Chain <char, char> >(cond).Build <Chain <Chain <char, char>, IList <char> >, Node[]>(hit => new Node[0]);
            ParseAction <char>           parse    = CharGrammar.Ch(new Func <char, bool>(char.IsLetterOrDigit)).Or <char>(CharGrammar.Ch(new char[] { '-', '_', ':' }));
            ParseAction <string>         action8  = CharGrammar.Ch(new Func <char, bool>(char.IsLetter)).Or <char>(CharGrammar.Ch(new char[] { '_', ':' })).And <char, IList <char> >(Grammar.Rep <char>(parse)).Build <Chain <char, IList <char> >, string>(hit => hit.Left + new string(hit.Down.ToArray <char>()));
            ParseAction <TextNode>       action9  = CharGrammar.Ch('|').And <char, IList <char> >(Grammar.Rep <char>(CharGrammar.Ch((Func <char, bool>)(_ => true)).Unless <char, Chain <char, char> >(action))).Build <Chain <char, IList <char> >, TextNode>(hit => new TextNode(hit.Down));
            ParseAction <Node>           action10 = base.AsNode <EntityNode>(base.EntityRef).Or <Node>(base.AsNode <ExpressionNode>(base.Code));
            ParseAction <TextNode>       parser   = Grammar.Rep1 <char>(CharGrammar.Ch((Func <char, bool>)(ch => true)).Unless <char, Chain <char, char> >(cond).Unless <char, Node>(action10)).Build <IList <char>, TextNode>(hit => new TextNode(hit));
            ParseAction <IList <Node> >  action12 = CharGrammar.Ch('|').And <char, IList <Node> >(Grammar.Rep <Node>(base.AsNode <TextNode>(parser).Or <Node>(action10))).Build <Chain <char, IList <Node> >, IList <Node> >(hit => hit.Down);
            ParseAction <ExpressionNode> action13 = CharGrammar.Ch('=').And <char, Snippets>(base.LimitedExpression(cond.Build <Chain <char, char>, string>(x => ""))).Build <Chain <char, Snippets>, ExpressionNode>(hit => new ExpressionNode(hit.Down)
            {
                AutomaticEncoding = true
            });
            ParseAction <StatementNode> action14 = CharGrammar.Ch('-').And <char, IList <Snippet> >(base.Statement1).Build <Chain <char, IList <Snippet> >, StatementNode>(hit => new StatementNode(hit.Down));
            ParseAction <StatementNode> action15 = CharGrammar.Ch("@{").And <string, Snippets>(base.LimitedExpression(CharGrammar.Ch("}"))).And <Chain <string, Snippets>, char>(CharGrammar.Ch('}')).Build <Chain <Chain <string, Snippets>, char>, StatementNode>(hit => new StatementNode(hit.Left.Down));
            ParseAction <StatementNode> action16 = action14.Or <StatementNode>(action15);
            ParseAction <string>        action17 = CharGrammar.Ch('#').And <char, IList <char> >(Grammar.Rep <char>(CharGrammar.Ch(new Func <char, bool>(char.IsLetterOrDigit)).Or <char>(CharGrammar.Ch(new char[] { '-', '_' })))).Skip <Chain <char, IList <char> >, IList <char> >(action5).Build <Chain <char, IList <char> >, string>(hit => new string(hit.Down.ToArray <char>()));
            ParseAction <string>        action18 = CharGrammar.Ch('.').And <char, IList <char> >(Grammar.Rep <char>(CharGrammar.Ch(new Func <char, bool>(char.IsLetterOrDigit)).Or <char>(CharGrammar.Ch(new char[] { '-', '_' })))).Skip <Chain <char, IList <char> >, IList <char> >(action5).Build <Chain <char, IList <char> >, string>(hit => new string(hit.Down.ToArray <char>()));
            var action19 = Grammar.Rep <string>(action18).And <IList <string>, string>(Grammar.Opt <string>(action17)).And <Chain <IList <string>, string>, IList <string> >(Grammar.Rep <string>(action18)).Build(hit => new { id = hit.Left.Down, classes = hit.Left.Left.Concat <string>(hit.Down) });
            var action20 = Grammar.Rep <string>(action18).And <IList <string>, string>(action17).And <Chain <IList <string>, string>, IList <string> >(Grammar.Rep <string>(action18)).Or <Chain <Chain <IList <string>, string>, IList <string> > >(Grammar.Rep1 <string>(action18).And <IList <string>, string>(Grammar.Opt <string>(action17)).And <Chain <IList <string>, string>, IList <string> >(Grammar.Rep <string>(action18))).Or <Chain <Chain <IList <string>, string>, IList <string> > >(Grammar.Rep <string>(action18).And <IList <string>, string>(Grammar.Opt <string>(action17)).And <Chain <IList <string>, string>, IList <string> >(Grammar.Rep1 <string>(action18))).Build(hit => new { id = hit.Left.Down, classes = hit.Left.Left.Concat <string>(hit.Down) });
            ParseAction <ElementNode>   action22 = action8.Skip <string, IList <char> >(action5).And(action19).Or(Grammar.Opt <string>(action8).And(action20)).Build(hit => new { name = hit.Left ?? "div", attrs = ((hit.Down.id != null) ? new AttributeNode[] { new AttributeNode("id", hit.Down.id) } : new AttributeNode[0]).Concat <AttributeNode>(hit.Down.classes.Any <string>() ? new AttributeNode[] { new AttributeNode("class", string.Join(" ", hit.Down.classes.ToArray <string>())) } : new AttributeNode[0]) }).And(Grammar.Rep <AttributeNode>(base.Attribute.Skip <AttributeNode, IList <char> >(action5))).Build(hit => new ElementNode(hit.Left.name, hit.Left.attrs.Concat <AttributeNode>(hit.Down).ToList <AttributeNode>(), false));
            ParseAction <IList <Node> > action23 = action12.Or <IList <Node> >(action13.Build <ExpressionNode, IList <Node> >(hit => ((IList <Node>) new Node[] { hit }))).Or <IList <Node> >(action16.Build <StatementNode, IList <Node> >(hit => (IList <Node>) new Node[] { hit }));
            ParseAction <Chain <ElementNode, IList <Node> > > action24 = action22.Skip <ElementNode, IList <char> >(action5).And <ElementNode, IList <Node> >(Grammar.Opt <IList <Node> >(action23));
            ParseAction <Node[]>          action25 = action4.And <IndentationNode, Chain <ElementNode, IList <Node> > >(action24).Build <Chain <IndentationNode, Chain <ElementNode, IList <Node> > >, Node[]>(hit => new Node[] { hit.Left, hit.Down.Left }.Concat <Node>((hit.Down.Down ?? ((IList <Node>) new Node[0]))).ToArray <Node>());
            ParseAction <Node[]>          action26 = action4.And <IndentationNode, IList <Node> >(action12).Build <Chain <IndentationNode, IList <Node> >, Node[]>(hit => new Node[] { hit.Left }.Concat <Node>(hit.Down).ToArray <Node>());
            ParseAction <Node[]>          action27 = action4.And <IndentationNode, ExpressionNode>(action13).Build <Chain <IndentationNode, ExpressionNode>, Node[]>(hit => new Node[] { hit.Left, hit.Down });
            ParseAction <Node[]>          action28 = action4.And <IndentationNode, StatementNode>(action16).Build <Chain <IndentationNode, StatementNode>, Node[]>(hit => new Node[] { hit.Left, hit.Down });
            ParseAction <Node[]>          action29 = action24.Build <Chain <ElementNode, IList <Node> >, Node[]>(hit => new Node[] { hit.Left }.Concat <Node>((hit.Down ?? ((IList <Node>) new Node[0]))).ToArray <Node>());
            ParseAction <Node[]>          action30 = action6.Or <Node[]>(action25).Or <Node[]>(action26).Or <Node[]>(action27).Or <Node[]>(action28).Or <Node[]>(action29).Skip <Node[], IList <char> >(action5);
            ParseAction <IList <Node[]> > action31 = Grammar.Rep <Node[]>(action30);

            this.Indentation      = action4;
            this.TestLine         = action30;
            this.OffsetElement    = action22;
            this.OffsetText       = action9;
            this.OffsetTexts      = action12;
            this.OffsetExpression = action13;
            this.OffsetStatement  = action16;
            this.OffsetNodes      = action31.Build <IList <Node[]>, IList <Node> >(hit => (from nodes in hit select from node in nodes
                                                                                           where node != null
                                                                                           select node).ToList <Node>());
        }
            public UseMasterGrammar()
            {
                ParseAction <IList <char> > whiteSpace0    = Rep(Ch(char.IsWhiteSpace));
                ParseAction <IList <char> > whiteSpace1    = Rep1(Ch(char.IsWhiteSpace));
                ParseAction <string>        startOfElement = Ch("<use");
                ParseAction <Chain <Chain <Chain <string, IList <char> >, char>, IList <char> > > startOfAttribute = Ch("master").And(whiteSpace0).And(Ch('=')).And(whiteSpace0);
                ParseAction <Chain <Chain <char, IList <char> >, char> > attrValue = Ch('\'').And(Rep(ChNot('\''))).And(Ch('\''))
                                                                                     .Or(Ch('\"').And(Rep(ChNot('\"'))).And(Ch('\"')));

                ParseAction <string> endOfElement = Ch("/>");

                ParseAction <string> useMaster = startOfElement
                                                 .And(whiteSpace1)
                                                 .And(startOfAttribute)
                                                 .And(attrValue)
                                                 .And(whiteSpace0)
                                                 .And(endOfElement)
                                                 .Build(hit => new string(hit.Left.Left.Down.Left.Down.ToArray()));

                ParseUseMaster =
                    pos =>
                {
                    for (Position scan = pos; scan.PotentialLength() != 0; scan = scan.Advance(1))
                    {
                        ParseResult <string> result = useMaster(scan);
                        if (result != null)
                        {
                            return(result);
                        }
                    }
                    return(null);
                };
            }
        public JavascriptAnonymousTypeGrammar()
        {
            ParseAction <IList <char> > action = Grammar.Rep <char>(CharGrammar.Ch(new char[] { ' ', '\t', '\r', '\n' }));
            ParseAction <Chain <char, IList <char> > > parser = CharGrammar.Ch(new Func <char, bool>(char.IsLetter)).Or <char>(CharGrammar.Ch('_')).And <char, IList <char> >(Grammar.Rep <char>(CharGrammar.Ch(new Func <char, bool>(char.IsLetterOrDigit)).Or <char>(CharGrammar.Ch('_'))));
            ParseAction <Chain <Chain <char, IList <char> >, char> > action3 = CharGrammar.Ch('"').And <char, IList <char> >(Grammar.Rep <char>(CharGrammar.ChNot('"'))).And <Chain <char, IList <char> >, char>(CharGrammar.Ch('"'));
            ParseAction <Chain <Chain <char, IList <char> >, char> > action4 = CharGrammar.Ch('\'').And <char, IList <char> >(Grammar.Rep <char>(CharGrammar.ChNot('\''))).And <Chain <char, IList <char> >, char>(CharGrammar.Ch('\''));
            ParseAction <string>          action5 = new ParseAction <string>(this.ValuePart);
            ParseAction <IList <string> > action7 = Grammar.Rep <string>(Str <IList <char> >(Grammar.Rep1 <char>(CharGrammar.ChNot(new char[] { '}', ',' }).Unless <char, string>(action5))).Or <string>(action5));
            ParseAction <string>          action8 = action.And <IList <char>, string>(Str <Chain <char, IList <char> > >(parser)).And <Chain <IList <char>, string>, IList <char> >(action).And <Chain <Chain <IList <char>, string>, IList <char> >, char>(CharGrammar.Ch('=')).And <Chain <Chain <Chain <IList <char>, string>, IList <char> >, char>, IList <char> >(action).And <Chain <Chain <Chain <Chain <IList <char>, string>, IList <char> >, char>, IList <char> >, IList <string> >(action7).Build <Chain <Chain <Chain <Chain <Chain <IList <char>, string>, IList <char> >, char>, IList <char> >, IList <string> >, string>(hit => hit.Left.Left.Left.Left.Down + ":" + string.Concat(hit.Down.ToArray <string>()));
            ParseAction <Chain <Chain <IList <char>, char>, IList <char> > > action9 = action.And <IList <char>, char>(CharGrammar.Ch(',')).And <Chain <IList <char>, char>, IList <char> >(action);
            ParseAction <IEnumerable <string> > action10 = action8.And <string, IList <Chain <Chain <Chain <IList <char>, char>, IList <char> >, string> > >(Grammar.Rep <Chain <Chain <Chain <IList <char>, char>, IList <char> >, string> >(action9.And <Chain <Chain <IList <char>, char>, IList <char> >, string>(action8))).Build <Chain <string, IList <Chain <Chain <Chain <IList <char>, char>, IList <char> >, string> > >, IEnumerable <string> >(hit => new string[] { hit.Left }.Concat <string>(from x in hit.Down select x.Down));
            ParseAction <string> action11 = CharGrammar.Ch("new").And <string, IList <char> >(action).And <Chain <string, IList <char> >, char>(CharGrammar.Ch('{')).And <Chain <Chain <string, IList <char> >, char>, IEnumerable <string> >(action10).And <Chain <Chain <Chain <string, IList <char> >, char>, IEnumerable <string> >, char>(CharGrammar.Ch('}')).Build <Chain <Chain <Chain <Chain <string, IList <char> >, char>, IEnumerable <string> >, char>, string>(hit => "{" + string.Join(",", hit.Left.Down.ToArray <string>()) + "}");

            this._valuePart = Str <Chain <Chain <char, IList <char> >, char> >(action3.Or <Chain <Chain <char, IList <char> >, char> >(action4)).Or <string>(action11);
            ParseAction <IList <char> > action12 = Grammar.Rep1 <char>(CharGrammar.Ch((Func <char, bool>)(ch => true)).Unless <char, string>(action11));

            this.ReformatCode       = Grammar.Rep <string>(Str <IList <char> >(action12).Or <string>(action11)).Build <IList <string>, string>(hit => string.Concat(hit.ToArray <string>()));
            this.test_ws            = Test <IList <char> >(action);
            this.test_doubleString  = Test <Chain <Chain <char, IList <char> >, char> >(action3);
            this.test_singleString  = Test <Chain <Chain <char, IList <char> >, char> >(action4);
            this.test_propName      = Test <Chain <char, IList <char> > >(parser);
            this.test_propValue     = Test <IList <string> >(action7);
            this.test_term          = Test <string>(action8);
            this.test_terms         = Test <IEnumerable <string> >(action10);
            this.test_anonymousType = action11;
        }
Example #4
0
        public CodeGrammar()
        {
            Func <ParseAction <string>, ParseAction <Snippets> > func = null;
            Func <IList <char>, string>    bs            = hit => new string(hit.ToArray <char>());
            Func <IList <string>, string>  js            = hit => string.Concat(hit.ToArray <string>());
            ParseAction <string>           action        = CharGrammar.Ch('\\').And <char, char>(CharGrammar.Ch((Func <char, bool>)(c => true))).Build <Chain <char, char>, string>(hit => @"\" + hit.Down);
            ParseAction <string>           parse         = Grammar.Rep1 <char>(CharGrammar.ChNot(new char[] { '"', '\\' })).Build <IList <char>, string>(bs).Or <string>(action);
            ParseAction <IList <Snippet> > action3       = Snip <Chain <Chain <char, IList <string> >, char> >(CharGrammar.Ch('"').And <char, IList <string> >(Grammar.Rep <string>(parse)).And <Chain <char, IList <string> >, char>(CharGrammar.Ch('"')), (Func <Chain <Chain <char, IList <string> >, char>, string>)(hit => ("\"" + js(hit.Left.Down) + "\"")));
            ParseAction <string>           action4       = CharGrammar.Ch("\"\"").Or <string>(CharGrammar.ChNot('"').Build <char, string>(ch => new string(ch, 1)));
            ParseAction <IList <Snippet> > action5       = Snip <Chain <Chain <string, IList <string> >, char> >(CharGrammar.Ch("@\"").And <string, IList <string> >(Grammar.Rep <string>(action4)).And <Chain <string, IList <string> >, char>(CharGrammar.Ch('"')), (Func <Chain <Chain <string, IList <string> >, char>, string>)(hit => ("@\"" + js(hit.Left.Down) + "\"")));
            ParseAction <IList <Snippet> > action6       = Snip(Grammar.Rep1 <char>(CharGrammar.ChNot(new char[] { '\'', '\\', '"' }))).Or <IList <Snippet> >(Snip(action)).Or <IList <Snippet> >(Swap <char>(CharGrammar.Ch('"'), "\\\""));
            ParseAction <IList <Snippet> > action7       = Snip(Swap <char>(CharGrammar.Ch('\''), "\"").And <IList <Snippet>, IList <Snippet> >(Snip(Grammar.Rep <IList <Snippet> >(action6))).And <Chain <IList <Snippet>, IList <Snippet> >, IList <Snippet> >(Swap <char>(CharGrammar.Ch('\''), "\"")));
            ParseAction <IList <Snippet> > action8       = Swap <string>(CharGrammar.Ch("''"), "'").Or <IList <Snippet> >(Swap <char>(CharGrammar.Ch('"'), "\"\"")).Or <IList <Snippet> >(Snip(CharGrammar.ChNot('\'')));
            ParseAction <IList <Snippet> > action9       = Snip(Swap <string>(CharGrammar.Ch("@'"), "@\"").And <IList <Snippet>, IList <Snippet> >(Snip(Grammar.Rep <IList <Snippet> >(action8))).And <Chain <IList <Snippet>, IList <Snippet> >, IList <Snippet> >(Swap <char>(CharGrammar.Ch('\''), "\"")));
            ParseAction <IList <Snippet> > stringLiteral = TkStr <IList <Snippet> >(action3.Or <IList <Snippet> >(action5).Or <IList <Snippet> >(action7).Or <IList <Snippet> >(action9));

            this._stringLiteral = stringLiteral;
            ParseAction <IList <Snippet> > SpecialCharCast  = Snip <Chain <Chain <string, string>, char> >(CharGrammar.Ch("(char)'").And <string, string>(CharGrammar.ChNot(new char[] { '\'', '\\' }).Build <char, string>(ch => ch.ToString()).Or <string>(action)).And <Chain <string, string>, char>(CharGrammar.Ch('\'')), (Func <Chain <Chain <string, string>, char>, string>)(hit => ("(char)'" + hit.Left.Down + "'")));
            ParseAction <IList <Snippet> > oneLineComment   = Snip <Chain <string, IList <char> > >(CharGrammar.Ch("//").And <string, IList <char> >(Grammar.Rep <char>(CharGrammar.ChNot(new char[] { '\r', '\n' }))), (Func <Chain <string, IList <char> >, string>)(hit => ("//" + bs(hit.Down))));
            ParseAction <IList <Snippet> > multiLineComment = Snip <Chain <Chain <string, IList <char> >, string> >(CharGrammar.Ch("/*").And <string, IList <char> >(Grammar.Rep <char>(CharGrammar.Ch((Func <char, bool>)(c => true)).Unless <char, string>(CharGrammar.Ch("*/")))).And <Chain <string, IList <char> >, string>(CharGrammar.Ch("*/")), (Func <Chain <Chain <string, IList <char> >, string>, string>)(hit => ("/*" + bs(hit.Left.Down) + "*/")));
            ParseAction <char>             action10         = CharGrammar.Ch((Func <char, bool>)(c => (char.GetUnicodeCategory(c) == UnicodeCategory.ConnectorPunctuation)));
            ParseAction <char>             action11         = CharGrammar.Ch(delegate(char c) {
                if (char.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
                {
                    return(char.GetUnicodeCategory(c) == UnicodeCategory.SpacingCombiningMark);
                }
                return(true);
            });
            ParseAction <char>             action12   = CharGrammar.Ch((Func <char, bool>)(c => (char.GetUnicodeCategory(c) == UnicodeCategory.Format)));
            ParseAction <char>             action13   = CharGrammar.Ch(new Func <char, bool>(char.IsLetter)).Or <char>(CharGrammar.Ch('_'));
            ParseAction <char>             action14   = CharGrammar.Ch(new Func <char, bool>(char.IsLetterOrDigit)).Or <char>(action10).Or <char>(action11).Or <char>(action12);
            ParseAction <string>           action15   = action13.And <char, IList <char> >(Grammar.Rep <char>(action14)).Build <Chain <char, IList <char> >, string>(hit => hit.Left + new string(hit.Down.ToArray <char>()));
            ParseAction <IList <Snippet> > keyword    = Snip(CharGrammar.Ch("abstract").Or <string>(CharGrammar.Ch("as")).Or <string>(CharGrammar.Ch("base")).Or <string>(CharGrammar.Ch("bool")).Or <string>(CharGrammar.Ch("break")).Or <string>(CharGrammar.Ch("byte")).Or <string>(CharGrammar.Ch("case")).Or <string>(CharGrammar.Ch("catch")).Or <string>(CharGrammar.Ch("char")).Or <string>(CharGrammar.Ch("checked")).Or <string>(CharGrammar.Ch("class")).Or <string>(CharGrammar.Ch("const")).Or <string>(CharGrammar.Ch("continue")).Or <string>(CharGrammar.Ch("decimal")).Or <string>(CharGrammar.Ch("default")).Or <string>(CharGrammar.Ch("delegate")).Or <string>(CharGrammar.Ch("double")).Or <string>(CharGrammar.Ch("do")).Or <string>(CharGrammar.Ch("else")).Or <string>(CharGrammar.Ch("enum")).Or <string>(CharGrammar.Ch("event")).Or <string>(CharGrammar.Ch("explicit")).Or <string>(CharGrammar.Ch("extern")).Or <string>(CharGrammar.Ch("false")).Or <string>(CharGrammar.Ch("finally")).Or <string>(CharGrammar.Ch("fixed")).Or <string>(CharGrammar.Ch("float")).Or <string>(CharGrammar.Ch("foreach")).Or <string>(CharGrammar.Ch("for")).Or <string>(CharGrammar.Ch("goto")).Or <string>(CharGrammar.Ch("if")).Or <string>(CharGrammar.Ch("implicit")).Or <string>(CharGrammar.Ch("int")).Or <string>(CharGrammar.Ch("in")).Or <string>(CharGrammar.Ch("interface")).Or <string>(CharGrammar.Ch("internal")).Or <string>(CharGrammar.Ch("is")).Or <string>(CharGrammar.Ch("lock")).Or <string>(CharGrammar.Ch("long")).Or <string>(CharGrammar.Ch("namespace")).Or <string>(CharGrammar.Ch("new")).Or <string>(CharGrammar.Ch("null")).Or <string>(CharGrammar.Ch("object")).Or <string>(CharGrammar.Ch("operator")).Or <string>(CharGrammar.Ch("out")).Or <string>(CharGrammar.Ch("override")).Or <string>(CharGrammar.Ch("params")).Or <string>(CharGrammar.Ch("private")).Or <string>(CharGrammar.Ch("protected")).Or <string>(CharGrammar.Ch("public")).Or <string>(CharGrammar.Ch("readonly")).Or <string>(CharGrammar.Ch("ref")).Or <string>(CharGrammar.Ch("return")).Or <string>(CharGrammar.Ch("sbyte")).Or <string>(CharGrammar.Ch("sealed")).Or <string>(CharGrammar.Ch("short")).Or <string>(CharGrammar.Ch("sizeof")).Or <string>(CharGrammar.Ch("stackalloc")).Or <string>(CharGrammar.Ch("static")).Or <string>(CharGrammar.Ch("string")).Or <string>(CharGrammar.Ch("struct")).Or <string>(CharGrammar.Ch("switch")).Or <string>(CharGrammar.Ch("this")).Or <string>(CharGrammar.Ch("throw")).Or <string>(CharGrammar.Ch("true")).Or <string>(CharGrammar.Ch("try")).Or <string>(CharGrammar.Ch("typeof")).Or <string>(CharGrammar.Ch("uint")).Or <string>(CharGrammar.Ch("ulong")).Or <string>(CharGrammar.Ch("unchecked")).Or <string>(CharGrammar.Ch("unsafe")).Or <string>(CharGrammar.Ch("ushort")).Or <string>(CharGrammar.Ch("using")).Or <string>(CharGrammar.Ch("virtual")).Or <string>(CharGrammar.Ch("void")).Or <string>(CharGrammar.Ch("volatile")).Or <string>(CharGrammar.Ch("while"))).NotNext <IList <Snippet>, char>(action14);
            ParseAction <IList <Snippet> > identifier = Snip(action15.Unless <string, IList <Snippet> >(keyword)).Or <IList <Snippet> >(Swap <string>(CharGrammar.Ch("class"), "@class")).Or <IList <Snippet> >(Snip <Chain <char, string> >(CharGrammar.Ch('@').And <char, string>(action15), (Func <Chain <char, string>, string>)(hit => ("@" + hit.Down))));
            ParseAction <IList <Snippet> > action17   = Snip <Chain <char, string> >(CharGrammar.Ch('.').And <char, string>(action15), (Func <Chain <char, string>, string>)(hit => (hit.Left + hit.Down)));
            ParseAction <IList <Snippet> > action18   = Swap <Chain <IList <char>, Chain <Chain <char, IList <char> >, char> > >(Grammar.Opt <IList <char> >(Grammar.Rep <char>(CharGrammar.Ch(new char[] { ' ', '\t' }))).And <IList <char>, Chain <Chain <char, IList <char> >, char> >(CharGrammar.Ch('"').And <char, IList <char> >(Grammar.Rep1 <char>(CharGrammar.ChNot('"'))).And <Chain <char, IList <char> >, char>(CharGrammar.Ch('"')).Or <Chain <Chain <char, IList <char> >, char> >(CharGrammar.Ch('\'').And <char, IList <char> >(Grammar.Rep1 <char>(CharGrammar.ChNot('\''))).And <Chain <char, IList <char> >, char>(CharGrammar.Ch('\'')))), (Func <Chain <IList <char>, Chain <Chain <char, IList <char> >, char> >, string>)(hit => (", \"{0:" + new string(hit.Down.Left.Down.ToArray <char>()) + "}\"")));
            ParseAction <IList <Snippet> > lateBound  = CharGrammar.Ch('#').And <char, IList <Snippet> >(Snip(action15)).And <Chain <char, IList <Snippet> >, IList <Snippet> >(Snip(Grammar.Rep <IList <Snippet> >(action17))).And <Chain <Chain <char, IList <Snippet> >, IList <Snippet> >, IList <Snippet> >(Grammar.Opt <IList <Snippet> >(action18)).Build <Chain <Chain <Chain <char, IList <Snippet> >, IList <Snippet> >, IList <Snippet> >, IList <Snippet> >(hit => new Snippets("Eval(\"").Concat <Snippet>(hit.Left.Left.Down).Concat <Snippet>(hit.Left.Down).Concat <Snippet>(new Snippets("\"")).Concat <Snippet>((hit.Down ?? ((IList <Snippet>) new Snippet[0]))).Concat <Snippet>(new Snippets(")")).ToList <Snippet>());
            ParseAction <IList <Snippet> > action19   = Snip(Grammar.Rep1 <IList <Snippet> >(Swap <string>(CharGrammar.Ch("[["), "<").Or <IList <Snippet> >(Swap <string>(CharGrammar.Ch("]]"), ">")).Or <IList <Snippet> >(lateBound).Or <IList <Snippet> >(Snip(CharGrammar.ChNot(new char[] { '"', '\'', '{', '}', '(', ')' }))).Unless <IList <Snippet>, IList <Snippet> >(identifier.Or <IList <Snippet> >(keyword).Or <IList <Snippet> >(SpecialCharCast)).Unless <IList <Snippet>, string>(CharGrammar.Ch("%>").Or <string>(CharGrammar.Ch("@\"")).Or <string>(CharGrammar.Ch("@'")).Or <string>(CharGrammar.Ch("//")).Or <string>(CharGrammar.Ch("/*")))));
            Func <ParseAction <string>, ParseAction <IList <Snippet> > > limitedCodeStretch = limit => Snip(Grammar.Rep1 <IList <Snippet> >(Swap <string>(CharGrammar.Ch("[["), "<").Or <IList <Snippet> >(Swap <string>(CharGrammar.Ch("]]"), ">")).Or <IList <Snippet> >(lateBound).Or <IList <Snippet> >(Snip(CharGrammar.ChNot(new char[] { '"', '\'', '{', '}', '(', ')' }))).Unless <IList <Snippet>, IList <Snippet> >(identifier.Or <IList <Snippet> >(keyword).Or <IList <Snippet> >(SpecialCharCast)).Unless <IList <Snippet>, string>(limit.Or <string>(CharGrammar.Ch("@\"")).Or <string>(CharGrammar.Ch("@'")).Or <string>(CharGrammar.Ch("//")).Or <string>(CharGrammar.Ch("/*")))));
            ParseAction <IList <Snippet> > braced = Snip(Snip(CharGrammar.Ch('{')).And <IList <Snippet>, IList <Snippet> >(new ParseAction <IList <Snippet> >(this.FnTerms)).And <Chain <IList <Snippet>, IList <Snippet> >, IList <Snippet> >(Snip(CharGrammar.Ch('}'))));
            ParseAction <IList <Snippet> > parens = Snip(Snip(CharGrammar.Ch('(')).And <IList <Snippet>, IList <Snippet> >(new ParseAction <IList <Snippet> >(this.FnTerms)).And <Chain <IList <Snippet>, IList <Snippet> >, IList <Snippet> >(Snip(CharGrammar.Ch(')')))).Unless <IList <Snippet>, IList <Snippet> >(SpecialCharCast);

            this.ExpressionTerms        = Snip(Grammar.Rep1 <IList <Snippet> >(stringLiteral.Or <IList <Snippet> >(braced).Or <IList <Snippet> >(parens).Or <IList <Snippet> >(action19).Or <IList <Snippet> >(identifier).Or <IList <Snippet> >(keyword).Or <IList <Snippet> >(SpecialCharCast).Or <IList <Snippet> >(oneLineComment).Or <IList <Snippet> >(multiLineComment))).Or <IList <Snippet> >(EmptySnip());
            this.LimitedExpressionTerms = limit => Snip(Grammar.Rep1 <IList <Snippet> >(stringLiteral.Or <IList <Snippet> >(braced).Or <IList <Snippet> >(parens).Or <IList <Snippet> >(limitedCodeStretch(limit)).Or <IList <Snippet> >(identifier).Or <IList <Snippet> >(keyword).Or <IList <Snippet> >(SpecialCharCast).Or <IList <Snippet> >(oneLineComment).Or <IList <Snippet> >(multiLineComment))).Or <IList <Snippet> >(EmptySnip());
            this.Expression             = this.ExpressionTerms.Build <IList <Snippet>, Snippets>(hit => new Snippets(hit));
            if (func == null)
            {
                func = limit => this.LimitedExpressionTerms(limit).Build <IList <Snippet>, Snippets>(hit => new Snippets(hit));
            }
            this.LimitedExpression = func;
            ParseAction <IList <Snippet> > action20 = Swap <string>(CharGrammar.Ch("[["), "<").Or <IList <Snippet> >(Swap <string>(CharGrammar.Ch("]]"), ">")).Or <IList <Snippet> >(lateBound).Or <IList <Snippet> >(Snip(CharGrammar.ChNot(new char[] { '"', '\'' }))).Unless <IList <Snippet>, IList <Snippet> >(SpecialCharCast).Unless <IList <Snippet>, string>(CharGrammar.Ch("@\"").Or <string>(CharGrammar.Ch("@'")).Or <string>(CharGrammar.Ch("//")).Or <string>(CharGrammar.Ch("/*")));
            ParseAction <IList <Snippet> > action21 = Snip(Grammar.Rep1 <IList <Snippet> >(action20.Unless <IList <Snippet>, char>(CharGrammar.Ch(new char[] { '\r', '\n' }))));
            ParseAction <IList <Snippet> > action22 = Snip(Grammar.Rep1 <IList <Snippet> >(action20.Unless <IList <Snippet>, string>(CharGrammar.Ch("%>"))));

            this.Statement1 = Snip(Grammar.Rep <IList <Snippet> >(stringLiteral.Or <IList <Snippet> >(action21).Or <IList <Snippet> >(SpecialCharCast).Or <IList <Snippet> >(oneLineComment).Or <IList <Snippet> >(multiLineComment)));
            this.Statement2 = Snip(Grammar.Rep <IList <Snippet> >(stringLiteral.Or <IList <Snippet> >(action22).Or <IList <Snippet> >(SpecialCharCast).Or <IList <Snippet> >(oneLineComment).Or <IList <Snippet> >(multiLineComment)));
        }
        public MarkupGrammar(IParserSettings settings)
        {
            Func <Chain <Chain <string, Snippets>, char>, ExpressionNode> builder = null;
            Func <Chain <Chain <string, Snippets>, char>, ExpressionNode> func2   = null;
            ParseAction <char> parser  = CharGrammar.Ch('\'');
            ParseAction <char> action2 = CharGrammar.Ch('"');
            ParseAction <char> action3 = CharGrammar.Ch('<');
            ParseAction <char> action4 = CharGrammar.Ch('>');

            CharGrammar.ChNot('<');
            ParseAction <char>   parse   = CharGrammar.Ch(new Func <char, bool>(char.IsLetterOrDigit)).Or <char>(CharGrammar.Ch(new char[] { '.', '-', '_', ':' }));
            ParseAction <string> action6 = CharGrammar.Ch(new Func <char, bool>(char.IsLetter)).Or <char>(CharGrammar.Ch(new char[] { '_', ':' })).And <char, IList <char> >(Grammar.Rep <char>(parse)).Build <Chain <char, IList <char> >, string>(hit => hit.Left + new string(hit.Down.ToArray <char>()));

            Grammar.Rep1 <char>(parse).Build <IList <char>, string>(hit => new string(hit.ToArray <char>()));
            this.Whitespace = Grammar.Rep1 <char>(CharGrammar.Ch(new Func <char, bool>(char.IsWhiteSpace)));
            ParseAction <Chain <Chain <IList <char>, char>, IList <char> > > action7 = Grammar.Opt <IList <char> >(this.Whitespace).And <IList <char>, char>(CharGrammar.Ch('=')).And <Chain <IList <char>, char>, IList <char> >(Grammar.Opt <IList <char> >(this.Whitespace));
            ParseAction <StatementNode> action8 = base.Statement1.Build <IList <Snippet>, StatementNode>(hit => new StatementNode(hit)).Paint <StatementNode, Node>();
            string match = string.IsNullOrEmpty(settings.StatementMarker) ? "#" : settings.StatementMarker;
            ParseAction <StatementNode> action9  = Grammar.Opt <char>(CharGrammar.Ch('\r')).And <char, char>(CharGrammar.Ch('\n').Or <char>(CharGrammar.ChSTX())).And <Chain <char, char>, IList <char> >(Grammar.Rep <char>(CharGrammar.Ch(new char[] { ' ', '\t' }))).And <Chain <Chain <char, char>, IList <char> >, string>(CodeGrammar.TkCode <string>(CharGrammar.Ch(match))).And <Chain <Chain <Chain <char, char>, IList <char> >, string>, StatementNode>(action8).IfNext <Chain <Chain <Chain <Chain <char, char>, IList <char> >, string>, StatementNode>, char>(CharGrammar.Ch(new char[] { '\r', '\n' }).Or <char>(CharGrammar.ChETX())).Build <Chain <Chain <Chain <Chain <char, char>, IList <char> >, string>, StatementNode>, StatementNode>(hit => hit.Down);
            ParseAction <StatementNode> action10 = base.Statement2.Build <IList <Snippet>, StatementNode>(hit => new StatementNode(hit)).Paint <StatementNode, Node>();
            ParseAction <StatementNode> action11 = CodeGrammar.TkAspxCode <string>(CharGrammar.Ch("<%")).NotNext <string, char>(CharGrammar.Ch('=')).And <string, StatementNode>(action10).And <Chain <string, StatementNode>, string>(CodeGrammar.TkAspxCode <string>(CharGrammar.Ch("%>"))).Build <Chain <Chain <string, StatementNode>, string>, StatementNode>(hit => hit.Left.Down);

            this.Statement = action9.Or <StatementNode>(action11);
            ParseAction <TextNode> action12 = CodeGrammar.TkCode <string>(CharGrammar.Ch(@"\${").Or <string>(CharGrammar.Ch("$${")).Or <string>(CharGrammar.Ch("`${"))).And <string, Snippets>(base.Expression).And <Chain <string, Snippets>, char>(CodeGrammar.TkCode <char>(CharGrammar.Ch('}'))).Build <Chain <Chain <string, Snippets>, char>, TextNode>(hit => new TextNode("${" + hit.Left.Down + "}"));
            ParseAction <TextNode> action13 = CodeGrammar.TkCode <string>(CharGrammar.Ch(@"\!{").Or <string>(CharGrammar.Ch("!!{")).Or <string>(CharGrammar.Ch("`!{"))).And <string, Snippets>(base.Expression).And <Chain <string, Snippets>, char>(CodeGrammar.TkCode <char>(CharGrammar.Ch('}'))).Build <Chain <Chain <string, Snippets>, char>, TextNode>(hit => new TextNode("!{" + hit.Left.Down + "}"));
            ParseAction <TextNode> action14 = CodeGrammar.TkCode <string>(CharGrammar.Ch(@"\$!{").Or <string>(CharGrammar.Ch("$$!{")).Or <string>(CharGrammar.Ch("`$!{"))).And <string, Snippets>(base.Expression).And <Chain <string, Snippets>, char>(CodeGrammar.TkCode <char>(CharGrammar.Ch('}'))).Build <Chain <Chain <string, Snippets>, char>, TextNode>(hit => new TextNode("$!{" + hit.Left.Down + "}"));

            this.EscapedCode = action12.Or <TextNode>(action13).Or <TextNode>(action14);
            if (builder == null)
            {
                builder = hit => new ExpressionNode(hit.Left.Down)
                {
                    AutomaticEncoding = settings.AutomaticEncoding
                };
            }
            ParseAction <ExpressionNode> action15 = CodeGrammar.TkCode <string>(CharGrammar.Ch("${")).And <string, Snippets>(base.Expression).And <Chain <string, Snippets>, char>(CodeGrammar.TkCode <char>(CharGrammar.Ch('}'))).Build <Chain <Chain <string, Snippets>, char>, ExpressionNode>(builder);
            ParseAction <ExpressionNode> action16 = CodeGrammar.TkAspxCode <string>(CharGrammar.Ch("<%")).And <string, char>(CodeGrammar.TkAttDelim <char>(CharGrammar.Ch('='))).And <Chain <string, char>, Snippets>(base.Expression).And <Chain <Chain <string, char>, Snippets>, string>(CodeGrammar.TkAspxCode <string>(CharGrammar.Ch("%>"))).Build <Chain <Chain <Chain <string, char>, Snippets>, string>, ExpressionNode>(hit => new ExpressionNode(hit.Left.Down));

            if (func2 == null)
            {
                func2 = hit => new ExpressionNode(hit.Left.Down)
                {
                    SilentNulls = true, AutomaticEncoding = settings.AutomaticEncoding
                };
            }
            ParseAction <ExpressionNode> action17 = CodeGrammar.TkCode <string>(CharGrammar.Ch("$!{")).And <string, Snippets>(base.Expression).And <Chain <string, Snippets>, char>(CodeGrammar.TkCode <char>(CharGrammar.Ch('}'))).Build <Chain <Chain <string, Snippets>, char>, ExpressionNode>(func2);
            ParseAction <ExpressionNode> action18 = CodeGrammar.TkCode <string>(CharGrammar.Ch("!{")).And <string, Snippets>(base.Expression).And <Chain <string, Snippets>, char>(CodeGrammar.TkCode <char>(CharGrammar.Ch('}'))).Build <Chain <Chain <string, Snippets>, char>, ExpressionNode>(hit => new ExpressionNode(hit.Left.Down));

            this.Code = action15.Or <ExpressionNode>(action16).Or <ExpressionNode>(action17).Or <ExpressionNode>(action18);
            ParseAction <ConditionNode> action19 = CodeGrammar.TkCode <string>(CharGrammar.Ch("?{")).And <string, Snippets>(base.Expression).And <Chain <string, Snippets>, char>(CodeGrammar.TkCode <char>(CharGrammar.Ch('}'))).Build <Chain <Chain <string, Snippets>, char>, ConditionNode>(hit => new ConditionNode(hit.Left.Down));
            ParseAction <Node>          action20 = CharGrammar.Ch('<').Build <char, Node>(hit => new TextNode("<"));

            this.EntityRef = CodeGrammar.TkEntity <Chain <Chain <char, string>, char> >(CharGrammar.Ch('&').And <char, string>(action6).And <Chain <char, string>, char>(CharGrammar.Ch(';'))).Build <Chain <Chain <char, string>, char>, EntityNode>(hit => new EntityNode(hit.Left.Down));
            ParseAction <Node>     action21 = this.AsNode <EntityNode>(this.EntityRef).Or <Node>(CharGrammar.Ch('&').Build <char, Node>(hit => new TextNode("&")));
            ParseAction <TextNode> action22 = CodeGrammar.TkAttVal <IList <char> >(Grammar.Rep1 <char>(CharGrammar.ChNot(new char[] { '<', '&', '\'' }).Unless <char, ExpressionNode>(this.Code).Unless <char, ConditionNode>(action19))).Build <IList <char>, TextNode>(hit => new TextNode(hit));
            ParseAction <Chain <Chain <char, IList <Node> >, char> > action23 = CodeGrammar.TkAttQuo <char>(parser).And <char, IList <Node> >(Grammar.Rep <Node>(this.AsNode <TextNode>(action22).Or <Node>(action21).Or <Node>(this.AsNode <ExpressionNode>(this.Code)).Or <Node>(this.AsNode <ConditionNode>(action19)).Or <Node>(action20).Paint <Node>())).And <Chain <char, IList <Node> >, char>(CodeGrammar.TkAttQuo <char>(parser));
            ParseAction <TextNode> action24 = CodeGrammar.TkAttVal <IList <char> >(Grammar.Rep1 <char>(CharGrammar.ChNot(new char[] { '<', '&', '"' }).Unless <char, ExpressionNode>(this.Code).Unless <char, ConditionNode>(action19))).Build <IList <char>, TextNode>(hit => new TextNode(hit));
            ParseAction <Chain <Chain <char, IList <Node> >, char> > action25 = CodeGrammar.TkAttQuo <char>(action2).And <char, IList <Node> >(Grammar.Rep <Node>(this.AsNode <TextNode>(action24).Or <Node>(action21).Or <Node>(this.AsNode <ExpressionNode>(this.Code)).Or <Node>(this.AsNode <ConditionNode>(action19)).Or <Node>(action20).Paint <Node>())).And <Chain <char, IList <Node> >, char>(CodeGrammar.TkAttQuo <char>(action2));
            ParseAction <Chain <Chain <char, IList <Node> >, char> > action26 = action23.Or <Chain <Chain <char, IList <Node> >, char> >(action25);

            this.Attribute = CodeGrammar.TkAttNam <string>(action6).And <string, Chain <Chain <IList <char>, char>, IList <char> > >(CodeGrammar.TkAttDelim <Chain <Chain <IList <char>, char>, IList <char> > >(action7)).And <Chain <string, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, IList <Node> >, char> >(action26).Build <Chain <Chain <string, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, IList <Node> >, char> >, AttributeNode>(hit => new AttributeNode(hit.Left.Left, hit.Down.Down, hit.Down.Left.Down)).Paint <AttributeNode, Node>();
            this.Ignore    = Grammar.Opt <Chain <string, string> >(CharGrammar.Ch("\r\n").Or <string>(CharGrammar.Ch("\n")).And <string, string>(CharGrammar.StringOf(CharGrammar.Ch(new Func <char, bool>(char.IsWhiteSpace)).Unless <char, char>(CharGrammar.Ch(new char[] { '\r', '\n' }))))).And <Chain <string, string>, char>(CodeGrammar.TkTagDelim <char>(action3)).And <Chain <Chain <string, string>, char>, string>(CodeGrammar.TkEleNam <string>(CharGrammar.Ch("ignore"))).And <Chain <Chain <Chain <string, string>, char>, string>, char>(CodeGrammar.TkTagDelim <char>(action4)).And <Chain <Chain <Chain <Chain <string, string>, char>, string>, char>, IList <char> >(Grammar.Rep <char>(CharGrammar.ChNot('<').Or <char>(action3.IfNext <char, string>(CharGrammar.ChNot("/ignore>"))))).And <Chain <Chain <Chain <Chain <Chain <string, string>, char>, string>, char>, IList <char> >, string>(CharGrammar.Ch("</ignore>")).Build <Chain <Chain <Chain <Chain <Chain <Chain <string, string>, char>, string>, char>, IList <char> >, string>, SpecialNode>(hit => new SpecialNode(new ElementNode(hit.Left.Left.Left.Down, new List <AttributeNode>(), false, (hit.Left.Left.Left.Left.Left == null) ? string.Empty : (hit.Left.Left.Left.Left.Left.Left + hit.Left.Left.Left.Left.Left.Down)))
            {
                Body = new List <Node> {
                    new TextNode(hit.Left.Down)
                }
            });
            this.Element    = Grammar.Opt <Chain <string, string> >(CharGrammar.Ch("\r\n").Or <string>(CharGrammar.Ch("\n")).And <string, string>(CharGrammar.StringOf(CharGrammar.Ch(new Func <char, bool>(char.IsWhiteSpace)).Unless <char, char>(CharGrammar.Ch(new char[] { '\r', '\n' }))))).And <Chain <string, string>, char>(CodeGrammar.TkTagDelim <char>(action3)).And <Chain <Chain <string, string>, char>, string>(CodeGrammar.TkEleNam <string>(action6)).And <Chain <Chain <Chain <string, string>, char>, string>, IList <AttributeNode> >(Grammar.Rep <AttributeNode>(this.Whitespace.And <IList <char>, AttributeNode>(this.Attribute).Down <IList <char>, AttributeNode>())).And <Chain <Chain <Chain <Chain <string, string>, char>, string>, IList <AttributeNode> >, IList <char> >(Grammar.Opt <IList <char> >(this.Whitespace)).And <Chain <Chain <Chain <Chain <Chain <string, string>, char>, string>, IList <AttributeNode> >, IList <char> >, char>(Grammar.Opt <char>(CodeGrammar.TkTagDelim <char>(CharGrammar.Ch('/')))).And <Chain <Chain <Chain <Chain <Chain <Chain <string, string>, char>, string>, IList <AttributeNode> >, IList <char> >, char>, char>(CodeGrammar.TkTagDelim <char>(action4)).Build <Chain <Chain <Chain <Chain <Chain <Chain <Chain <string, string>, char>, string>, IList <AttributeNode> >, IList <char> >, char>, char>, ElementNode>(hit => new ElementNode(hit.Left.Left.Left.Left.Down, hit.Left.Left.Left.Down, hit.Left.Down != '\0', (hit.Left.Left.Left.Left.Left.Left == null) ? string.Empty : (hit.Left.Left.Left.Left.Left.Left.Left + hit.Left.Left.Left.Left.Left.Left.Down)));
            this.EndElement = Grammar.Opt <Chain <string, string> >(CharGrammar.Ch("\r\n").Or <string>(CharGrammar.Ch("\n")).And <string, string>(CharGrammar.StringOf(CharGrammar.Ch(new Func <char, bool>(char.IsWhiteSpace)).Unless <char, char>(CharGrammar.Ch(new char[] { '\r', '\n' }))))).And <Chain <string, string>, Chain <char, char> >(CodeGrammar.TkTagDelim <Chain <char, char> >(action3.And <char, char>(CharGrammar.Ch('/')))).And <Chain <Chain <string, string>, Chain <char, char> >, string>(CodeGrammar.TkEleNam <string>(action6)).And <Chain <Chain <Chain <string, string>, Chain <char, char> >, string>, IList <char> >(Grammar.Opt <IList <char> >(this.Whitespace)).And <Chain <Chain <Chain <Chain <string, string>, Chain <char, char> >, string>, IList <char> >, char>(CodeGrammar.TkTagDelim <char>(action4)).Build <Chain <Chain <Chain <Chain <Chain <string, string>, Chain <char, char> >, string>, IList <char> >, char>, EndElementNode>(hit => new EndElementNode(hit.Left.Left.Down, (hit.Left.Left.Left.Left == null) ? string.Empty : (hit.Left.Left.Left.Left.Left + hit.Left.Left.Left.Left.Down)));
            this.Text       = Grammar.Rep1 <char>(CharGrammar.ChNot(new char[] { '&', '<' }).Unless <char, StatementNode>(this.Statement).Unless <char, ExpressionNode>(this.Code).Unless <char, TextNode>(this.EscapedCode).Unless <char, SpecialNode>(this.Ignore).Unless <char, ElementNode>(this.Element).Unless <char, EndElementNode>(this.EndElement)).Build <IList <char>, TextNode>(hit => new TextNode(hit));
            this.Comment    = CodeGrammar.TkComm <Chain <Chain <string, IList <char> >, string> >(CharGrammar.Ch("<!--").And <string, IList <char> >(Grammar.Rep <char>(CharGrammar.ChNot('-').Or <char>(CharGrammar.Ch('-').IfNext <char, char>(CharGrammar.ChNot('-'))))).And <Chain <string, IList <char> >, string>(CharGrammar.Ch("-->"))).Build <Chain <Chain <string, IList <char> >, string>, CommentNode>(hit => new CommentNode(hit.Left.Down));
            ParseAction <string>         action27 = action2.And <char, IList <char> >(Grammar.Rep <char>(CharGrammar.ChNot('"'))).And <Chain <char, IList <char> >, char>(action2).Or <Chain <Chain <char, IList <char> >, char> >(parser.And <char, IList <char> >(Grammar.Rep <char>(CharGrammar.ChNot('\''))).And <Chain <char, IList <char> >, char>(parser)).Build <Chain <Chain <char, IList <char> >, char>, string>(hit => new string(hit.Left.Down.ToArray <char>()));
            ParseAction <char>           action28 = CharGrammar.Ch(new Func <char, bool>(char.IsLetterOrDigit)).Or <char>(CharGrammar.Ch(" \r\n-()+,./:=?;!*#@$_%".ToArray <char>()));
            ParseAction <char>           action29 = action28.Or <char>(parser);
            ParseAction <string>         action30 = action2.And <char, IList <char> >(Grammar.Rep <char>(action29)).And <Chain <char, IList <char> >, char>(action2).Or <Chain <Chain <char, IList <char> >, char> >(parser.And <char, IList <char> >(Grammar.Rep <char>(action28)).And <Chain <char, IList <char> >, char>(parser)).Build <Chain <Chain <char, IList <char> >, char>, string>(hit => new string(hit.Left.Down.ToArray <char>()));
            ParseAction <ExternalIdInfo> action31 = CharGrammar.Ch("SYSTEM").And <string, IList <char> >(this.Whitespace).And <Chain <string, IList <char> >, string>(action27).Build <Chain <Chain <string, IList <char> >, string>, ExternalIdInfo>(hit => new ExternalIdInfo {
                ExternalIdType = hit.Left.Left, SystemId = hit.Down
            });
            ParseAction <ExternalIdInfo> action32 = CharGrammar.Ch("PUBLIC").And <string, IList <char> >(this.Whitespace).And <Chain <string, IList <char> >, string>(action30).And <Chain <Chain <string, IList <char> >, string>, IList <char> >(this.Whitespace).And <Chain <Chain <Chain <string, IList <char> >, string>, IList <char> >, string>(action27).Build <Chain <Chain <Chain <Chain <string, IList <char> >, string>, IList <char> >, string>, ExternalIdInfo>(hit => new ExternalIdInfo {
                ExternalIdType = hit.Left.Left.Left.Left, PublicId = hit.Left.Left.Down, SystemId = hit.Down
            });
            ParseAction <ExternalIdInfo> action33 = action31.Or <ExternalIdInfo>(action32);

            this.DoctypeDecl = CharGrammar.Ch("<!DOCTYPE").And <string, IList <char> >(this.Whitespace).And <Chain <string, IList <char> >, string>(action6).And <Chain <Chain <string, IList <char> >, string>, ExternalIdInfo>(Grammar.Opt <ExternalIdInfo>(this.Whitespace.And <IList <char>, ExternalIdInfo>(action33).Down <IList <char>, ExternalIdInfo>())).And <Chain <Chain <Chain <string, IList <char> >, string>, ExternalIdInfo>, IList <char> >(Grammar.Opt <IList <char> >(this.Whitespace)).And <Chain <Chain <Chain <Chain <string, IList <char> >, string>, ExternalIdInfo>, IList <char> >, char>(CharGrammar.Ch('>')).Build <Chain <Chain <Chain <Chain <Chain <string, IList <char> >, string>, ExternalIdInfo>, IList <char> >, char>, DoctypeNode>(hit => new DoctypeNode {
                Name = hit.Left.Left.Left.Down, ExternalId = hit.Left.Left.Down
            });
            ParseAction <string> action34 = CharGrammar.Ch("1.0");
            ParseAction <Chain <Chain <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, string>, char> > > action35 = this.Whitespace.And <IList <char>, string>(CharGrammar.Ch("version")).And <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >(action7).And <Chain <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, string>, char> >(parser.And <char, string>(action34).And <Chain <char, string>, char>(parser).Or <Chain <Chain <char, string>, char> >(action2.And <char, string>(action34).And <Chain <char, string>, char>(action2)));
            ParseAction <string> action36 = CharGrammar.Ch(new Func <char, bool>(char.IsLetter)).And <char, IList <char> >(Grammar.Rep <char>(CharGrammar.Ch(new Func <char, bool>(char.IsLetterOrDigit)).Or <char>(CharGrammar.Ch(new char[] { '.', '_', '-' })))).Build <Chain <char, IList <char> >, string>(hit => hit.Left + new string(hit.Down.ToArray <char>()));
            ParseAction <string> action37 = this.Whitespace.And <IList <char>, string>(CharGrammar.Ch("encoding")).And <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >(action7).And <Chain <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, string>, char> >(parser.And <char, string>(action36).And <Chain <char, string>, char>(parser).Or <Chain <Chain <char, string>, char> >(action2.And <char, string>(action36).And <Chain <char, string>, char>(action2))).Build <Chain <Chain <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, string>, char> >, string>(hit => hit.Down.Left.Down);
            ParseAction <string> action38 = this.Whitespace.And <IList <char>, string>(CharGrammar.Ch("standalone")).And <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >(action7).And <Chain <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, string>, char> >(parser.And <char, string>(CharGrammar.Ch("yes").Or <string>(CharGrammar.Ch("no"))).And <Chain <char, string>, char>(parser).Or <Chain <Chain <char, string>, char> >(action2.And <char, string>(CharGrammar.Ch("yes").Or <string>(CharGrammar.Ch("no"))).And <Chain <char, string>, char>(action2))).Build <Chain <Chain <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, string>, char> >, string>(hit => hit.Down.Left.Down);

            this.XMLDecl = CharGrammar.Ch("<?xml").And <string, Chain <Chain <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, string>, char> > >(action35).And <Chain <string, Chain <Chain <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, string>, char> > >, string>(Grammar.Opt <string>(action37)).And <Chain <Chain <string, Chain <Chain <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, string>, char> > >, string>, string>(Grammar.Opt <string>(action38)).And <Chain <Chain <Chain <string, Chain <Chain <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, string>, char> > >, string>, string>, IList <char> >(Grammar.Opt <IList <char> >(this.Whitespace)).And <Chain <Chain <Chain <Chain <string, Chain <Chain <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, string>, char> > >, string>, string>, IList <char> >, string>(CharGrammar.Ch("?>")).Build <Chain <Chain <Chain <Chain <Chain <string, Chain <Chain <Chain <IList <char>, string>, Chain <Chain <IList <char>, char>, IList <char> > >, Chain <Chain <char, string>, char> > >, string>, string>, IList <char> >, string>, XMLDeclNode>(hit => new XMLDeclNode {
                Encoding = hit.Left.Left.Left.Down, Standalone = hit.Left.Left.Down
            });
            ParseAction <string> action39 = action6.Unless <string, Chain <Chain <char, char>, char> >(CharGrammar.Ch(new char[] { 'X', 'x' }).And <char, char>(CharGrammar.Ch(new char[] { 'M', 'm' })).And <Chain <char, char>, char>(CharGrammar.Ch(new char[] { 'L', 'l' })));

            this.ProcessingInstruction = CharGrammar.Ch("<?").And <string, string>(action39).And <Chain <string, string>, IList <char> >(Grammar.Opt <IList <char> >(this.Whitespace)).And <Chain <Chain <string, string>, IList <char> >, IList <char> >(Grammar.Rep <char>(CharGrammar.Ch((Func <char, bool>)(ch => true)).Unless <char, string>(CharGrammar.Ch("?>")))).And <Chain <Chain <Chain <string, string>, IList <char> >, IList <char> >, string>(CharGrammar.Ch("?>")).Build <Chain <Chain <Chain <Chain <string, string>, IList <char> >, IList <char> >, string>, ProcessingInstructionNode>(hit => new ProcessingInstructionNode {
                Name = hit.Left.Left.Left.Down, Body = new string(hit.Left.Down.ToArray <char>())
            });
            this.AnyNode = this.AsNode <SpecialNode>(this.Ignore).Paint <Node>().Or <Node>(this.AsNode <TextNode>(this.EscapedCode).Paint <Node>()).Or <Node>(this.AsNode <ElementNode>(this.Element).Paint <Node>()).Or <Node>(this.AsNode <EndElementNode>(this.EndElement).Paint <Node>()).Or <Node>(this.AsNode <TextNode>(this.Text).Paint <Node>()).Or <Node>(action21.Paint <Node>()).Or <Node>(this.AsNode <StatementNode>(this.Statement)).Or <Node>(this.AsNode <ExpressionNode>(this.Code).Paint <Node>()).Or <Node>(this.AsNode <DoctypeNode>(this.DoctypeDecl).Paint <Node>()).Or <Node>(this.AsNode <CommentNode>(this.Comment).Paint <Node>()).Or <Node>(this.AsNode <XMLDeclNode>(this.XMLDecl).Paint <Node>()).Or <Node>(this.AsNode <ProcessingInstructionNode>(this.ProcessingInstruction).Paint <Node>()).Or <Node>(this.AsNode <Node>(action20).Paint <Node>());
            this.Nodes   = Grammar.Rep <Node>(this.AnyNode);
        }