Example #1
0
        protected static StringBuilder BuildResult(OneOperatorMatch <AstNode> expr, StringBuilder sb)
        {
            //sb.Append(expr.Operator.NodeType.SafeName);
            bool first = true;

            foreach (OneOperatorMatchPart <AstNode> part in expr.Parts)
            {
                if (!first)
                {
                    sb.Append(" ");
                }
                else
                {
                    first = false;
                }
                if (part.MatchedExpr)
                {
                    sb.Append('(');
                    BuildResult(part.Expr, sb);
                    sb.Append(')');
                }
                else
                {
                    sb.Append(part.Text);
                }
            }
            return(sb);
        }
Example #2
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 #3
0
 public static string BuildResult(OneOperatorMatch <AstNode> expr)
 {
     return(BuildResult(expr, new StringBuilder()).ToString());
 }