コード例 #1
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);
		}
コード例 #2
0
ファイル: AutocompleteTests.cs プロジェクト: yallie/Eto.Parse
        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
ファイル: JsonTokens.cs プロジェクト: rajeshwarn/Creek
        /// <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
ファイル: BnfTests.cs プロジェクト: yallie/Eto.Parse
 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
ファイル: BnfTests.cs プロジェクト: halid-durakovic/Eto.Parse
		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);
		}