diff --git a/src/vtlengine/AST/ASTConstructor.py b/src/vtlengine/AST/ASTConstructor.py index 4954cad1..994661b1 100644 --- a/src/vtlengine/AST/ASTConstructor.py +++ b/src/vtlengine/AST/ASTConstructor.py @@ -65,7 +65,10 @@ def visitStart(self, ctx: Parser.StartContext): for statement in statements: statements_nodes.append(self.visitStatement(statement)) - token_info = extract_token_info(ctx) + if ctx.stop is None: + token_info = {"column_start": 0, "column_stop": 0, "line_start": 1, "line_stop": 1} + else: + token_info = extract_token_info(ctx) start_node = Start(children=statements_nodes, **token_info) diff --git a/tests/AST/test_AST.py b/tests/AST/test_AST.py index bf49fd12..e5d83bd3 100644 --- a/tests/AST/test_AST.py +++ b/tests/AST/test_AST.py @@ -948,3 +948,26 @@ def test_rule_name_not_in_ruleset(): """ ast = create_ast(text=script) assert len(ast.children) == 1 + + +empty_script_params = [ + "", + "//Comment", + "/*Comment*/", +] + + +@pytest.mark.parametrize("script", empty_script_params) +def test_create_ast_empty_script(script): + ast = create_ast(text=script) + assert isinstance(ast, Start) + assert ast.children == [] + + +@pytest.mark.parametrize("script", empty_script_params) +def test_create_ast_with_comments_empty_script(script): + from vtlengine.AST import Comment + + ast = create_ast_with_comments(text=script) + assert isinstance(ast, Start) + assert all(isinstance(child, Comment) for child in ast.children)