while-continue with labels and docs/tests
This commit is contained in:
1 parent
22fbd5584b
commit
ebeed385e9
2 files changed
+85
-28
No files matched your search
@@ -305,6 +305,7 @@ class Compiler {
|
||||
"var" -> parseVarDeclaration(id.value, true, cc)
|
||||
"while" -> parseWhileStatement(cc)
|
||||
"break" -> parseBreakStatement(id.pos, cc)
|
||||
"continue" -> parseContinueStatement(id.pos, cc)
|
||||
"fn", "fun" -> parseFunctionDeclaration(cc)
|
||||
"if" -> parseIfStatement(cc)
|
||||
else -> null
|
||||
@@ -388,6 +389,27 @@ class Compiler {
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseContinueStatement(start: Pos, cc: CompilerContext): Statement {
|
||||
val t = cc.next()
|
||||
|
||||
val label = if (t.pos.line != start.line || t.type != Token.Type.ATLABEL) {
|
||||
cc.previous()
|
||||
null
|
||||
} else {
|
||||
t.value
|
||||
}?.also {
|
||||
// check that label is defined
|
||||
cc.ensureLabelIsValid(start, it)
|
||||
}
|
||||
|
||||
return statement(start) {
|
||||
throw LoopBreakContinueException(
|
||||
doContinue = true,
|
||||
label = label,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun ensureRparen(tokens: CompilerContext): Pos {
|
||||
val t = tokens.next()
|
||||
if (t.type != Token.Type.RPAREN)
|
||||
|
||||
Reference in new issue
Block a user