Example #1
0
        public bool Parse(ref Lexer lexer, out SyntaxNode node)
        {
            var token = syntax.Parse(ref lexer);

            node = Nodes.Create(this, syntax, token);
            return(token.IsValid);
        }
Example #2
0
        public bool Parse(ref Lexer lexer, out SyntaxNode node)
        {
            whitespace.Parse(ref lexer);
            int count = 0;

            node = new SyntaxNode(this, lexer.Here);

            while (true)
            {
                count++;
                bool parsed = item.Parse(ref lexer, out SyntaxNode n);
                if (parsed)
                {
                    node.Append(n, errorproliferation: State.Valid);
                }
                else if (count > mincount)
                {
                    n.Mark(State.Dismissed);
                    node.Append(n, errorproliferation: State.Valid);
                    return(true);
                }
                else
                {
                    // always append (or you will lose your error)
                    node.Append(n, errorproliferation: State.Error);
                    return(false);
                }
            }
        }
Example #3
0
        public bool Parse(ref Lexer lexer, out SyntaxNode node)
        {
            whitespace.Parse(ref lexer);
            var token = eof.Parse(ref lexer);
            var state = (token.IsValid) ? State.Valid : State.Error;

            node = new SyntaxNode(this, eof, token, state);
            return(token.IsValid);
        }
Example #4
0
        public bool Parse(ref Lexer lexer, out SyntaxNode node)
        {
            whitespace.Parse(ref lexer); // consume whitespace.
            node = new SyntaxNode(this, lexer.Here);

            foreach (var grammar in List)
            {
                whitespace.Parse(ref lexer);

                bool ok = grammar.Parse(ref lexer, out SyntaxNode n);
                node.Append(n);
                if (!ok)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #5
0
        public bool Parse(ref Lexer lexer, out SyntaxNode node)
        {
            whitespace.Parse(ref lexer); // consume whitespace.
            var branches = new List <SyntaxNode>();

            node = new SyntaxNode(this, lexer.Here);
            var  bookmark = lexer;
            bool ok       = false;

            foreach (var grammar in children)
            {
                lexer = bookmark;

                ok = grammar.Parse(ref lexer, out SyntaxNode n);

                if (ok)
                {
                    node.Append(n);
                    break;
                }
                else
                {
                    branches.Add(n);
                }
            }

            if (branches.Count > 0)
            {
                var longest = branches.GetFarthestEnd();
                if (ok)
                {
                    longest.Mark(State.Dismissed);
                }
                else
                {
                    longest.Mark(State.Error);
                }

                node.Append(longest);
            }

            return(ok);
        }
Example #6
0
 public virtual void Parse(Parser parser, List <IExpression> list, ref int pos)
 {
     _syntax.Parse(parser, list, ref pos);
 }
Example #7
0
 public static Token?TryParse(ISyntax syntax, ref Lexer lexer)
 {
     return(syntax.Parse(ref lexer));
 }