public override bool ParseMatch(TokenReader tr, SyntaxTree.Node node) { /*var con = true; * while (con) { * con = base.ParseMatch(tr, node); * }*/ while (base.ParseMatch(tr, node)) { } return(true); }
public bool ParseMatch(TokenReader tr, SyntaxTree.Node node) { if (tr.Peek()?.type == this) { tr.Next(); if (createNode) { node.AddChild(new SyntaxTree.Node(this, tr.Current.value)); } return(true); } return(false); }
public bool ParseMatch(TokenReader tr, SyntaxTree.Node node) { var n = createNode ? new SyntaxTree.Node(this, "") : node; for (int i = 0; i < patterns.Length; i++) { if (patterns[i].Match(tr, n)) { if (createNode) { node.AddChild(n); } return(true); } } return(false); }
public SyntaxTree Parse(string input) { var reader = new TokenReader(lexer.Lex(input)); Console.WriteLine(reader.TokensAsText()); var mainRule = parserules[0]; // hard-code to first rule for now var root = new SyntaxTree.Node(mainRule, ""); if (!mainRule.ParseMatch(reader, root)) { throw new ParserException(""); } return(new SyntaxTree(root)); }
public bool Match(TokenReader tr, SyntaxTree.Node node) { int startIndex = tr.index; int startChildCount = node.childCount; for (int i = 0; i < rules.Length; i++) { if (!rules[i].ParseMatch(tr, node)) { // fail. reset tokenreader index and syntaxtree nodes tr.index = startIndex; while (node.childCount > startChildCount) { node.RemoveChild(node.childCount - 1); } return(false); } } return(true); }
public override bool ParseMatch(TokenReader tr, SyntaxTree.Node node) { base.ParseMatch(tr, node); return(true); }
public virtual bool ParseMatch(TokenReader tr, SyntaxTree.Node node) => inner.ParseMatch(tr, node);