private LuaParser CreateParser() { var handler = new ParaEngine.Tools.Lua.Parser.ErrorHandler(); LuaScanner scanner = new LuaScanner(); LuaParser parser = new LuaParser(); scanner.Handler = handler; parser.scanner = scanner; parser.Request = null; return(parser); }
private Chunk ParseSource(string source) { if (source == null) { throw new ArgumentNullException("source"); } //Create a parser for the request LuaParser parser = CreateParser(); // Set the source ((LuaScanner)parser.scanner).SetSource(source, 0); // Trigger the parse (hidden region and errors will be added to the AuthoringSink) parser.Parse(); return(parser.Chunk); }
private void RefreshDeclarationsForRequest(ParseRequest request, LuaParser parser, bool addLocals) { luaFileDeclarationProviders[request.FileName] = new TableDeclarationProvider(); // Create an AST declaration parser to add the declarations from the parsed chunk var declarationParser = new AstDeclarationParser(luaFileDeclarationProviders[request.FileName]); // Parse the AST and add the declaarations if(addLocals) declarationParser.AddChunk(parser.Chunk, request.Line, request.Col); else declarationParser.AddChunk(parser.Chunk); }
/// <summary> /// Creates the parser. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> private static LuaParser CreateParser(ParseRequest request) { // Create ErrorHandler for scanner var handler = new ParaEngine.Tools.Lua.Parser.ErrorHandler(); // Create scanner and parser LuaScanner scanner = new ParaEngine.Tools.Lua.Lexer.Scanner(); LuaParser parser = new LuaParser(); // Set the error handler for the scanner scanner.Handler = handler; // Associate the scanner with the parser parser.scanner = scanner; // Initialize with the request (can be null) parser.Request = request; // If the parser is created for a request, automatically set the source from the request if (request != null) scanner.SetSource(request.Text, 0); // Return the parser return parser; }