コード例 #1
0
        public static void Test(string s, Grammar.Rule r)
        {
            try
            {
                Print(string.Format("Using rule {0} to parse string {1}", r.ToString(), s));

                var nodes = RubyParser.ParseByRule(s, r);
                if (nodes == null || nodes.Count != 1)
                {
                    Print("Parsing failed!", ConsoleColor.Red);
                }
                else if (nodes[0].ToString() != s)
                {
                    Print("Parsing partially succeeded", ConsoleColor.Yellow);
                }
                else
                {
                    Print("Parsing suceeded", ConsoleColor.Green);
                }

                if (nodes != null && nodes.Count > 0)
                {
                    Console.WriteLine(nodes[0] + "\n");
                }
                else
                {
                    Console.WriteLine();
                }
            }
            catch (Exception e)
            {
                Print("Parsing failed with exception:", ConsoleColor.Red);
                Print(e.Message + "\n" + e.StackTrace + "\n", ConsoleColor.Gray);
            }
        }
コード例 #2
0
        public static List <RubyAstNode> ParseByRule(string s, Grammar.Rule rule)
        {
            Parser parser = new Parser(s);

            try {
                bool bResult = parser.Parse(rule);
                if (!bResult)
                {
                    throw new Exception("failed to parse input");
                }
            }
            catch (Exception e) {
                Console.WriteLine("Parsing error occured with message: " + e.Message);
                Console.WriteLine(parser.ParserPosition);
                throw e;
            }

            RubyScript tmp = new RubyScript(parser.GetAst());

            return(tmp.mStatements);
        }
コード例 #3
0
 public static void TestParse(string s, Grammar.Rule r)
 {
     GrammarTest.Test(s, r);
 }