/// <summary> /// Assigns the specified state. /// </summary> /// <param name="state">The state.</param> public void Assign(ParserState state) { this.Input = state.Input; this.CurrentPosition = state.CurrentPosition; this.Nodes.Clear(); foreach (Token node in state.Nodes) { this.Nodes.Add(node); } }
/// <summary> /// Indicates if the current parser state matches the rule. /// </summary> /// <param name="state">The state.</param> /// <returns></returns> public override bool Match(ParserState state) { Match match = this.regex.Match(state.Input, state.CurrentPosition); if (match == null || match.Index != state.CurrentPosition) { return false; } state.CurrentPosition = state.CurrentPosition + match.Length; return true; }
/// <summary> /// Indicates if the current parser state matches the rule. /// </summary> /// <param name="state">The state.</param> /// <returns></returns> public override bool Match(ParserState state) { Token node = new Token(this.Name, state); IList<Token> oldNodes = state.Nodes; state.Nodes = new List<Token>(); if (this.FirstSon.Match(state)) { node.End = state.CurrentPosition; node.Tokens = state.Nodes; oldNodes.Add(node); state.Nodes = oldNodes; return true; } else { state.Nodes = oldNodes; return false; } }
/// <summary> /// Clones this instance. /// </summary> /// <returns></returns> public ParserState Clone() { ParserState result = new ParserState(this.Input); result.CurrentPosition = this.CurrentPosition; foreach (Token node in this.Nodes) { result.Nodes.Add(node); } return result; }
/// <summary> /// Indicates if the current parser state matches the rule. /// </summary> /// <param name="state">The state.</param> /// <returns></returns> public abstract bool Match(ParserState state);