Exemplo n.º 1
0
        public TextHighlighter(RichTextBox textbox, Scanner scanner, Parser parser)
        {
            Textbox = textbox;
            Scanner = scanner;
            Parser = parser;

            ClearUndo();

            //Tree = Parser.Parse(Textbox.Text);
            Textbox.TextChanged += new EventHandler(Textbox_TextChanged);
            textbox.KeyDown += new KeyEventHandler(textbox_KeyDown);
            Textbox.SelectionChanged += new EventHandler(Textbox_SelectionChanged);
            Textbox.Disposed += new EventHandler(Textbox_Disposed);

            SwitchContext = null;
            currentContext = Tree;

            threadAutoHighlight = new Thread(AutoHighlightStart);
            threadAutoHighlight.Start();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            #if DEBUG
            mode = "Debug";
            #else
            mode = "Release";
            #endif

            //Mizu.Lib.Evaluator.Evaluator.Eval("var a=5;(2+2)");
            #if !DEBUG
            try
            {
            #endif
                Console.WriteLine("Mizu Compiler v" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + " " + mode + " build.");
                if (args.Length >= 2)
                {
                    if (System.IO.File.Exists(args[0]))
                    {
                        var info = new FileInfo(args[0]); //Loads info on the input file.
                        Console.WriteLine("Parsing: " + info.Name);

                        var scanner = new Mizu.Parser.Scanner(); //Makes a scanner.
                        var parser = new Mizu.Parser.Parser(scanner); //Makes a parser

                        code = File.ReadAllText(args[0]); //Reads all the code.

                        if (code.Length == 0)
                        {
                            Console.Error.WriteLine("Error: Input file cannot be empty.");
                            return;
                        }

                        var parsetree = parser.Parse(code); //Parse the code.
                        if (parsetree.Errors.Count > 0)
                        {
                            foreach (Mizu.Parser.ParseError err in parsetree.Errors) //Report all errors.
                            {
                                Console.Error.WriteLine("Error: {0} - On pos: {1}, line: {2}, col: {3}.", err.Message, err.Position, err.Line, err.Column);
                                return;
                            }
                        }
                        else
                        {
                            var output = new FileInfo(args[1]); //Get info on the future output file.

                            if (output.Extension.Length == 0)
                            {
                                Console.Error.WriteLine("Error: Output filename must have an extension.");
                                return;
                            }

                            Console.WriteLine("Compiling: {0} -> {1}", info.Name, output.Name);

                            if (args.Length > 2)
                            {
                                for (int i = 2; i < args.Length; i++)
                                {
                                    switch (args[i].ToLower())
                                    {
                                        case "/debug":
                                            {
                                                if (!IsDebug)
                                                    Console.WriteLine("- Emitting debugging information.");

                                                IsDebug = true;
                                                break;
                                            }
                                        case "/invalid":
                                            {
                                                if (!IsInvalid)
                                                    Console.WriteLine("- Executable will be invalid on purpose.");

                                                IsInvalid = true;
                                                break;
                                            }
                                        case "/run":
                                            {
                                                if (!IsRun)
                                                    Console.WriteLine("- Executable will run when completed.");

                                                IsRun = true;
                                                break;
                                            }
                                        case "/noeval":
                                            {
                                                if (!NoEval)
                                                    Console.WriteLine("- Executable will not depend on Mizu.Lib.Evaluator.dll. NOTE: This is experimental.");

                                                NoEval = true;
                                                break;
                                            }
                                    }
                                }
                            }

                            bool result = Compile(parsetree, info, output); //Start the compiler process.

                            if (IsRun && result)
                                Process.Start(output.FullName);
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine("Error: Input file doesn't exist.");
                        return;
                    }
                }
                else
                {
                    Console.WriteLine("Accepted Input: mizu <input file> <output file> <switchs?>");
                }
            #if !DEBUG
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                return;
            }
            #endif
        }