public override ParseTree Parse(Lexer lexer, ParserState state) { int start = lexer.Position; state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "options"); bool oldBuildTextNodes = state.BuildTextNodes; Pattern oldWhitespace = lexer.WhitespacePattern; Precedence oldCurrentPrecedence = state.CurrentPrecedence; bool oldPrecedenceCanEqualCurrent = state.PrecedenceCanEqualCurrent; if (buildTextNodes.HasValue) { state.BuildTextNodes = buildTextNodes.Value; } if (whitespace.HasValue) { lexer.Whitespace(state.RuntimeState); lexer.WhitespacePattern = whitespace.Value; } if (exclude.HasValue) { state.Excluded.Add(exclude.Value); } if (dropPrecedence.HasValue && dropPrecedence.Value) { state.CurrentPrecedence = null; state.PrecedenceCanEqualCurrent = false; } ParseTree tree = body.Parse(lexer, state); state.BuildTextNodes = oldBuildTextNodes; lexer.WhitespacePattern = oldWhitespace; if (exclude.HasValue) { state.Excluded.Remove(exclude.Value); } state.CurrentPrecedence = oldCurrentPrecedence; state.PrecedenceCanEqualCurrent = oldPrecedenceCanEqualCurrent; if (tree == ParseTree.No) { state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start)); return(ParseTree.No); } state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start)); return(tree); }
public override ParseTree Parse(Lexer lexer, ParserState state) { ParseTree bodyTree = body.Parse(lexer, state); if (bodyTree == ParseTree.No) { return(ParseTree.No); } ParseTree labelledTree = new ParseTree(); labelledTree = labelledTree.ExtendFields(bodyTree); labelledTree.Fields[label] = bodyTree.Value; return(labelledTree); }
public override ParseTree Parse(Lexer lexer, ParserState state) { int start = lexer.Position; // todo traces ParseTree bodyTree = body.Parse(lexer, state); if (bodyTree == ParseTree.No) { return(ParseTree.No); } lexer.Position = start; return(ParseTree.Yes); }
public override ParseTree Parse(Lexer lexer, ParserState state) { state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), Reps.Name); int start = lexer.Position; bool matched = false; ParseTree tree = ParseTree.Yes; while (true) { ParseTree repTree = body.Parse(lexer, state); if (repTree == ParseTree.No) { break; } tree = tree.Extend(repTree); if (reps.MaximumOfOne) { break; } matched = true; } if ((reps.Minimum > 0) && !matched) { state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start), "Not enough reps"); lexer.Position = start; return(ParseTree.No); } state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start)); return(tree); }
public override ParseTree Parse(Lexer lexer, ParserState state) { state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "token"); int start = lexer.Position; ParseTree bodyTree = body.Parse(lexer, state); if (bodyTree == ParseTree.No) { state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start)); return(ParseTree.No); } state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start)); ParseTree tokenTree = new ParseTree( lexer.Text.Substring(start, lexer.Position - start)); tokenTree = tokenTree.ExtendFields(bodyTree); return(tokenTree); }
public override ParseTree Parse(Lexer lexer, ParserState state) { int start = lexer.Position; ParseTree oldLHS = state.LeftHandSide; bool oldPrecedenceCanEqualCurrent = state.PrecedenceCanEqualCurrent; ConcretePattern oldRecursionExclude = null; ParseTree tree = ParseTree.Yes; for (int n = 0; n < nodes.Count; n++) { ParseGraphNode node = nodes[n]; ParseTree nodeTree = node.Parse(lexer, state); if (nodeTree == ParseTree.No) { state.PrecedenceCanEqualCurrent = oldPrecedenceCanEqualCurrent; state.LeftHandSide = oldLHS; state.RecursionExclude = oldRecursionExclude; if (oldRecursionExclude != null) { state.Excluded.Add(oldRecursionExclude); } lexer.Position = start; return(ParseTree.No); } tree = tree.Extend(nodeTree); if (n == 0) { if (state.RecursionExclude != null) { oldRecursionExclude = state.RecursionExclude; state.Excluded.Remove(state.RecursionExclude); state.RecursionExclude = null; } if (state.RecursionBehaviour == RecursionBehaviour.RightRecursive) { state.PrecedenceCanEqualCurrent = true; } else if (state.RecursionBehaviour == RecursionBehaviour.LeftRecursive) { state.LeftHandSide = null; } } } state.PrecedenceCanEqualCurrent = oldPrecedenceCanEqualCurrent; state.LeftHandSide = oldLHS; state.RecursionExclude = oldRecursionExclude; if (oldRecursionExclude != null) { state.Excluded.Add(oldRecursionExclude); } return(tree); }