Skip to content

Commit 047bbc1

Browse files
committed
Add support for parsing empty statements
1 parent b572f04 commit 047bbc1

File tree

9 files changed

+85
-3
lines changed

9 files changed

+85
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Add a formatter option for space around commas in return lists.
77
- Add a formatter option for space within return list parenthesis.
88
- Add error recovery for statements.
9+
- Add support for parsing empty statements.
910

1011
### Changed
1112
- The build window will now display internal compiler errors as well.

src/main/gen/io/runescript/plugin/lang/parser/RsParser.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ static boolean parse_root_(IElementType t, PsiBuilder b, int l) {
4343
}
4444

4545
public static final TokenSet[] EXTENDS_SETS_ = new TokenSet[] {
46-
create_token_set_(ARRAY_VARIABLE_DECLARATION_STATEMENT, ASSIGNMENT_STATEMENT, BLOCK_STATEMENT, EXPRESSION_STATEMENT,
47-
IF_STATEMENT, LOCAL_VARIABLE_DECLARATION_STATEMENT, RETURN_STATEMENT, STATEMENT,
48-
SWITCH_STATEMENT, WHILE_STATEMENT),
46+
create_token_set_(ARRAY_VARIABLE_DECLARATION_STATEMENT, ASSIGNMENT_STATEMENT, BLOCK_STATEMENT, EMPTY_STATEMENT,
47+
EXPRESSION_STATEMENT, IF_STATEMENT, LOCAL_VARIABLE_DECLARATION_STATEMENT, RETURN_STATEMENT,
48+
STATEMENT, SWITCH_STATEMENT, WHILE_STATEMENT),
4949
create_token_set_(ARITHMETIC_EXPRESSION, ARITHMETIC_VALUE_EXPRESSION, ARRAY_ACCESS_EXPRESSION, BOOLEAN_LITERAL_EXPRESSION,
5050
CALC_EXPRESSION, COMMAND_EXPRESSION, CONDITION_EXPRESSION, CONSTANT_EXPRESSION,
5151
COORD_LITERAL_EXPRESSION, DYNAMIC_EXPRESSION, EXPRESSION, GOSUB_EXPRESSION,
@@ -536,6 +536,18 @@ public static boolean DynamicExpression(PsiBuilder b, int l) {
536536
return r;
537537
}
538538

539+
/* ********************************************************** */
540+
// ';'
541+
public static boolean EmptyStatement(PsiBuilder b, int l) {
542+
if (!recursion_guard_(b, l, "EmptyStatement")) return false;
543+
if (!nextTokenIs(b, "<Statement>", SEMICOLON)) return false;
544+
boolean r;
545+
Marker m = enter_section_(b, l, _NONE_, EMPTY_STATEMENT, "<Statement>");
546+
r = consumeToken(b, SEMICOLON);
547+
exit_section_(b, l, m, r, false, null);
548+
return r;
549+
}
550+
539551
/* ********************************************************** */
540552
// ParExpression
541553
// | ArrayAccessExpression
@@ -1253,6 +1265,7 @@ private static boolean Script_6(PsiBuilder b, int l) {
12531265
// | LocalVariableDeclarationStatement
12541266
// | AssignmentStatement
12551267
// | ExpressionStatement
1268+
// | EmptyStatement
12561269
public static boolean Statement(PsiBuilder b, int l) {
12571270
if (!recursion_guard_(b, l, "Statement")) return false;
12581271
boolean r;
@@ -1266,6 +1279,7 @@ public static boolean Statement(PsiBuilder b, int l) {
12661279
if (!r) r = LocalVariableDeclarationStatement(b, l + 1);
12671280
if (!r) r = AssignmentStatement(b, l + 1);
12681281
if (!r) r = ExpressionStatement(b, l + 1);
1282+
if (!r) r = EmptyStatement(b, l + 1);
12691283
exit_section_(b, l, m, r, false, null);
12701284
return r;
12711285
}

src/main/gen/io/runescript/plugin/lang/psi/RsElementTypes.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public interface RsElementTypes {
2525
IElementType CONSTANT_EXPRESSION = new RsElementType("CONSTANT_EXPRESSION");
2626
IElementType COORD_LITERAL_EXPRESSION = new RsElementType("COORD_LITERAL_EXPRESSION");
2727
IElementType DYNAMIC_EXPRESSION = new RsElementType("DYNAMIC_EXPRESSION");
28+
IElementType EMPTY_STATEMENT = new RsElementType("EMPTY_STATEMENT");
2829
IElementType EXPRESSION = new RsElementType("EXPRESSION");
2930
IElementType EXPRESSION_STATEMENT = new RsElementType("EXPRESSION_STATEMENT");
3031
IElementType GOSUB_EXPRESSION = new RsElementType("GOSUB_EXPRESSION");
@@ -156,6 +157,9 @@ else if (type == COORD_LITERAL_EXPRESSION) {
156157
else if (type == DYNAMIC_EXPRESSION) {
157158
return new RsDynamicExpressionImpl(node);
158159
}
160+
else if (type == EMPTY_STATEMENT) {
161+
return new RsEmptyStatementImpl(node);
162+
}
159163
else if (type == EXPRESSION_STATEMENT) {
160164
return new RsExpressionStatementImpl(node);
161165
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This class is automatically generated. Do not edit.
2+
package io.runescript.plugin.lang.psi;
3+
4+
import java.util.List;
5+
import org.jetbrains.annotations.*;
6+
import com.intellij.psi.PsiElement;
7+
8+
public interface RsEmptyStatement extends RsStatement {
9+
10+
@NotNull
11+
PsiElement getSemicolon();
12+
13+
}

src/main/gen/io/runescript/plugin/lang/psi/RsVisitor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public void visitDynamicExpression(@NotNull RsDynamicExpression o) {
7979
// visitNamedElement(o);
8080
}
8181

82+
public void visitEmptyStatement(@NotNull RsEmptyStatement o) {
83+
visitStatement(o);
84+
}
85+
8286
public void visitExpression(@NotNull RsExpression o) {
8387
visitPsiElement(o);
8488
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This class is automatically generated. Do not edit.
2+
package io.runescript.plugin.lang.psi.impl;
3+
4+
import java.util.List;
5+
import org.jetbrains.annotations.*;
6+
import com.intellij.lang.ASTNode;
7+
import com.intellij.psi.PsiElement;
8+
import com.intellij.psi.PsiElementVisitor;
9+
import com.intellij.psi.util.PsiTreeUtil;
10+
import static io.runescript.plugin.lang.psi.RsElementTypes.*;
11+
import io.runescript.plugin.lang.psi.*;
12+
13+
public class RsEmptyStatementImpl extends RsStatementImpl implements RsEmptyStatement {
14+
15+
public RsEmptyStatementImpl(@NotNull ASTNode node) {
16+
super(node);
17+
}
18+
19+
@Override
20+
public void accept(@NotNull RsVisitor visitor) {
21+
visitor.visitEmptyStatement(this);
22+
}
23+
24+
@Override
25+
public void accept(@NotNull PsiElementVisitor visitor) {
26+
if (visitor instanceof RsVisitor) accept((RsVisitor)visitor);
27+
else super.accept(visitor);
28+
}
29+
30+
@Override
31+
@NotNull
32+
public PsiElement getSemicolon() {
33+
return notNullChild(findChildByType(SEMICOLON));
34+
}
35+
36+
}

src/main/grammars/RuneScript.bnf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Statement ::= BlockStatement
9595
| LocalVariableDeclarationStatement
9696
| AssignmentStatement
9797
| ExpressionStatement
98+
| EmptyStatement
9899

99100
BlockStatement ::= '{' StatementList '}'
100101
IfStatement ::= IF '(' LogicalOrWrapper ')' Statement (ELSE Statement)? {
@@ -137,6 +138,7 @@ private AssignableExpression ::= ArrayAccessExpression | LocalVariableExpression
137138
ExpressionStatement ::= Expression ';' {
138139
pin=1
139140
}
141+
EmptyStatement ::= ';'
140142

141143
// Arithmetic & Bitwise Expressions
142144

src/main/kotlin/io/runescript/plugin/ide/codeInsight/controlFlow/RsControlFlowBuilder.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ class RsControlFlowBuilder : ControlFlowBuilder() {
147147
addInstruction(o)
148148
}
149149

150+
override fun visitEmptyStatement(o: RsEmptyStatement) {
151+
addInstruction(o)
152+
}
153+
150154
override fun visitIfStatement(o: RsIfStatement) {
151155
// ------------------------
152156
// Case 1:false statement is not present

src/main/kotlin/io/runescript/plugin/lang/psi/type/inference/RsTypeInferenceVisitor.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ class RsTypeInferenceVisitor(private val myInferenceData: RsTypeInference) : RsV
369369
o.expression.accept(this)
370370
}
371371

372+
override fun visitEmptyStatement(o: RsEmptyStatement) {
373+
// Do nothing.
374+
}
375+
372376
override fun visitSwitchStatement(o: RsSwitchStatement) {
373377
val type = RsPrimitiveType.lookupReferencable(o.switch.text.substring("switch_".length))
374378
val expression = o.expression

0 commit comments

Comments
 (0)