RVList <LNode> ParseArgList(Token group) { var ch = group.Children; if (ch != null) { return(new RVList <LNode>(_hostLanguage.Parse(ch, ch.File, ErrorSink, ParsingService.Exprs))); } else { return(RVList <LNode> .Empty); } }
protected void Test(string input, IParsingService inLang, string expected, IParsingService outLang, int maxExpand = 0xFFFF, IMessageSink sink = null) { MacroProcessor lemp = NewLemp(maxExpand, inLang).With(l => l.Sink = sink); var inputCode = new LNodeList(inLang.Parse(input, MessageSink.Default)); Test(inputCode, lemp, expected, outLang); }
public void CreateWordListAndExtractBigrams_VerifyCount(string text, int expectedBigramCount) { var words = _parsingService.Parse(text); var bigrams = _bigramService.Extract(words); Assert.True(bigrams.Count == expectedBigramCount, $"Bigram count = {bigrams.Count} but {expectedBigramCount} was expected."); }
protected LNodeList ParseHostCode(Token group, ParsingMode mode) { var ch = group.Children; if (ch != null) { return(LNode.List(_hostLanguage.Parse(ch, ch.File, ErrorSink, mode))); } else { return(LNode.List()); } }
protected VList <LNode> ParseHostCode(Token group, ParsingMode mode) { var ch = group.Children; if (ch != null) { return(new VList <LNode>(_hostLanguage.Parse(ch, ch.File, ErrorSink, mode))); } else { return(VList <LNode> .Empty); } }
private void Test(string input, IParsingService inLang, string expected, IParsingService outLang, int maxExpand = 0xFFFF) { var lemp = NewLemp(maxExpand); var inputCode = new RVList <LNode>(inLang.Parse(input, _sink)); var results = lemp.ProcessSynchronously(inputCode); var expectCode = outLang.Parse(expected, _sink); if (!results.SequenceEqual(expectCode)) { // TEST FAILED, print error string resultStr = results.Select(n => outLang.Print(n, _sink)).Join("\n"); Assert.AreEqual(TestCompiler.StripExtraWhitespace(expected), TestCompiler.StripExtraWhitespace(resultStr)); } }
protected void Test(LNodeList input, MacroProcessor lemp, string expected, IParsingService outLang) { // The current printer affects the assert macro and contract macros, // so we'll want to set it up before running LeMP using (LNode.SetPrinter((ILNodePrinter)outLang)) { var inputCode = input; var results = lemp.ProcessSynchronously(inputCode); var expectCode = outLang.Parse(expected, MessageSink.Default); if (!results.SequenceEqual(expectCode)) { // TEST FAILED, print error string resultStr = results.Select(n => ((ILNodePrinter)outLang).Print(n)).Join("\n"); Assert.AreEqual(TestCompiler.StripExtraWhitespace(expected), TestCompiler.StripExtraWhitespace(resultStr)); // In some tests, the text is equal even though the trees are different, // typically because of differences in #trivia attributes between the two. Console.WriteLine("(minor dif)"); // it's OK, but print a hint that this occurred. } } }
protected void Test(string input, IParsingService inLang, string expected, IParsingService outLang, int maxExpand = 0xFFFF) { var lemp = NewLemp(maxExpand, inLang); using (ParsingService.PushCurrent(inLang)) { var inputCode = new VList <LNode>(inLang.Parse(input, MessageSink.Current)); var results = lemp.ProcessSynchronously(inputCode); var expectCode = outLang.Parse(expected, MessageSink.Current); if (!results.SequenceEqual(expectCode)) { // TEST FAILED, print error string resultStr = results.Select(n => outLang.Print(n)).Join("\n"); Assert.AreEqual(TestCompiler.StripExtraWhitespace(expected), TestCompiler.StripExtraWhitespace(resultStr)); // In some tests, the text is equal even though the trees are different, // typically because of differences in #trivia attributes between the two. Console.WriteLine(); // it's OK, but print a hint that this occurred. } } }
public void StringDomains_VerifyBuckets(string testString) { var words = _parsingService.Parse(testString); var domain = _histogramService.BuildStringDomain(words); Assert.True(words.Count == domain.Count); int wordIndex = 0; foreach (var bucket in domain) { Assert.True(bucket.Value == words[wordIndex], $"Bucket Value ({bucket.Value}) does not match word ({words[wordIndex]}"); Assert.True(bucket.Key == words[wordIndex].GetHashCode(), "Key does not match the hash code of word"); Assert.True(bucket.Count == 0, "Count is not zero"); Assert.True(bucket.SortOrder == wordIndex, "Sort Order does not match word index"); wordIndex++; } }
protected void Test(string input, IParsingService inLang, string expected, IParsingService outLang, int maxExpand = 0xFFFF) { var lemp = NewLemp(maxExpand, inLang); // The current printer affects the assert macro and contract macros using (LNode.SetPrinter((ILNodePrinter)outLang)) { var inputCode = new VList<LNode>(inLang.Parse(input, MessageSink.Default)); var results = lemp.ProcessSynchronously(inputCode); var expectCode = outLang.Parse(expected, MessageSink.Default); if (!results.SequenceEqual(expectCode)) { // TEST FAILED, print error string resultStr = results.Select(n => ((ILNodePrinter)outLang).Print(n)).Join("\n"); Assert.AreEqual(TestCompiler.StripExtraWhitespace(expected), TestCompiler.StripExtraWhitespace(resultStr)); // In some tests, the text is equal even though the trees are different, // typically because of differences in #trivia attributes between the two. Console.WriteLine(); // it's OK, but print a hint that this occurred. } } }
/// <summary>Parses a string and expects exactly one output.</summary> /// <exception cref="InvalidOperationException">The output list was empty or contained multiple nodes.</exception> public static LNode ParseSingle(this IParsingService parser, ICharSource text, string fileName, IMessageSink msgs = null, ParsingMode inputType = null, bool preserveComments = true) { var e = parser.Parse(text, fileName, msgs, inputType, preserveComments); return(Single(e)); }
/// <summary>Parses a string and expects exactly one output.</summary> /// <exception cref="InvalidOperationException">The output list was empty or contained multiple nodes.</exception> public static LNode ParseSingle(this IParsingService parser, UString expr, IMessageSink msgs = null, ParsingMode inputType = null, bool preserveComments = true) { var e = parser.Parse(expr, msgs, inputType, preserveComments); return(Single(e)); }
/// <summary>Parses a string by invoking <see cref="IParsingService.Parse(ICharSource, string, IMessageSink, ParsingMode, bool)"/> using an empty string as the file name.</summary> public static IListSource <LNode> Parse(this IParsingService parser, UString input, IMessageSink msgs = null, ParsingMode inputType = null, bool preserveComments = true) { return(parser.Parse(input, "", msgs ?? MessageSink.Default, inputType, preserveComments)); }
public static IListSource <LNode> Parse(this IParsingService parser, ILexer <Token> input, IMessageSink msgs = null, ParsingMode mode = null, bool preserveComments = true) { return(parser.Parse(input, msgs, QuickOptions(mode, preserveComments))); }
public static IListSource <LNode> Parse(this IParsingService parser, IListSource <Token> tokens, ISourceFile file, IMessageSink msgs, ParsingMode inputType = null) { return(parser.Parse(tokens, file, msgs, QuickOptions(inputType))); }
public static LNode ParseSingle(this IParsingService parser, ICharSource file, string fileName, IMessageSink msgs = null, Symbol inputType = null) { var e = parser.Parse(file, fileName, msgs, inputType); return(Single(e)); }
public static LNode ParseSingle(this IParsingService parser, string expr, IMessageSink msgs = null, Symbol inputType = null) { var e = parser.Parse(expr, msgs, inputType); return(Single(e)); }
public static IListSource <LNode> Parse(this IParsingService parser, ICharSource text, string fileName, IMessageSink msgs = null, ParsingMode inputType = null, bool preserveComments = true) { return(parser.Parse(text, fileName, msgs ?? MessageSink.Default, QuickOptions(inputType, preserveComments))); }
/// <summary>Parses a string and expects exactly one output.</summary> /// <exception cref="InvalidOperationException">The output list was empty or contained multiple nodes.</exception> public static LNode ParseSingle(this IParsingService parser, ICharSource text, string fileName, IMessageSink msgs = null, IParsingOptions options = null) { var e = parser.Parse(text, fileName, msgs ?? MessageSink.Default, options ?? _fileWithComments); return(Single(e)); }
/// <summary>Parses a Stream.</summary> public static IListSource <LNode> Parse(this IParsingService parser, Stream stream, string fileName, ParsingMode inputType = null, IMessageSink msgs = null, bool preserveComments = true) { return(parser.Parse(new StreamCharSource(stream), fileName, msgs, inputType, preserveComments)); }
public static IEnumerable<LNode> ParseNodes(string Text, string Identifier, IParsingService Service, MacroProcessor Processor, IMessageSink Sink) { var lexer = Service.Tokenize(new UString(Text), Identifier, Sink); var nodes = Service.Parse(lexer, Sink); return Processor.ProcessSynchronously(new VList<LNode>(nodes)); }
private void Test(string input, IParsingService inLang, string expected, IParsingService outLang, int maxExpand = 0xFFFF) { var lemp = NewLemp(maxExpand); var inputCode = new RVList<LNode>(inLang.Parse(input, _sink)); var results = lemp.ProcessSynchronously(inputCode); var expectCode = outLang.Parse(expected, _sink); if (!results.SequenceEqual(expectCode)) { // TEST FAILED, print error string resultStr = results.Select(n => outLang.Print(n, _sink)).Join("\n"); Assert.AreEqual(TestCompiler.StripExtraWhitespace(expected), TestCompiler.StripExtraWhitespace(resultStr)); } }
public static IListSource <LNode> Parse(this IParsingService parser, Stream stream, string fileName, IMessageSink msgs = null, Symbol inputType = null) { return(parser.Parse(new StreamCharSource(stream), fileName, msgs, inputType)); }
public static IListSource <LNode> Parse(this IParsingService parser, string input, IMessageSink msgs = null, Symbol inputType = null) { return(parser.Parse(new StringSlice(input), "", msgs ?? MessageSink.Current, inputType)); }
/// <summary>Parses a string by invoking <see cref="IParsingService.Parse(ICharSource, string, IMessageSink, IParsingOptions)"/> using an empty string as the file name.</summary> public static IListSource <LNode> Parse(this IParsingService parser, UString input, IMessageSink msgs, IParsingOptions options) { return(parser.Parse(input, "", msgs ?? MessageSink.Default, options ?? _fileWithComments)); }