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

@@ -75,6 +75,12 @@ switch x {
default:
// ...
}
try {
// ...
} catch {
// ...
}
```
### Functions
@@ -115,6 +121,59 @@ foo(x, y, z)(1, 2, 3);
[x, y, z] foo [1, 2, 3];
```
### Special functions
There are some special functions in SQF, which also require special syntax in ASL. The examples presented here show how they are written in ASL and what the output will look like. Remember that ASL is case sensitive!
**exitWith**
```
exitwith {
// your code
}
// output:
if (true) exitWith {
// your code
};
```
**waitUntil**
```
waituntil(condition);
// or
waituntil(expression;condition);
// output:
waitUntil {condition};
// or
waitUntil {expression;condition};
```
## List of all keywords
Keywords should not be used as identifiers. Here is a full list of all keywords in ASL. Remember that build in functions should not be used neither.
| Keyword |
| - |
| var |
| if |
| while |
| witch |
| for |
| foreach |
| func |
| true |
| false |
| case |
| default |
| return |
| try |
| catch |
| exitwith |
| waituntil |
## Contribute
To contribute please create pull requests or explain your ideas in the issue section on GitHub. Report any bugs or incompatible ASL <-> SQF syntax you can find.

View File

@@ -14,6 +14,6 @@
## Special cases
* exitWith...
* waitUntil...
* ~~exitWith...~~
* ~~waitUntil...~~
* ~~!buildInFunc()()...~~

View File

@@ -34,7 +34,7 @@ if !(isNil()(_getunit)) {
if local()(_unit) {
try {
execVM(_unit)(_file);
execVM(_unit)(_file);
} catch {
// do nothing
}

View File

@@ -1 +1,8 @@
var x = !foo();
waituntil(x = x+1; x < 100);
if timeIsOver {
exitwith {
foo();
bar();
}
}

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_"

3
test/parser_exitwith.asl Normal file
View File

@@ -0,0 +1,3 @@
exitwith {
// ...
}

View File

@@ -0,0 +1 @@
waituntil(x = x+1; x < 100);