Example #1
0
 public void GetDeclarations(LuaBlockNode block, LuaModel model)
 {
     // require("sample.lua")
     if (Target != null &&
         (Target.AsString == "require" ||
          Target.AsString == "NPL.load") &&
         Arguments.ChildNodes.Count == 1 &&
         Arguments.ChildNodes[0] is LuaLiteralNode &&
         ((LuaLiteralNode)Arguments.ChildNodes[0]).Type == LuaType.String)
     {
         string fileName = ((LuaLiteralNode)Arguments.ChildNodes[0]).Value;
         fileName = fileName.Substring(1, fileName.Length - 2);
         try
         {
             string filePath = Path.Combine(Path.GetDirectoryName(model.FilePath), fileName);
             // project mode
             if (model.Entry != null && model.Entry.Analyzer != null && model.Entry.Analyzer.ContainsFile(filePath))
             {
                 AnalysisEntry requiredEntry = model.Entry.Analyzer.GetAnalysisEntry(filePath);
                 if (requiredEntry.Model != null)
                 {
                     block.Requires.AddRange(requiredEntry.Model.GetGlobalDeclarations());
                     model.AddIncludedFile(filePath, requiredEntry.Model);
                 }
             }
             // singleton mode
             else
             {
                 string source = File.ReadAllText(filePath);
                 Irony.Parsing.Parser parser        = new Irony.Parsing.Parser(LuaGrammar.Instance);
                 ParseTree            tree          = parser.Parse(source);
                 LuaModel             requiredModel = new LuaModel(tree, filePath);
                 block.Requires.AddRange(requiredModel.GetGlobalDeclarations());
                 model.AddIncludedFile(filePath, requiredModel);
             }
         }
         catch (Exception e)
         {
         }
     }
 }