Example #1
0
        /// <summary>
        /// Returns the syntax tree for <paramref name="path" />. May find and/or create a
        /// cached copy in the mem cache or the disk cache.
        /// 
        /// <param name="path">Absolute path to a source file.</param>
        /// <returns>The AST, or <code>null</code> if the parse failed for any reason</returns>
        /// </summary>
        public Module getAST(string path)
        {
            // Cache stores null value if the parse failed.
            Module module;
            if (cache.TryGetValue(path, out module))
            {
                return module;
            }

            // Might be cached on disk but not in memory.
            module = GetSerializedModule(path);
            if (module != null)
            {
                LOG.Verbose("Reusing " + path);
                cache[path] = module;
                return module;
            }

            module = null;
            try
            {
                LOG.Verbose("parsing " + path);
                var lexer = new Lexer(path, fs.CreateStreamReader(path));
                var parser = new Parser(path, lexer);
                var moduleStmts = parser.Parse().ToList();
                int posStart = 0;
                int posEnd = 0;
                if (moduleStmts.Count > 0)
                {
                    posStart = moduleStmts[0].Start;
                    posEnd = moduleStmts.Last().End;
                }
                module = new Module(
                    analyzer.ModuleName(path),
                    new SuiteStatement(moduleStmts, path, posStart, posEnd),
                    path, posStart, posEnd);
            }
            finally
            {
                cache[path] = module;  // may be null
            }
            return module;
        }
Example #2
0
 public Binding Insert(Analyzer analyzer, string id, Module node, DataType type, BindingKind kind)
 {
     Binding b = analyzer.CreateBinding(id, node, type, kind);
     if (type is ModuleType)
     {
         b.qname = type.asModuleType().qname;
     }
     else
     {
         b.qname = analyzer.ExtendPath(this.Path, id);
     }
     Update(id, b);
     return b;
 }