Inheritance: PrintNode
Example #1
0
 internal Engine Parse(bool showTree, Element env)
 {
     var matches = _parser.Parse();
     if(!matches) throw new ParsingException("FAILURE: Parser did not match input file");
     var pegEl = _parser.GetRoot();
     var treeWalker = new TreeBuilder(pegEl, less);
     Root = treeWalker.Build();
     css = Root.Group().ToCss();
     if (showTree)
     {
         var tprint = new TreePrint(Console.Out, less, 60, new NodePrinter(_parser).GetNodeName, false);
         tprint.PrintTree(_parser.GetRoot(), 0, 0);
     }
     return this;
 }
        static int Main(string[] args)
        {
            if (args.Length < 1 || !File.Exists(args[0]))
            {
                Console.WriteLine("FATAL: First command line parameter must be an existing file");
                return -1;
            }
            try
            {
                FileLoader loader = new FileLoader(json_tree.json_tree.encodingClass,json_tree.json_tree.unicodeDetection, args[0]);
                Debug.Assert(!loader.IsBinaryFile());
                string src;
                if (loader.LoadFile(out src))
                {
                    json_tree.json_tree jsonParser = new json_tree.json_tree(src, Console.Out);
                    bool bMatches = jsonParser.json_text();
                    if (bMatches)
                    {
                        Console.WriteLine("SUCCESS: Json Parser matched input file '{0}'", args[0]);
                        TreePrint tprint = new TreePrint(Console.Out, src, 60, new NodePrinter(jsonParser).GetNodeName, false);
                        tprint.PrintTree(jsonParser.GetRoot(), 0, 0);
                    }
                    else
                    {
                        Console.WriteLine("FAILURE: Json Parser did not match input file '{0]'", args[0]);
                    }
                    return 0;
                }
                else
                {
                    Console.WriteLine("FATAL: File '{0}' could not be loaded", args[0]);
                    return -1;
                }

            }
            catch (Exception e)
            {
                Console.WriteLine("FATAL: Program terminated by exception '{0}'",e.Message);
                return -1;
            }
        }