private static IEnumerable<string> FindPossibilities(GrammarMatch match) { var literals = new List<string>(); foreach (var child in match.Errors) { literals.AddRange(FindPossibilities(child)); } return literals.Distinct().OrderBy(l => l); }
private static IEnumerable <string> FindPossibilities(GrammarMatch match) { var literals = new List <string>(); foreach (var child in match.Errors) { literals.AddRange(FindPossibilities(child)); } return(literals.Distinct().OrderBy(l => l)); }
public GoldDefinition Build(string grammar) { GrammarMatch match = Match(grammar); if (!match.Success) { throw new FormatException(string.Format("Error parsing gold grammar: {0}", match.ErrorMessage)); } return(definition); }
/// <summary> /// Parses the specified json into a token value /// </summary> /// <param name="json">Json string to parse</param> public static JsonToken Parse(string json) { GrammarMatch match = Grammar.Match(json); if (!match.Success) { throw new ArgumentOutOfRangeException("json", string.Format("Invalid Json string: {0}", match.ErrorMessage)); } return(GetToken(match.Matches.First())); }
public static void TestAddress(GrammarMatch match) { Assert.IsTrue(match.Success, match.ErrorMessage); Assert.AreEqual("Joe", match["first-name", true].Text); Assert.AreEqual("Smith", match["last-name", true].Text); Assert.AreEqual("123", match["house-num", true].Text); Assert.AreEqual("Elm Street", match["street", true].Text); Assert.AreEqual("Elm", match["street-name", true].Text); Assert.AreEqual("Street", match["street-type", true].Text); Assert.AreEqual("Vancouver", match["town-name", true].Text); Assert.AreEqual("BC", match["state-code", true].Text); Assert.AreEqual("V5V5V5", match["zip-code", true].Text); }
public Grammar Build(string bnf, string startParserName) { this.startParserName = startParserName; Parser parser; GrammarMatch match = Match(new StringScanner(bnf)); if (!match.Success) { throw new FormatException(string.Format("Error parsing bnf: \n{0}", match.ErrorMessage)); } if (!parserLookup.TryGetValue(startParserName, out parser)) { throw new ArgumentException("the topParser specified is not found in this bnf"); } return(parser as Grammar); }
public GrammarMatch Match(Scanner scanner) { //scanner.ThrowIfNull("scanner"); var args = new ParseArgs(this, scanner); if (!initialized) { Initialize(); } Parse(args); GrammarMatch root = args.Root; if (root.Success && EnableMatchEvents) { root.TriggerPreMatch(); root.TriggerMatch(); } return(root); }
public MatchCollection Matches(Scanner scanner) { scanner.ThrowIfNull("scanner"); var matches = new MatchCollection(); bool eof = scanner.IsEof; while (!eof) { GrammarMatch match = Match(scanner); if (match.Success) { matches.AddRange(match.Matches); eof = scanner.IsEof; } else { eof = scanner.Advance(1) < 0; } } return(matches); }