/// <summary> /// Translates Chunk node to LuaCodeClass. /// </summary> /// <param name="chunk">Instance of Chunk.</param> /// <param name="name">Class name.</param> /// <returns></returns> public LuaCodeClass Translate(Chunk chunk, string name) { rootElement = new LuaCodeClass(dte, parent, name, chunk); rootClass = CreateVirtualFunction(rootElement); AddElementToParent(rootElement, rootClass); try { if (chunk.Block != null) foreach (Block member in chunk.Block) { if (member.StatementList != null) foreach (Node node in member.StatementList) { RecurseNode(node); } } //TraceDump(rootElement); } catch (ThreadAbortException) { } catch (Exception ex) { Trace.WriteLine(ex); dte.StatusBar.Text = "An error has occured during parsing source."; dte.StatusBar.Highlight(true); } return rootElement; }
/// <summary> /// Adds the full chunk. /// </summary> /// <param name="chunk"></param> public void AddChunk(Chunk chunk) { if (chunk == null) throw new ArgumentNullException("chunk"); chunk.InitializeContext(); AddNode(chunk, Int32.MaxValue, Int32.MaxValue, TableDeclarationProvider.DeclarationsTable, false); }
/// <summary> /// Adds a chunk with location information. /// </summary> public void AddChunk(Chunk chunk, int line, int column) { if (chunk == null) throw new ArgumentNullException("chunk"); chunk.InitializeContext(); AddNode(chunk, line, column, TableDeclarationProvider.DeclarationsTable, false); }
/// <summary> /// Initialize LuaFileCodeModel from Chunk /// </summary> /// <param name="chunk">Lua Chunk from the parser.</param> private void InitializeFileCodeModel(Chunk chunk) { var DTE = GetService(typeof(DTE)) as DTE2; if(DTE == null) throw new InvalidOperationException("DTE is not available!"); var codeModel = DTE.ActiveDocument.ProjectItem.FileCodeModel as LuaFileCodeModel; if (codeModel != null) { try { codeModel.Initialize(chunk); NotifyOnFileCodeModelChanged(); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } } else { if(DTE.ActiveDocument.ProjectItem.FileCodeModel!=null) { string sLang = DTE.ActiveDocument.ProjectItem.FileCodeModel.Language; } } }
/// <summary> /// performs lazy initialization to ensure our current code model is up-to-date. /// /// If we haven't yet created our CodeDom backing we'll create it for the 1st time. If we've /// created our backing, but some elements have been changed that we haven't yet reparsed /// then we'll reparse & merge any of the appropriate changes. /// </summary> public void Initialize(Chunk chunkNode) { chunk = chunkNode; var translator = new ASTTranslator(DTE, this); RootElement = translator.Translate(chunkNode); modelInitialized = true; }
/// <summary> /// Translates Chunk node to LuaCodeClass with random name. /// </summary> /// <param name="chunk">Instance of Chunk.</param> /// <returns></returns> public LuaCodeClass Translate(Chunk chunk) { return Translate(chunk, String.Concat("LuaCodeClass::", Guid.NewGuid())); }