private static void charTest(string testName, Func <char, bool> predicate, int times, int maxItemCount, string inputText) { Console.WriteLine(testName); CharParsersPerformanceTests.CharParserTest(CharParsers.Satisfy(predicate), times, maxItemCount, inputText); Console.WriteLine(); }
private static void testBacktracking() { var letExpr = stringParser("let"); var identifier = CharParsers.Many1(CharParsers.Satisfy(c => char.IsLetter(c))); var expr = CharParsers.Choice(letExpr, identifier); displayResult(runParser(expr, "lexical")); }
private Parser <char, string> createParser(BasePattern pattern) { if (pattern == null) { throw new ArgumentNullException("pattern.", "Pattern is null when creating match parser."); } switch (pattern.Type) { case PatternType.Group: return(from vs in CharParsers.Sequence(((GroupPattern)pattern).Patterns .Select(p => createParser(p))) select vs.JoinStrings()); case PatternType.Quantifier: QuantifierPattern quant = (QuantifierPattern)pattern; return(from vs in CharParsers.Count(quant.MinOccurrences, quant.MaxOccurrences, createParser(quant.ChildPattern)) select vs.JoinStrings()); case PatternType.Alternation: return(CharParsers.Choice(((AlternationPattern)pattern).Alternatives .Select(p => createParser(p)) .ToArray())); case PatternType.String: return(CharParsers.String(((StringPattern)pattern).Value)); case PatternType.Char: return(from c in CharParsers.Satisfy(((CharPattern)pattern).IsMatch) select new string(c, 1)); default: throw new ApplicationException( string.Format("ExplicitDFAMatcher: unrecognized pattern type ({0}).", pattern.GetType().Name)); } }