Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/script_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ ParseResult ScriptParser::parse(const QVector<TokenLine> &tokenLines) {
continue;
}

// LABEL must be at top level (labels are resolved against root->children only)
if (first == TokenType::LABEL && !blockStack.isEmpty()) {
error(line, "LABEL must be at the top level (not inside IF/WHILE/REPEAT/DEF)");
continue;
}

// Parse the line into an AST node
auto node = parseLine(tl);
if (!node) continue;
Expand Down
17 changes: 17 additions & 0 deletions tests/test_script_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class TestScriptParser : public QObject {
void testFunctionReturn();
void testNestedDefError();
void testDefInsideBlockError();
void testLabelInsideBlockError();
void testCallUndefinedFunction();
void testCallWrongArgCount();
void testDuplicateFunction();
Expand Down Expand Up @@ -682,6 +683,22 @@ void TestScriptParser::testDefInsideBlockError() {
QVERIFY(found);
}

void TestScriptParser::testLabelInsideBlockError() {
auto result = m_parser->parse(
"IF $X == \"1\"\n"
" LABEL inside\n"
"ENDIF\n"
"GOTO inside\n"
);
QVERIFY(result.hasErrors());
bool foundLabelError = false;
for (const auto &e : result.errors) {
if (e.line == 2 && e.message.contains("LABEL must be at the top level"))
foundLabelError = true;
}
QVERIFY(foundLabelError);
}

void TestScriptParser::testCallUndefinedFunction() {
auto result = m_parser->parse("CALL nonexistent()");
QVERIFY(result.hasErrors());
Expand Down