Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,24 @@ public EndOfStatementResult consumeEndOfStatement() throws AnalysisException {
state = InlineProcessorState.EXPECTING_ELSE_CLAUSE;
return EndOfStatementResult.CONSUMED;
}
final var nextElement = ctx.lexicalAnalyzer.peek();

// handle multiple statements separated with colon
if(nextElement!=null && nextElement.getLexeme().equals(":")) {
ctx.lexicalAnalyzer.get();
return EndOfStatementResult.CONSUMED;
}

if (!nextElement.isLineTerminator() && !nextElement.getLexeme().equals("'")
&& state == InlineProcessorState.EXPECTING_THEN_CLAUSE) {
// only else statement is allowed
if(nextElement.isSymbol(ScriptBasicKeyWords.KEYWORD_ELSE)) {
state = InlineProcessorState.EXPECTING_ELSE;
final var nextElement = ctx.lexicalAnalyzer.peek();
if(nextElement!=null) {
// handle multiple statements separated with colon
if(nextElement.getLexeme().equals(":")) {
ctx.lexicalAnalyzer.get();
return EndOfStatementResult.CONSUMED;
}
throw new BasicSyntaxException("Unexpexted element: "+nextElement.getLexeme());
}

if (!nextElement.isLineTerminator() && !nextElement.getLexeme().equals("'")
&& state == InlineProcessorState.EXPECTING_THEN_CLAUSE) {
// only else statement is allowed
if (nextElement.isSymbol(ScriptBasicKeyWords.KEYWORD_ELSE)) {
state = InlineProcessorState.EXPECTING_ELSE;
return EndOfStatementResult.CONSUMED;
}
throw new BasicSyntaxException("Unexpexted element: " + nextElement.getLexeme());
}
}

state = InlineProcessorState.CLAUSE_DEFINED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void testPrograms() throws Exception {
codeTest("TestIf2.bas", "12568");
codeTest("TestIf3.bas", "12456");
codeTest("TestIf4.bas", "135910");
codeTest("TestIf5.bas", "1");
testSyntaxFail("TestIncorrectIf1.bas");
testSyntaxFail("TestIncorrectIf2.bas");
testSyntaxFail("TestIncorrectIf3.bas");
Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/com/scriptbasic/testprograms/TestIf5.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'
' This program is used in unit testing the jScriptBasic interpreter to test the functionality of the
' single line if-then-else
'
if true then print "1"