/// <summary> /// Action caller method /// </summary> /// <param name="m"></param> public virtual void OnAction(ParserMatch m) { if (Act != null) { Act(this, new ActionEventArgs(m)); } }
/// <summary> /// Concatenates match with m /// </summary> /// <param name="m"></param> public virtual ParserMatch Concat(ParserMatch m) { if (m == null) { throw new ArgumentNullException(nameof(m)); } if (!m.Success) { throw new ArgumentException("Trying to concatenated non successful match"); } // if other is empty, return this if (!m.Empty) { if (m.Offset < Offset) { throw new ArgumentException("match resersed ?"); } this.Length = (int)(m.Offset - Offset) + m.Length; } return(this); }
/// <summary> /// Concatenates match with m /// </summary> /// <param name="m"></param> public void Concat(ParserMatch m) { if (m == null) { throw new ArgumentNullException("m", "Cannot concatenate null match"); } if (!m.Success) { throw new ArgumentException("Non-successful matches cannot be concatenated onto matches"); } if (!Success) { throw new InvalidOperationException("Matches cannot be concatenated onto non-successful matches"); } // if other is empty, return this if (m.Empty) { return; } if (m.Offset < Offset) { throw new ArgumentException("match reserved ?"); } m_Length = (int)(m.Offset - Offset) + m.Length; }
/// <summary> /// Lookahead to determine if parser can be used to parse (does not consume input) /// </summary> /// <param name="scanner"></param> /// <returns></returns> internal ParserMatch TryAccept(IScanner scanner) { long offset = scanner.Offset; ParserMatch m = ParseMain(scanner); scanner.Offset = offset; return(m); }
/// <summary> /// Construct a new event argument instance /// </summary> /// <param name="match"></param> public ActionEventArgs(ParserMatch match) { if (match == null) throw new ArgumentNullException("match"); if (!match.Success) throw new ArgumentException("Match is not successfull"); m_Match = match; m_TypeValue = null; }
/// <summary> /// Outer parse method (consumes input) /// </summary> /// <param name="scanner"></param> /// <returns></returns> public ParserMatch Parse(IScanner scanner) { ParserMatch m = ParseMain(scanner); if (m.Success) { OnAction(m); } return(m); }
/// <summary> /// Action caller method /// </summary> /// <param name="m"></param> public virtual ParserMatch OnAction(ParserMatch m) { if (m == null) { throw new ArgumentNullException(nameof(m)); } this.Action?.Invoke(this, new ActionEventArgs(m)); return(m); }
/// <summary> /// Outer parse method /// </summary> /// <param name="scanner"></param> /// <returns></returns> public virtual ParserMatch Parse(IScanner scanner) { if (scanner == null) { throw new ArgumentNullException(nameof(scanner)); } ParserMatch m = this.ParseMain(scanner); if (m.Success) { this.OnAction(m); } return(m); }
public ParserError(ParserMatch noMatch, string errorId, string errorMessage) { if (errorId == null) { throw new ArgumentNullException("errorId"); } if (errorMessage == null) { throw new ArgumentNullException("errorMessage"); } long errorOffset = noMatch.Offset + noMatch.Length; IScanner scanner = noMatch.Scanner; long originalOffset = scanner.Offset; long lastLineOffset = 0; scanner.Offset = 0; Parser eol = Prims.Eol; Parser notEol = new CharParser(delegate(Char c) { return c != '\r' && c != '\n'; }); _line=1; // 1 based not 0 based while (!scanner.AtEnd) { notEol.Parse(scanner); if (scanner.AtEnd) { break; } ParserMatch match = eol.Parse(scanner); if (scanner.Offset > errorOffset) { break; } if (match.Success) { ++_line; lastLineOffset = scanner.Offset; } } _column = errorOffset - lastLineOffset + 1; // 1 based not 0 based scanner.Offset = originalOffset; _errorText = errorMessage; _errorId = errorId; }
static private bool AssertMatchSuccess(ParserMatch match) { return match.Success; }
private bool CollationElementIsUnique(ParserMatch match) { // we don't want to have an error if it didn't match // only if it matched but we have already declared this collation element if (match.Success) { string collationElement = _currentCollationElement.ToString(); if (_usedCollationElements.Contains(collationElement)) { return false; } } return true; }
/// <summary> /// Concatenates match with m /// </summary> /// <param name="m"></param> public void Concat(ParserMatch m) { if(m==null) throw new ArgumentNullException("m", "Cannot concatenate null match"); if(!m.Success) throw new ArgumentException("Non-successful matches cannot be concatenated onto matches"); if(!Success) { throw new InvalidOperationException("Matches cannot be concatenated onto non-successful matches"); } // if other is empty, return this if(m.Empty) return; if (m.Offset < Offset) throw new ArgumentException("match reserved ?"); m_Length = (int)(m.Offset-Offset) + m.Length; }