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);
		}
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }
예제 #4
0
        /// <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()));
        }
예제 #5
0
 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);
 }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
		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);
		}