예제 #1
0
        public EnvFile ProcessFile(String name, String contents)
        {
            if (this.PathFiles.ContainsKey(name))
            {
                return(this.PathFiles[name]);
            }

            var file      = new EnvFile(name, contents);
            var tokenizer = new GLuaLexer(contents);
            var parser    = new GLuaParser(tokenizer, this);

            this.PathFiles[name]       = file;
            this.LexerFiles[tokenizer] = file;
            this.ParserFiles[parser]   = file;

            file.Successful = true;
            try
            {
                file.AST = parser.Parse( );
            }
            catch (Exception)
            {
                file.Successful = false;
                throw;
            }

            if (file.Successful)
            {
                foreach (IPriorityContainer module in this.Modules.Values.OrderBy(con => con.Priority))
                {
                    if (module is AnalyserEntry entryA)
                    {
                        entryA.Analyser.File = file;
                        entryA.Analyser.Analyse(file.AST);
                    }
                    else if (module is FolderEntry entryB)
                    {
                        entryB.Folder.File = file;
                        file.AST           = ( StatementList )entryB.Folder.Fold(file.AST);
                    }
                }

                foreach (Error err in file.Errors)
                {
                    if (err.Type == ErrorType.Error || err.Type == ErrorType.Fatal)
                    {
                        file.Successful = false;
                        break;
                    }
                }
            }

            return(file);
        }
예제 #2
0
 private static Double?StringToNumber(String str)
 {
     try
     {
         var lexer = new GLuaLexer(str);
         foreach (LToken token in lexer.Lex( ))
         {
             return(( Double )token.Value);
         }
         return(null);
     }
     catch (Exception)
     {
         return(null);
     }
 }
예제 #3
0
        public static void LexFile(String filePath, String outputPath = "stdin")
        {
            if (!File.Exists(filePath))
            {
                throw new Exception("File doesn't exists.");
            }

            StreamWriter outputWriter;

            using (outputWriter = outputPath == "stdin"
                ? new StreamWriter(Console.OpenStandardOutput( ), Encoding.UTF8, 4096)
                : new StreamWriter(outputPath, false, Encoding.UTF8, 4096))
                using (FileStream handle = File.OpenRead(filePath))
                {
                    var max  = new SourceLocation(Int32.MaxValue, Int32.MaxValue, Int32.MaxValue);
                    var last = new SourceRange(max, max);

                    var sw    = Stopwatch.StartNew( );
                    var lexer = new GLuaLexer(handle);
                    foreach (LToken token in lexer.Lex( ))
                    {
                        outputWriter.WriteLine($"LToken ( '{token.ID}', '{token.Raw}', '{token.Value}', {token.Type}, {token.Range} )");
                        foreach (Token flair in token.LeadingFlair)
                        {
                            outputWriter.WriteLine($"\tLTokenFlair ( '{flair.ID}', '{flair.Raw}', '{flair.Value}', {flair.Type}, {flair.Range} )");
                        }

                        if (last == token.Range && token.Type != TokenType.EOF)
                        {
                            throw new Exception("Possible infinite loop. Token has same range as last.");
                        }
                        last = token.Range;
                    }
                    sw.Stop( );
                    outputWriter.WriteLine($"Time elapsed on lexing: {HumanTime ( sw )}");
                }
        }
예제 #4
0
 public GLuaParser(GLuaLexer lexer, LuaEnvironment environment) : base(lexer)
 {
     this.Environment = environment;
     this.RootScope   = this.CreateScope(null);
     this.ScopeStack  = new Stack <Scope> ( );
 }
예제 #5
0
 public EnvFile GetFile(GLuaLexer lexer)
 => this.LexerFiles.ContainsKey(lexer) ? this.LexerFiles[lexer] : null;