Ejemplo n.º 1
0
        private List <NewFolding> CreateNewFoldings(String text, ref List <MarkerPosition> markers)
        {
            List <NewFolding> newFoldings = null;

            try
            {
                using (var reader = new StringReader(text))
                {
                    var antlrInputStream = new AntlrInputStream(reader);
                    var lexer            = new LuaLexer(antlrInputStream);
                    var tokens           = new CommonTokenStream(lexer);
                    var parser           = new LuaParser(tokens)
                    {
                        BuildParseTree = true
                    };
                    parser.RemoveErrorListeners();
                    parser.AddErrorListener(new MyErrorListener(_textMarkerService, ref markers));
                    var tree    = parser.block();
                    var visitor = new LuaVisitor();
                    newFoldings = visitor.Visit(tree);
                    Interlocked.Exchange(ref _syntaxErrors, parser.NumberOfSyntaxErrors);
                }
            }
            catch (Exception e)
            {
                // MessageBox.Show(e.ToString(), "NodeMCU Studio 2015", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.Yes);
                //On error resume next
            }

            return(newFoldings ?? new List <NewFolding>());
        }
Ejemplo n.º 2
0
        public static int ScriptMain(Options opts, List <string> args)
        {
            if (opts.Help)
            {
                PrintScriptHelp();
                return(0);
            }

            if (args.Count < 2)
            {
                Console.WriteLine("Not enough arguments.");
                PrintScriptHelp();
                return(1);
            }

            try {
                var runtime = new XTRuntime.XTRuntime();
                var visitor = new LuaVisitor(runtime);
                runtime.DoFile(args[1]);

                var parser = new Parser(File.ReadAllText(args[0]));
                var block  = parser.Read();

                visitor.Visit(block);

                Console.WriteLine(block);
            } catch (Exception e) {
                Console.WriteLine($"An error occured while transforming the script:");
                Console.WriteLine(e.Message);
                if (opts.Verbose)
                {
                    Console.WriteLine(e.StackTrace);
                }
                return(1);
            }

            return(0);
        }