Example #1
0
        protected void DoTest(string Input, bool untilEnd, string expected)
        {
            // Lex and filter the input, then wrap it in an EnumerableSource and parse it
            StringCharSourceFile  input = new StringCharSourceFile(Input);
            IEnumerable <AstNode> lexer;

            if (untilEnd)
            {
                lexer = new BooLexerCore(input, new Dictionary <string, Symbol>());
            }
            else
            {
                lexer = new BooLexer(input, new Dictionary <string, Symbol>(), true);
            }
            IEnumerable <AstNode>      lexFilter = new VisibleTokenFilter <AstNode>(lexer);
            EnumerableSource <AstNode> source    = new EnumerableSource <AstNode>(lexFilter);
            int pos = 0;
            OneOperatorMatch <AstNode> expr = _parser.Parse((IParserSource <AstNode>)source, ref pos, untilEnd);

            // Build result string
            Assert.IsNotNull(expr);
            string result = BuildResult(expr);

            Assert.AreEqual(expected, result);
        }
Example #2
0
            public void Test(int testNum)
            {
                StringCharSourceFile  input  = new StringCharSourceFile(Input);
                BooLexerCore          lexer  = new BooLexerCore(input, new Dictionary <string, Symbol>());
                IEnumerator <AstNode> lexerE = lexer.GetEnumerator();

                string[] toks = Toks.Split(',');
                AstNode  t;

                for (int i = 0; i < toks.Length; i++)
                {
                    var    _ = StringExt.SplitAt(toks[i], ':');
                    string wantType = _.A, wantText = _.B;

                    wantType = wantType.Trim();

                    // Get the next token
                    Assert.IsTrue(lexerE.MoveNext());
                    t = lexerE.Current;
                    string type = t.NodeType.Name;
                    string msg  = string.Format("Test[{0}][{1}]: Expected {2}<{3}>, got {4}<{5}>",
                                                testNum, i, wantType, wantText, type, t.SourceText);
                    Assert.AreEqual(wantType, type, msg);
                    Assert.AreEqual(wantText, t.SourceText, msg);
                }
                Assert.IsFalse(lexerE.MoveNext());
            }
Example #3
0
			public void Test(int testNum) 
			{
				StringCharSourceFile input = new StringCharSourceFile(Input);
				BooLexerCore lexer = new BooLexerCore(input, new Dictionary<string, Symbol>());
				IEnumerator<AstNode> lexerE = lexer.GetEnumerator();

				string[] toks = Toks.Split(',');
				AstNode t;
				for(int i = 0; i < toks.Length; i++) {
					var _ = StringExt.SplitAt(toks[i], ':');
					string wantType = _.A, wantText = _.B;
					
					wantType = wantType.Trim();
					
					// Get the next token
					Assert.IsTrue(lexerE.MoveNext());
					t = lexerE.Current;
					string type = t.NodeType.Name;
					string msg = string.Format("Test[{0}][{1}]: Expected {2}<{3}>, got {4}<{5}>", 
						testNum, i, wantType, wantText, type, t.SourceText);
					Assert.AreEqual(wantType, type, msg);
					Assert.AreEqual(wantText, t.SourceText, msg);
				}
				Assert.IsFalse(lexerE.MoveNext());
			}
		public void DoTest(string input, bool boo, bool success, params object[] outputs)
		{
			ILanguageStyle lang;
			ISourceFile src;
			IEnumerable<AstNode> lexer;
			if (boo) {
				lang = new BooLanguage();
				src = new StringCharSourceFile(input);
				lexer = new BooLexer(src, lang.StandardKeywords, false);
			} else {
				lang = new BooLanguage();
				src = new StringCharSourceFile(input);
				lexer = new BooLexerCore(src, lang.StandardKeywords);
			}
			EssentialTreeParser etp = new EssentialTreeParser();
			AstNode root = AstNode.New(SourceRange.Nowhere, GSymbol.Empty);

			Assert.AreEqual(success, etp.Parse(ref root, lexer));
			CheckOutput(root, outputs, 0);
		}
Example #5
0
        public void DoTest(string input, bool boo, bool success, params object[] outputs)
        {
            ILanguageStyle        lang;
            ISourceFile           src;
            IEnumerable <AstNode> lexer;

            if (boo)
            {
                lang  = new BooLanguage();
                src   = new StringCharSourceFile(input);
                lexer = new BooLexer(src, lang.StandardKeywords, false);
            }
            else
            {
                lang  = new BooLanguage();
                src   = new StringCharSourceFile(input);
                lexer = new BooLexerCore(src, lang.StandardKeywords);
            }
            EssentialTreeParser etp  = new EssentialTreeParser();
            AstNode             root = AstNode.New(SourceRange.Nowhere, GSymbol.Empty);

            Assert.AreEqual(success, etp.Parse(ref root, lexer));
            CheckOutput(root, outputs, 0);
        }