protected override int InnerParse(ParseArgs args) { var scanner = args.Scanner; var length = 0; var pos = scanner.Position; var ch = scanner.ReadChar(); for (int i = 0; i < _items.Count; i++) { var item = _items[i]; var count = 0; while (ch != -1 && item.Test((char)ch)) { length++; count++; ch = scanner.ReadChar(); if (count >= item.Maximum) break; } if (count < item.Minimum) { scanner.Position = pos; return -1; } } scanner.Position = pos + length; return length; }
protected override int InnerParse(ParseArgs args) { var scanner = args.Scanner; var len = 0; int ch; var pos = scanner.Position; if (AllowSign) { ch = scanner.ReadChar(); if (ch == -1) { return -1; } if (ch == '-' || ch == '+') { len++; ch = scanner.ReadChar(); } } else ch = scanner.ReadChar(); bool foundNumber = false; bool hasDecimal = false; bool hasExponent = false; do { if (char.IsDigit((char)ch)) { foundNumber = true; } else if (AllowDecimal && !hasDecimal && ch == DecimalSeparator) { hasDecimal = true; } else if (hasExponent && (ch == '+' || ch == '-')) { } else if (AllowExponent && !hasExponent && (ch == 'E' || ch == 'e')) { hasExponent = true; hasDecimal = true; // no decimals after exponent } else if (!foundNumber) { scanner.Position = pos; return -1; } else break; len++; ch = scanner.ReadChar(); } while (ch != -1); scanner.Position = pos + len; return len; }
protected override int InnerParse(ParseArgs args) { var pos = args.Scanner.Position; var match = Except.Parse(args); if (match < 0) return base.InnerParse(args); args.Scanner.Position = pos; return -1; }
protected override int InnerParse(ParseArgs args) { var pos = args.Scanner.Position; var length = 0; var count = Items.Count; if (separator != null) { var parser = Items[0]; var childMatch = parser.Parse(args); if (childMatch < 0) { return childMatch; } length += childMatch; for (int i = 1; i < count; i++) { var sepMatch = separator.Parse(args); if (sepMatch >= 0) { parser = Items[i]; childMatch = parser.Parse(args); if (childMatch > 0) { length += childMatch + sepMatch; continue; } else if (childMatch == 0) { continue; } } // failed args.Scanner.Position = pos; return -1; } return length; } for (int i = 0; i < count; i++) { var parser = Items[i]; var childMatch = parser.Parse(args); if (childMatch >= 0) { length += childMatch; continue; } args.Scanner.Position = pos; return -1; } return length; }
protected override int InnerParse(ParseArgs args) { var scanner = args.Scanner; int count = 0; var pos = scanner.Position; int length = 0; while (count < Maximum) { int curPos = scanner.Position; int stopMatch; if (skipMatches) { args.Push(); stopMatch = Inner.Parse(args); args.PopFailed(); } else { stopMatch = Inner.Parse(args); } if (stopMatch >= 0) { if (Capture) length += stopMatch; else if (!Skip) scanner.Position = curPos; break; } var ofs = scanner.Advance(1); if (ofs >= 0) { length++; count++; } else { scanner.Position = curPos; break; } } if (count < Minimum) { scanner.Position = pos; return -1; } return length; }
protected override int InnerParse(ParseArgs args) { var scanner = args.Scanner; int ch = scanner.ReadChar(); if (ch != -1) { if (Test((char)ch) != Inverse) { return 1; } scanner.Position--; } return -1; }
protected override int InnerParse(ParseArgs args) { int codePoint; if (!args.Scanner.IsEof && TryGetCodePoint(args.Scanner, out codePoint)) { if (Test(codePoint) != Inverse) { return 2; } } return -1; }
protected override int InnerParse(ParseArgs args) { var count = Items.Count; if (HasNamedChildren) { args.Push(); for (int i = 0; i < count; i++) { var parser = Items[i]; if (parser != null) { var match = parser.Parse(args); if (match < 0) { args.ClearMatches(); } else { args.PopSuccess(); return match; } } else { args.PopFailed(); return 0; } } args.PopFailed(); } else { for (int i = 0; i < count; i++) { var parser = Items[i]; if (parser != null) { var match = parser.Parse(args); if (match >= 0) return match; } else { return 0; } } } return -1; }
protected override int InnerParse(ParseArgs args) { if (!HasNamedChildren) { var match = Inner.Parse(args); return match < 0 ? 0 : match; } else { args.Push(); var match = Inner.Parse(args); if (match >= 0) { args.PopSuccess(); return match; } args.PopFailed(); return 0; } }
protected override int InnerParse(ParseArgs args) { if (TrueValues != null) { for (int i = 0; i < TrueValues.Length; i++) { var val = TrueValues[i]; if (args.Scanner.ReadString(val, caseSensitive)) return val.Length; } } if (FalseValues != null) { for (int i = 0; i < FalseValues.Length; i++) { var val = FalseValues[i]; if (args.Scanner.ReadString(val, caseSensitive)) return val.Length; } } return -1; }
protected override int InnerParse(ParseArgs args) { var pos = args.Scanner.Advance(1); return pos < 0 ? -1 : 1; }
protected override int InnerParse(ParseArgs args) { if (Inner != null) return Inner.Parse(args); return 0; }
protected override int InnerParse(ParseArgs args) { int length = 1; var scanner = args.Scanner; var pos = scanner.Position; int ch; if (AllowQuoted) { ch = scanner.ReadChar(); if (ch == -1) return -1; var quoteIndex = quoteCharString.IndexOf((char)ch); if (quoteIndex >= 0) { char quote = endQuoteCharString[quoteIndex]; bool isEscape = false; ch = scanner.ReadChar(); while (ch != -1) { length++; if (AllowEscapeCharacters && ch == '\\') isEscape = true; else if (!isEscape) { if (ch == quote) { if (!AllowDoubleQuote || scanner.Peek() != quote) return length; isEscape = true; } } else isEscape = false; ch = scanner.ReadChar(); } } length = 0; scanner.Position = pos; } if (AllowNonQuoted && NonQuotedLetter != null) { var m = NonQuotedLetter.Parse(args); while (m > 0) { length += m; m = NonQuotedLetter.Parse(args); } if (length > 0) return length; } return -1; }
public GrammarMatch Match(Scanner scanner) { //scanner.ThrowIfNull("scanner"); var args = new ParseArgs(this, scanner); if (!initialized) Initialize(); Parse(args); var root = args.Root; if (root.Success && EnableMatchEvents) { root.TriggerPreMatch(); root.TriggerMatch(); } return root; }
protected override int InnerParse(ParseArgs args) { if (groupParser != null) return groupParser.Parse(args); return -1; }
protected override int InnerParse(ParseArgs args) { if (args.IsRoot) { var scanner = args.Scanner; var pos = scanner.Position; args.Push(); var match = Inner.Parse(args); MatchCollection matches = null; if (match >= 0 && !AllowPartialMatch && !scanner.IsEof) { args.PopFailed(); scanner.Position = pos; match = -1; } else { matches = args.Pop(); } IEnumerable<Parser> errors = null; if (args.Errors != null) { var errorList = new List<Parser>(args.Errors.Count); for (int i = 0; i < args.Errors.Count; i++) { var error = args.Errors[i]; if (!errorList.Contains(error)) errorList.Add(error); } errors = errorList; } args.Root = new GrammarMatch(this, scanner, pos, match, matches, args.ErrorIndex, args.ChildErrorIndex, errors); return match; } return base.InnerParse(args); }
protected override int InnerParse(ParseArgs args) { return !args.Scanner.ReadString(Value, caseSensitive) ? -1 : Value.Length; }
protected override int InnerParse(ParseArgs args) { var scanner = args.Scanner; int count = 0; var pos = scanner.Position; int length = 0; // retrieve up to the maximum number var sepMatch = 0; if (Inner != null) { while (count < Maximum) { int curPos = scanner.Position; if (Until != null && count >= Minimum) { int stopMatch; if (skipUntilMatches) { args.Push(); stopMatch = Until.Parse(args); args.PopFailed(); } else { stopMatch = Until.Parse(args); } if (stopMatch >= 0) { if (CaptureUntil) length += stopMatch; else if (!SkipUntil) scanner.Position = curPos; return length; } } if (separator != null && count > 0) { sepMatch = separator.Parse(args); if (sepMatch < 0) break; } var childMatch = Inner.Parse(args); if (childMatch > 0) { length += childMatch + sepMatch; count++; } else { if (sepMatch > 0) scanner.Position = curPos; break; } } } else { while (count < Maximum) { int curPos = scanner.Position; if (Until != null && count >= Minimum) { int stopMatch; if (skipUntilMatches) { args.Push(); stopMatch = Until.Parse(args); args.PopFailed(); } else { stopMatch = Until.Parse(args); } if (stopMatch >= 0) { if (CaptureUntil) length += stopMatch; else if (!SkipUntil) scanner.Position = curPos; return length; } } if (separator != null && count > 0) { sepMatch = separator.Parse(args); if (sepMatch < 0) break; } var ofs = scanner.Advance(1); if (ofs >= 0) { length += sepMatch; length++; count++; } else { if (sepMatch > 0) scanner.Position = curPos; break; } } } if (count < Minimum) { scanner.Position = pos; return -1; } return length; }
protected override int InnerParse(ParseArgs args) { return 0; }