Skip to content

Commit 8d9bdbc

Browse files
committed
ast: Add errors on undefined parser behavior
1 parent 5793c72 commit 8d9bdbc

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/main/java/org/piccode/ast/PiccodeVisitor.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,23 @@ public Ast visitDeclaration(DeclarationContext ctx) {
150150
var func = (FunctionAst) visitFunc(ctx.func());
151151
func.name = id;
152152
return func;
153+
}
154+
155+
if (ctx.module() != null) {
156+
var mod = (ModuleAst) visitModule(ctx.module());
157+
mod.name = id;
158+
return mod;
159+
}
160+
161+
if (ctx.import_module() != null) {
162+
var tok = ctx.import_module().getStart();
163+
var mod = (ImportAst) visitImport_module(ctx.import_module());
164+
var result = new ImportModuleCreateAst(id, mod);
165+
return finalizeAstNode(result, tok);
153166
}
154167

155-
var mod = (ModuleAst) visitModule(ctx.module());
156-
mod.name = id;
157-
return mod;
168+
var tok = ctx.getStart();
169+
throw new PiccodeException(fileName, tok.getLine(), tok.getCharPositionInLine(), "Invalid declaration node");
158170
}
159171

160172
@Override

0 commit comments

Comments
 (0)