Special cases for waitUntil and exitWith.

This commit is contained in:
Marvin Blum
2015-10-25 15:10:29 +01:00
parent 4848a502bb
commit abda5faff7
9 changed files with 121 additions and 5 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -43,7 +43,9 @@ var keywords = []string{
"default",
"return",
"try",
"catch"}
"catch",
"exitwith",
"waituntil"}
var whitespace = []byte{' ', '\n', '\t'}
var identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"