Skip to content

Commit 039bae2

Browse files
committed
support continue and more lua fixes!
1 parent ed61749 commit 039bae2

20 files changed

Lines changed: 573 additions & 29 deletions

File tree

de.peeeq.wurstscript/parserspec/wurstscript.parseq

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ ControlflowStatement =
147147
CompoundStatement
148148
| StmtReturn(@ignoreForEquality de.peeeq.wurstscript.parser.WPos source, OptExpr returnedObj)
149149
| StmtExitwhen(@ignoreForEquality de.peeeq.wurstscript.parser.WPos source, Expr cond)
150+
| StmtContinue(de.peeeq.wurstscript.parser.WPos source)
150151

151152
CompoundStatement =
152153
StmtIf(@ignoreForEquality de.peeeq.wurstscript.parser.WPos source, Expr cond, WStatements thenBlock, WStatements elseBlock, boolean hasElse)
@@ -1073,4 +1074,4 @@ Annotation.getAnnotationType()
10731074

10741075
Annotation.getAnnotationMessage()
10751076
returns String
1076-
implemented by de.peeeq.wurstscript.attributes.Annotations.annotationMessage
1077+
implemented by de.peeeq.wurstscript.attributes.Annotations.annotationMessage

de.peeeq.wurstscript/src/main/antlr/de/peeeq/wurstscript/antlr/Wurst.g4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ statement:
260260
| stmtSet (externalLambda|NL)
261261
| stmtReturn (externalLambda|NL)
262262
| stmtBreak NL
263+
| stmtContinue NL
263264
| stmtSkip NL
264265
| expr (externalLambda|NL)
265266
| stmtIf
@@ -435,6 +436,7 @@ forIteratorLoop:
435436

436437

437438
stmtBreak:'break';
439+
stmtContinue:'continue';
438440
stmtSkip:'skip';
439441

440442

@@ -461,6 +463,7 @@ WHILE: 'while';
461463
FOR: 'for';
462464
IN: 'in';
463465
BREAK: 'break';
466+
CONTINUE: 'continue';
464467
NEW: 'new';
465468
NULL: 'null';
466469
PACKAGE: 'package';

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/HoverInfo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,11 @@ public List<Either<String, MarkedString>> case_StmtExitwhen(StmtExitwhen stmtExi
422422
return string("exitwhen: exits the current loop when the condition is true.");
423423
}
424424

425+
@Override
426+
public List<Either<String, MarkedString>> case_StmtContinue(StmtContinue stmtContinue) {
427+
return string("continue: skips the rest of the current loop iteration.");
428+
}
429+
425430
@Override
426431
public List<Either<String, MarkedString>> case_ConstructorDef(ConstructorDef constr) {
427432
return description(constr);

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import de.peeeq.wurstscript.jassprinter.JassPrinter;
2828
import de.peeeq.wurstscript.luaAst.LuaCompilationUnit;
2929
import de.peeeq.wurstscript.parser.WPos;
30+
import de.peeeq.wurstscript.translation.lua.translation.LuaTranslator;
3031
import de.peeeq.wurstscript.utils.LineOffsets;
3132
import de.peeeq.wurstscript.utils.Utils;
3233
import net.moonlightflower.wc3libs.bin.app.W3I;
@@ -167,6 +168,7 @@ protected File compileMap(File projectFolder, WurstGui gui, Optional<File> mapCo
167168
luaCode.get().print(sb, 0);
168169

169170
String compiledMapScript = sb.toString();
171+
LuaTranslator.assertNoLeakedHashtableNativeCalls(compiledMapScript);
170172
File buildDir = getBuildDir();
171173
File outFile = new File(buildDir, BUILD_COMPILED_LUA_NAME);
172174
Files.write(compiledMapScript.getBytes(Charsets.UTF_8), outFile);

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/WurstKeywords.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package de.peeeq.wurstscript;
22

33
public class WurstKeywords {
4-
public static final String[] KEYWORDS = new String[]{"class", "return", "if", "else", "while", "for", "in", "break", "new", "null",
4+
public static final String[] KEYWORDS = new String[]{"class", "return", "if", "else", "while", "for", "in", "break", "continue", "new", "null",
55
"package", "endpackage", "function", "returns", "public", "private", "protected", "import", "initlater", "native", "nativetype", "extends",
66
"interface", "implements", "module", "use", "abstract", "static", "thistype", "override", "immutable", "it", "array", "and",
77
"or", "not", "this", "construct", "ondestroy", "destroy", "type", "constant", "endfunction", "nothing", "init", "castTo",

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/attributes/DescriptionHtml.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ public static String description(StmtSkip stmtSkip) {
326326
return "The skip statement does nothing. Just skip this line.";
327327
}
328328

329+
public static String description(StmtContinue stmtContinue) {
330+
return "continue: Skips the rest of the current loop iteration.";
331+
}
332+
329333
public static String description(StmtWhile stmtWhile) {
330334
return "While Statement: Repeat while the condition is true.";
331335
}

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/attributes/Flow.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ public static List<WStatement> getNext(StmtExitwhen s) {
5959
return next;
6060
}
6161

62+
public static List<WStatement> getNext(StmtContinue s) {
63+
LoopStatement loop = getParentLoopStatement(s);
64+
if (loop == null) {
65+
s.addError("Continue statements must be used inside a loop.");
66+
return Collections.emptyList();
67+
}
68+
List<WStatement> next = loop.attrAfterBodyStatements();
69+
setPrevios(s, next);
70+
return next;
71+
}
72+
6273
private static boolean isConstantBool(Expr cond, boolean value) {
6374
return cond instanceof ExprBoolVal && ((ExprBoolVal) cond).getValB() == value;
6475
}

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/attributes/InitOrder.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import de.peeeq.wurstscript.ast.WImport;
88
import de.peeeq.wurstscript.ast.WImports;
99
import de.peeeq.wurstscript.ast.WPackage;
10+
import de.peeeq.wurstscript.ast.WurstModel;
1011

1112
import java.util.*;
1213

@@ -19,7 +20,8 @@ public static ImmutableList<WPackage> initDependencies(WPackage p) {
1920
packages.addAll(p.attrImportedPackagesTransitive());
2021

2122
// add config package if it exists:
22-
WPackage configPackage = p.getModel().attrConfigOverridePackages().get(p);
23+
WurstModel model = safeModel(p);
24+
WPackage configPackage = model == null ? null : model.attrConfigOverridePackages().get(p);
2325
if (configPackage != null) {
2426
packages.add(configPackage);
2527
}
@@ -70,8 +72,11 @@ private static String getCyclicDependencyString(List<WPackage> callStack, WPacka
7072
StringBuilder msg = new StringBuilder();
7173
Map<WPackage, WPackage> configuredPackage = new HashMap<>();
7274
if (considerConfig) {
73-
for (WPackage configured : imported.getModel().attrConfigOverridePackages().keySet()) {
74-
configuredPackage.put(imported.getModel().attrConfigOverridePackages().get(configured), configured);
75+
WurstModel model = safeModel(imported);
76+
if (model != null) {
77+
for (WPackage configured : model.attrConfigOverridePackages().keySet()) {
78+
configuredPackage.put(model.attrConfigOverridePackages().get(configured), configured);
79+
}
7580
}
7681
}
7782
for (WPackage p : callStack) {
@@ -152,7 +157,8 @@ private static void addCollectImportedPackage(List<WPackage> callStack, WPackage
152157
// add imports of configured package to config package
153158
// that way cyclic dependencies are checked for the config package and errors will be reported for the config package
154159
if (considerConfig) {
155-
WPackage configPackage = p.getModel().attrConfigOverridePackages().get(imported);
160+
WurstModel model = safeModel(p);
161+
WPackage configPackage = model == null ? null : model.attrConfigOverridePackages().get(imported);
156162
if (configPackage != null && configPackage != p) {
157163
if (configPackage == callStack.get(0)) {
158164
reportCyclicDependency(callStack, configPackage, reportedErrors, useWarnings);
@@ -168,6 +174,10 @@ private static void addCollectImportedPackage(List<WPackage> callStack, WPackage
168174
}
169175

170176
private static void collectImportedPackages(List<WPackage> callStack, WPackage p, Collection<WPackage> result, Set<String> reportedErrors, boolean considerConfig, boolean useWarnings) {
177+
if (safeModel(p) == null) {
178+
// Detached packages can occur transiently in language-server workflows; ignore them for init-order analysis.
179+
return;
180+
}
171181
callStack.add(p);
172182
addCollectImportedPackage(callStack, p, result, p.getImports(), reportedErrors, considerConfig, useWarnings);
173183
/*
@@ -178,7 +188,8 @@ private static void collectImportedPackages(List<WPackage> callStack, WPackage p
178188
even though the configured package will be initialized after the config package.
179189
*/
180190
if (considerConfig) {
181-
for (Map.Entry<WPackage, WPackage> e : p.getModel().attrConfigOverridePackages().entrySet()) {
191+
WurstModel model = safeModel(p);
192+
if (model != null) for (Map.Entry<WPackage, WPackage> e : model.attrConfigOverridePackages().entrySet()) {
182193
if (e.getValue().equals(p)) {
183194
addCollectImportedPackage(callStack, e.getKey(), result, e.getKey().getImports(), reportedErrors, considerConfig, useWarnings);
184195
}
@@ -187,4 +198,12 @@ private static void collectImportedPackages(List<WPackage> callStack, WPackage p
187198
callStack.remove(callStack.size() - 1);
188199
}
189200

201+
private static WurstModel safeModel(WPackage p) {
202+
try {
203+
return p.getModel();
204+
} catch (Error ignored) {
205+
return null;
206+
}
207+
}
208+
190209
}

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/attributes/prettyPrint/PrettyPrinter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,12 @@ public static void prettyPrint(StmtSkip e, Spacer spacer, StringBuilder sb, int
11461146
sb.append("\n");
11471147
}
11481148

1149+
public static void prettyPrint(StmtContinue e, Spacer spacer, StringBuilder sb, int indent) {
1150+
printIndent(sb, indent);
1151+
sb.append("continue");
1152+
sb.append("\n");
1153+
}
1154+
11491155
public static void prettyPrint(StmtWhile e, Spacer spacer, StringBuilder sb, int indent) {
11501156
printIndent(sb, indent);
11511157
sb.append("while");

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/parser/antlr/AntlrWurstParseTreeTransformer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ private WStatement transformStatement2(StatementContext s) {
747747
} else if (s.stmtBreak() != null) {
748748
return Ast
749749
.StmtExitwhen(source(s), Ast.ExprBoolVal(source(s), true));
750+
} else if (s.stmtContinue() != null) {
751+
return Ast.StmtContinue(source(s));
750752
} else if (s.stmtSkip() != null) {
751753
return Ast.StmtSkip(source(s));
752754
} else if (s.stmtSwitch() != null) {

0 commit comments

Comments
 (0)