From 85b227278e813128eda4b9d67368045c2f3c4961 Mon Sep 17 00:00:00 2001 From: Mateo Date: Mon, 16 Mar 2026 11:50:53 +0100 Subject: [PATCH 1/2] Fixed empty/only-comments AST generation --- src/vtlengine/AST/ASTConstructor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/vtlengine/AST/ASTConstructor.py b/src/vtlengine/AST/ASTConstructor.py index 4954cad1c..994661b16 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) From e1631c4ddaa82156d3a10cb9d11da1665930214e Mon Sep 17 00:00:00 2001 From: Mateo Date: Mon, 16 Mar 2026 11:51:24 +0100 Subject: [PATCH 2/2] Added related tests --- tests/AST/test_AST.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/AST/test_AST.py b/tests/AST/test_AST.py index bf49fd12e..e5d83bd31 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)