mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Special cases for waitUntil and exitWith.
This commit is contained in:
@@ -37,6 +37,10 @@ func parseBlock() {
|
||||
parseReturn()
|
||||
} else if accept("try") {
|
||||
parseTryCatch()
|
||||
} else if accept("exitwith") {
|
||||
parseExitWith()
|
||||
} else if accept("waituntil") {
|
||||
parseWaitUntil()
|
||||
} else if accept("case") || accept("default") {
|
||||
return
|
||||
} else {
|
||||
@@ -248,6 +252,32 @@ func parseTryCatch() {
|
||||
appendOut("};", true)
|
||||
}
|
||||
|
||||
func parseExitWith() {
|
||||
expect("exitwith")
|
||||
expect("{")
|
||||
appendOut("if (true) exitWith {", true)
|
||||
parseBlock()
|
||||
expect("}")
|
||||
appendOut("};", true)
|
||||
}
|
||||
|
||||
func parseWaitUntil() {
|
||||
expect("waituntil")
|
||||
expect("(")
|
||||
appendOut("waitUntil {", false)
|
||||
parseExpression(true)
|
||||
|
||||
if accept(";") {
|
||||
next()
|
||||
appendOut(";", false)
|
||||
parseExpression(true)
|
||||
}
|
||||
|
||||
expect(")")
|
||||
expect(";")
|
||||
appendOut("};", true)
|
||||
}
|
||||
|
||||
// Everything that does not start with a keyword.
|
||||
func parseStatement() {
|
||||
// empty block
|
||||
|
||||
@@ -115,6 +115,20 @@ func TestParserNegationFunctionCall(t *testing.T) {
|
||||
equal(t, got, want)
|
||||
}
|
||||
|
||||
func TestParserExitWith(t *testing.T) {
|
||||
got := getCompiled(t, "test/parser_exitwith.asl")
|
||||
want := "if (true) exitWith {\n};\n"
|
||||
|
||||
equal(t, got, want)
|
||||
}
|
||||
|
||||
func TestParserWaitUntil(t *testing.T) {
|
||||
got := getCompiled(t, "test/parser_waituntil.asl")
|
||||
want := "waitUntil {x=x+1;x<100};\n"
|
||||
|
||||
equal(t, got, want)
|
||||
}
|
||||
|
||||
func getCompiled(t *testing.T, file string) string {
|
||||
code, err := ioutil.ReadFile(file)
|
||||
|
||||
|
||||
@@ -43,7 +43,9 @@ var keywords = []string{
|
||||
"default",
|
||||
"return",
|
||||
"try",
|
||||
"catch"}
|
||||
"catch",
|
||||
"exitwith",
|
||||
"waituntil"}
|
||||
|
||||
var whitespace = []byte{' ', '\n', '\t'}
|
||||
var identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||
|
||||
Reference in New Issue
Block a user