コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: MacroTesterBase.cs プロジェクト: dadhi/ecsharp
        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);
        }
コード例 #3
0
        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.");
        }
コード例 #4
0
ファイル: StageOneParser.cs プロジェクト: dadhi/ecsharp
        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());
            }
        }
コード例 #5
0
ファイル: StageOneParser.cs プロジェクト: modulexcite/ecsharp
        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);
            }
        }
コード例 #6
0
ファイル: StandardMacroTests.cs プロジェクト: bel-uwa/Loyc
        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));
            }
        }
コード例 #7
0
ファイル: MacroTesterBase.cs プロジェクト: dadhi/ecsharp
 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.
         }
     }
 }
コード例 #8
0
        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.
                }
            }
        }
コード例 #9
0
        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++;
            }
        }
コード例 #10
0
ファイル: MacroTesterBase.cs プロジェクト: qwertie/ecsharp
		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.
				}
			}
		}
コード例 #11
0
        /// <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));
        }
コード例 #12
0
        /// <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));
        }
コード例 #13
0
 /// <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));
 }
コード例 #14
0
ファイル: IParsingService.cs プロジェクト: dadhi/ecsharp
 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)));
 }
コード例 #15
0
ファイル: IParsingService.cs プロジェクト: dadhi/ecsharp
 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)));
 }
コード例 #16
0
        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));
        }
コード例 #17
0
        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));
        }
コード例 #18
0
ファイル: IParsingService.cs プロジェクト: dadhi/ecsharp
 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)));
 }
コード例 #19
0
ファイル: IParsingService.cs プロジェクト: dadhi/ecsharp
        /// <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));
        }
コード例 #20
0
 /// <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));
 }
コード例 #21
0
        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));
        }
コード例 #22
0
ファイル: StandardMacroTests.cs プロジェクト: Shaykh/Loyc
		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));
			}
		}
コード例 #23
0
ファイル: IParsingService.cs プロジェクト: lydonchandra/Loyc
 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));
 }
コード例 #24
0
 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));
 }
コード例 #25
0
ファイル: IParsingService.cs プロジェクト: dadhi/ecsharp
 /// <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));
 }