public void Parse(ref Node node, TokenWalker walker, out ParseResultHistory resultHistory) { StateWalker walk = null; resultHistory = new ParseResultHistory(); try { this.ParseNode(ref node, out walk, walker, resultHistory); } catch (Success) { walk(walker); if (node is null) { throw new FailedParsingNodeException("Success, but result node is empty"); } } catch (Failure) { throw new FailedParsingNodeException($"Failed parsing node"); } }
public override void ParseNode(ref Node node, out TokenWalker.StateWalker walk, TokenWalker walker, ParseResultHistory resultHistory) { TokenWalker LocalWalker = new TokenWalker(walker); TokenWalker.StateWalker localWalk = LocalWalker.State; List <Node> parsedNodes = new List <Node>(); foreach (NodeParser parser in this.Parsers) { Node parsedNode = null; try { parser.ParseNode(ref parsedNode, out localWalk, LocalWalker, resultHistory); } catch (Failure) { continue; } catch (Success) { localWalk(LocalWalker); walk = localWalk; if (parsedNode != null) { parsedNodes.Add(parsedNode); } } } if (parsedNodes.Count == 2) { Node left = node; Node binaryModifier = parsedNodes[0]; Node right = parsedNodes[1]; SourceContext binaryNodeContext = left.Context.To(right); node = new BinaryNode(this.type, left, binaryModifier, right, binaryNodeContext); resultHistory.AddResult(new SuccessfulParsingResult(binaryNodeContext, this)); throw Succeded; } resultHistory.AddResult(new FailedParsingResult(walker.Location, this)); throw Failed; }
public override void ParseNode(ref Node node, out TokenWalker.StateWalker walk, TokenWalker walker, ParseResultHistory resultHistory) { TokenWalker LocalWalker = new TokenWalker(walker); TokenWalker.StateWalker localWalk = LocalWalker.State; List <Node> parsedNodes = new List <Node>(); while (true) { Node parsedNode = null; try { this.Parser.ParseNode(ref parsedNode, out localWalk, LocalWalker, resultHistory); } catch (Failure) { break; } catch (Success) { localWalk(LocalWalker); if (parsedNode != null) { parsedNodes.Add(parsedNode); } else { resultHistory.AddResult(new FailedParsingResult(walker.Location, this)); throw Failed; } } } if (!this.allowEmpty && parsedNodes.Count == 0) { resultHistory.AddResult(new FailedParsingResult(walker.Location, this)); throw Failed; } node = new ManyNode(parsedNodes, walker.To(LocalWalker)); walk = localWalk; resultHistory.AddResult(new SuccessfulParsingResult(walker.To(localWalk), this)); throw Succeded; }
public override void ParseNode(ref Node node, out TokenWalker.StateWalker walk, TokenWalker walker, ParseResultHistory resultHistory) { TokenWalker LocalWalker = new TokenWalker(walker); TokenWalker.StateWalker localWalk = LocalWalker.State; Debug.WriteLine(Parsers.Node.Program.ToStringRecursively(highlighted: this, enableHighlighting: false)); while (!LocalWalker.IsLast()) { try { this.Parser.ParseNode(ref node, out localWalk, LocalWalker, resultHistory); } catch (Failure) { resultHistory.AddResult(new FailedParsingResult(walker.Location, this)); throw; } catch (Success) { localWalk(LocalWalker); LocalWalker.SkipWhitespace(); continue; } } walk = LocalWalker.State; resultHistory.AddResult(new SuccessfulParsingResult(walker.To(localWalk), this)); throw Succeded; }
public abstract void ParseNode(ref Node node, out TokenWalker.StateWalker walk, TokenWalker walker, ParseResultHistory resultHistory);
public override void ParseNode(ref Node node, out TokenWalker.StateWalker walk, TokenWalker walker, ParseResultHistory resultHistory) { TokenWalker LocalWalker = new TokenWalker(walker); TokenWalker.StateWalker localWalk = LocalWalker.State; foreach (NodeParser parser in this.Parsers) { try { parser.ParseNode(ref node, out localWalk, LocalWalker, resultHistory); } catch (Failure) { continue; } catch (Success) { localWalk(LocalWalker); walk = localWalk; resultHistory.AddResult(new SuccessfulParsingResult(walker.To(localWalk), this)); throw; } } resultHistory.AddResult(new FailedParsingResult(walker.Location, this)); throw Failed; }
public static void Parse(ref Parsing.Node node, TokenWalker walker, out ParseResultHistory resultHistory) => Program.Parse(ref node, walker, out resultHistory);
public override void ParseNode(ref Node node, out TokenWalker.StateWalker walk, TokenWalker walker, ParseResultHistory resultHistory) { TokenWalker LocalWalker = new TokenWalker(walker); TokenWalker.StateWalker localWalk = LocalWalker.State; List <Node> parsedNodes = new List <Node>(); foreach (NodeParser parser in this.Parsers) { Node parsedNode = null; try { parser.ParseNode(ref parsedNode, out localWalk, LocalWalker, resultHistory); } catch (Failure) { resultHistory.AddResult(new FailedParsingResult(walker.Location, this)); throw; } catch (Success) { if (parsedNode != null) { parsedNodes.Add(parsedNode); } localWalk(LocalWalker); continue; } } walk = localWalk; var context = walker.To(walk); node = new ManyNode(parsedNodes, context); resultHistory.AddResult(new SuccessfulParsingResult(context, this)); throw Succeded; }
public override void ParseNode(ref Node node, out TokenWalker.StateWalker walk, TokenWalker walker, ParseResultHistory resultHistory) { TokenWalker LocalWalker = new TokenWalker(walker); walk = LocalWalker.State; this.parserReference().ParseNode(ref node, out walk, LocalWalker, resultHistory); }
public override void ParseNode(ref Node node, out TokenWalker.StateWalker walk, TokenWalker walker, ParseResultHistory resultHistory) { TokenWalker LocalWalker = new TokenWalker(walker); TokenWalker.StateWalker localWalk = LocalWalker.State; if (LocalWalker.TryGetNext(out Token token, this.Keywords)) { var walked = walker.To(LocalWalker); localWalk(LocalWalker); node = new TokenNode(token, walked); walk = localWalk; resultHistory.AddResult(new SuccessfulParsingResult(walker.To(localWalk), this)); throw Succeded; } resultHistory.AddResult(new FailedParsingResult(walker.Location, this)); throw Failed; }
public override void ParseNode(ref Node node, out TokenWalker.StateWalker walk, TokenWalker walker, ParseResultHistory resultHistory) { TokenWalker LocalWalker = new TokenWalker(walker); TokenWalker.StateWalker localWalk = LocalWalker.State; List <Node> parsedNodes = new List <Node>(); foreach (NodeParser parser in this.Parsers) { Node parsedNode = null; try { parser.ParseNode(ref parsedNode, out localWalk, LocalWalker, resultHistory); } catch (Failure) { continue; } catch (Success) { localWalk(LocalWalker); if (parsedNode != null) { parsedNodes.Add(parsedNode); } else { throw new Exception("Parser succeeded but no node was parsed"); } } } if (parsedNodes.Count == 1) { var parsedNode = parsedNodes[0]; node = new UnaryNode(this.type, parsedNode, node, node.Context.To(parsedNode.Context)); walk = localWalk; resultHistory.AddResult(new SuccessfulParsingResult(walker.To(localWalk), this)); throw Succeded; } resultHistory.AddResult(new FailedParsingResult(walker.Location, this)); throw Failed; }
public override void ParseNode(ref Node node, out TokenWalker.StateWalker walk, TokenWalker walker, ParseResultHistory resultHistory) { TokenWalker LocalWalker = new TokenWalker(walker); TokenWalker.StateWalker localWalk = LocalWalker.State; try { this.Parser.ParseNode(ref node, out localWalk, LocalWalker, resultHistory); } catch (Failure) { } catch (Success) { localWalk(LocalWalker); walk = localWalk; resultHistory.AddResult(new SuccessfulParsingResult(walker.To(localWalk), this)); } throw Succeded; }
public override void ParseNode(ref Node node, out TokenWalker.StateWalker walk, TokenWalker walker, ParseResultHistory resultHistory) { TokenWalker LocalWalker = new TokenWalker(walker); TokenWalker.StateWalker localWalk = LocalWalker.State; while (true) { try { this.Parser.ParseNode(ref node, out localWalk, LocalWalker, resultHistory); } catch (Failure) { resultHistory.AddResult(new SuccessfulParsingResult(walker.To(localWalk), this)); throw Succeded; } catch (Success) { localWalk(LocalWalker); walk = localWalk; continue; } throw new ParserException("Parser didnt specifiy if it succeded or not"); } }