Implemented issue: #87

This commit is contained in:
UnlegitDqrk
2026-03-02 13:10:29 +01:00
parent 98437da1fa
commit db392c4763
219 changed files with 73 additions and 15 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -76,6 +76,7 @@ public class LuaParser implements LuaParserConstants {
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case BREAK:
case CONTINUE:
case DO:
case FOR:
case FUNCTION:
@@ -133,6 +134,10 @@ public class LuaParser implements LuaParserConstants {
jj_consume_token(BREAK);
s=Stat.breakstat(); L(s,i); {if (true) return s;}
break;
case CONTINUE:
jj_consume_token(CONTINUE);
s=Stat.gotostat("continue"); L(s,i); {if (true) return s;}
break;
case GOTO:
jj_consume_token(GOTO);
n = jj_consume_token(NAME);

View File

@@ -124,6 +124,8 @@ public interface LuaParserConstants {
int SHL = 98;
/** RegularExpression Id. */
int SHR = 99;
/** Synthetic token for identifier keyword remapping. */
int CONTINUE = 100;
/** Lexical state. */
int DEFAULT = 0;
@@ -252,6 +254,7 @@ public interface LuaParserConstants {
"\"|\"",
"\"<<\"",
"\">>\"",
"\"continue\"",
};
}

View File

@@ -524,6 +524,8 @@ private int jjMoveStringLiteralDfa0_0()
return jjMoveStringLiteralDfa1_0(0x4000000000000L, 0x0L);
case 123:
return jjStopAtPos(0, 80);
case 124:
return jjStopAtPos(0, 97);
case 125:
return jjStopAtPos(0, 81);
case 126:
@@ -1866,6 +1868,8 @@ protected Token jjFillToken()
t.endLine = endLine;
t.beginColumn = beginColumn;
t.endColumn = endColumn;
if (t.kind == NAME && "continue".equals(t.image))
t.kind = CONTINUE;
return t;
}
@@ -2114,7 +2118,4 @@ private void jjCheckNAddStates(int start, int end)
jjCheckNAdd(jjnextStates[start]);
} while (start++ != end);
}
}
case 124:
return jjStopAtPos(0, 97);

Binary file not shown.

View File

@@ -117,6 +117,29 @@ public class FragmentsTest extends TestSuite {
runFragment(LuaValue.TRUE, "local x=5 local width=10 return x==width//2\n");
}
public void testContinueInLoops() {
runFragment(
LuaValue.valueOf(229),
"local sum = 0\n" +
"for i = 1, 5 do\n" +
" if i % 2 == 0 then continue end\n" +
" sum = sum + i\n" +
"end\n" +
"local j = 0\n" +
"while j < 4 do\n" +
" j = j + 1\n" +
" if j < 3 then continue end\n" +
" sum = sum + 10\n" +
"end\n" +
"local k = 0\n" +
"repeat\n" +
" k = k + 1\n" +
" if k < 3 then continue end\n" +
" sum = sum + 100\n" +
"until k >= 4\n" +
"return sum\n");
}
public void testLongIntegerLiteralPrecision() {
runFragment(
LuaValue.varargsOf(new LuaValue[] {

View File

@@ -7,6 +7,7 @@ import org.luaj.vm2.parser.LuaParser;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
public class LuaParserTests extends CompilerUnitTests {
@@ -26,4 +27,14 @@ public class LuaParserTests extends CompilerUnitTests {
e.printStackTrace();
}
}
public void testContinueParses() {
try {
Reader r = new StringReader("while true do continue end");
LuaParser parser = new LuaParser(r);
parser.Chunk();
} catch (Exception e) {
fail(e.getMessage());
}
}
}