Skip to content

Commit 7f35fa6

Browse files
authored
Merge pull request #15 from PetrPytelka/consumeEndOfLine_to_consumeEndOfStatement
Rename consumeEndOfLine to consumeEndOfStatement and allow to use colon as a statement separator
2 parents 2216ab6 + f7463f8 commit 7f35fa6

27 files changed

Lines changed: 62 additions & 35 deletions

src/main/java/com/scriptbasic/interfaces/LexicalElement.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,12 @@ public interface LexicalElement extends SourceLocationBound {
7979
*/
8080
Boolean isSymbol(String lexeme);
8181

82+
/**
83+
* Return true if the lexical element is colon
84+
*
85+
* @return true if the lexical element is colon
86+
*/
87+
Boolean isStatementSeparator();
88+
8289
Boolean isLineTerminator();
8390
}

src/main/java/com/scriptbasic/lexer/BasicLexicalElement.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,10 @@ public Boolean isLineTerminator() {
179179
&& CharUtils.isNewLine(getLexeme().codePointAt(0));
180180
}
181181

182+
@Override
183+
public Boolean isStatementSeparator() {
184+
return getType() == TYPE_SYMBOL && getLexeme().length() == 1
185+
&& getLexeme().codePointAt(0) == ':';
186+
}
187+
182188
}

src/main/java/com/scriptbasic/syntax/commands/AbstractCommandAnalyzer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,16 @@ protected boolean isKeyWord(final String keyword) throws AnalysisException {
9393
}
9494

9595
/**
96-
* Checks that there are no extra characters on a program line when the line
97-
* analyzer thinks that it has finished analyzing the line. If there are
96+
* Checks that there are no extra characters when the line analyzer
97+
* expects it has finished analyzing the statement. If there are
9898
* some extra characters on the line then throws syntax error exception.
99-
* Otherwise it simply steps the lexical analyzer iterator over the EOL
100-
* symbol.
99+
* Otherwise it simply steps the lexical analyzer iterator over the symbol.
101100
*
102101
* @throws AnalysisException when there are extra character on the actual line
103102
*/
104-
protected void consumeEndOfLine() throws AnalysisException {
103+
protected void consumeEndOfStatement() throws AnalysisException {
105104
final var le = ctx.lexicalAnalyzer.get();
106-
if (le != null && !le.isLineTerminator()) {
105+
if (le != null && !(le.isLineTerminator() || le.isStatementSeparator())) {
107106
SyntaxExceptionUtility.throwSyntaxException(
108107
"There are extra characters following the expression after the '"
109108
+ getName() + "' keyword", le);

src/main/java/com/scriptbasic/syntax/commands/AbstractCommandAnalyzerGlobalLocal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Command analyze() throws AnalysisException {
2727
final var node = newNode();
2828
final var list = analyzeSimpleLeftValueList();
2929
node.setLeftValueList(list);
30-
consumeEndOfLine();
30+
consumeEndOfStatement();
3131
return node;
3232
}
3333

src/main/java/com/scriptbasic/syntax/commands/AbstractCommandAnalyzerIfKind.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Command analyze() throws AnalysisException {
3131
protected Expression analizeLine() throws AnalysisException {
3232
final var condition = analyzeExpression();
3333
assertKeyWord(ScriptBasicKeyWords.KEYWORD_THEN);
34-
consumeEndOfLine();
34+
consumeEndOfStatement();
3535
return condition;
3636
}
3737

src/main/java/com/scriptbasic/syntax/commands/CommandAnalyzerCall.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public Command analyze() throws AnalysisException {
2626
ctx.lexicalAnalyzer.resetLine();
2727
final var commandLet = new CommandLet();
2828
commandLet.setExpression(ctx.expressionAnalyzer.analyze());
29-
consumeEndOfLine();
29+
consumeEndOfStatement();
3030
return commandLet;
3131
} else {
3232
final var functionName = lv.getIdentifier();
@@ -47,7 +47,7 @@ public Command analyze() throws AnalysisException {
4747
if (needClosingParenthesis) {
4848
consumeClosingParenthesis(ctx.lexicalAnalyzer);
4949
}
50-
consumeEndOfLine();
50+
consumeEndOfStatement();
5151
return new CommandCall(functionCall);
5252
}
5353
}

src/main/java/com/scriptbasic/syntax/commands/CommandAnalyzerCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Command analyze() throws AnalysisException {
2727
} else {
2828
analyzeCaseConditions(node);
2929
}
30-
consumeEndOfLine();
30+
consumeEndOfStatement();
3131

3232
var lastSelectPart = ctx.nestedStructureHouseKeeper.pop(AbstractCommandSelectPart.class);
3333
CommandSelect commandSelect = null;

src/main/java/com/scriptbasic/syntax/commands/CommandAnalyzerDSL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private void defineDSLRule() throws AnalysisException {
8686
if (!functionNameLexicalElement.isIdentifier()) {
8787
throw new BasicSyntaxException("there should be a function name after the keyword 'call' defining a sentenceó");
8888
}
89-
consumeEndOfLine();
89+
consumeEndOfStatement();
9090
final String[] syntaxElements = sentence.split("\\s+");
9191
if (syntaxElements.length == 0) {
9292
throw new BasicSyntaxException("sentence can not be empty");

src/main/java/com/scriptbasic/syntax/commands/CommandAnalyzerElse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public CommandAnalyzerElse(final Context ctx) {
1414
@Override
1515
public Command analyze() throws AnalysisException {
1616
final var node = new CommandElse();
17-
consumeEndOfLine();
17+
consumeEndOfStatement();
1818
registerAndSwapNode(node);
1919
return node;
2020
}

src/main/java/com/scriptbasic/syntax/commands/CommandAnalyzerEnd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public Command analyze() throws AnalysisException {
2525
throw new BasicSyntaxException(
2626
"Select has to be terminated with End Select statement");
2727
}
28-
consumeEndOfLine();
28+
consumeEndOfStatement();
2929

3030
var lastSelectPart = ctx.nestedStructureHouseKeeper.pop(AbstractCommandSelectPart.class);
3131

0 commit comments

Comments
 (0)