Exemple #1
0
        // Well, this is not a namespace creator, instead this will import everything from another file
        public override GamaNamespace VisitImportStmt([NotNull] GamaParser.ImportStmtContext context)
        {
            var file = context.StringLiteral().GetText().Trim('"');

            if (GlobalContext.ImportedFiles.Contains(file))
            {
                return(null); // just skip already included files, this is dumb, fix later: TODO:
            }
            if (!file.EndsWith(".gm"))
            {
                file += ".gm";
            }
            if (!File.Exists(file))
            {
                file = "./include/" + file; // TODO: might need fixing to app path
                if (!File.Exists(file))
                {
                    Console.WriteLine("Imported file not found: '{0}'", file);
                    // GlobalContext.AddError(new ErrorImportFileNotFound(file));
                    return(null);
                }
            }

            GlobalContext.ImportedFiles.Add(file);

            var input   = new AntlrInputStream(File.ReadAllText(file));
            var lexer   = new GamaLexer(input);
            var tokens  = new CommonTokenStream(lexer);
            var parser  = new GamaParser(tokens);
            var program = parser.program();

            if (parser.NumberOfSyntaxErrors > 0)
            {
                Console.WriteLine("Imported file contains syntax errors, aborting compilation.");
                return(null);
            }
            var unit = new GamaNamespaceCompiler(GlobalContext);

            unit.Visit(program);

            return(null);
        }
Exemple #2
0
 /// <summary>
 /// Visit a parse tree produced by the <c>ImportStmt</c>
 /// labeled alternative in <see cref="GamaParser.namespace"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitImportStmt([NotNull] GamaParser.ImportStmtContext context)
 {
     return(VisitChildren(context));
 }
Exemple #3
0
 /// <summary>
 /// Exit a parse tree produced by the <c>ImportStmt</c>
 /// labeled alternative in <see cref="GamaParser.namespace"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitImportStmt([NotNull] GamaParser.ImportStmtContext context)
 {
 }