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:
59
README.md
59
README.md
@@ -75,6 +75,12 @@ switch x {
|
|||||||
default:
|
default:
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// ...
|
||||||
|
} catch {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Functions
|
### Functions
|
||||||
@@ -115,6 +121,59 @@ foo(x, y, z)(1, 2, 3);
|
|||||||
[x, y, z] foo [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
|
## 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.
|
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.
|
||||||
|
|||||||
4
ToDo.md
4
ToDo.md
@@ -14,6 +14,6 @@
|
|||||||
|
|
||||||
## Special cases
|
## Special cases
|
||||||
|
|
||||||
* exitWith...
|
* ~~exitWith...~~
|
||||||
* waitUntil...
|
* ~~waitUntil...~~
|
||||||
* ~~!buildInFunc()()...~~
|
* ~~!buildInFunc()()...~~
|
||||||
|
|||||||
@@ -1 +1,8 @@
|
|||||||
var x = !foo();
|
waituntil(x = x+1; x < 100);
|
||||||
|
|
||||||
|
if timeIsOver {
|
||||||
|
exitwith {
|
||||||
|
foo();
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ func parseBlock() {
|
|||||||
parseReturn()
|
parseReturn()
|
||||||
} else if accept("try") {
|
} else if accept("try") {
|
||||||
parseTryCatch()
|
parseTryCatch()
|
||||||
|
} else if accept("exitwith") {
|
||||||
|
parseExitWith()
|
||||||
|
} else if accept("waituntil") {
|
||||||
|
parseWaitUntil()
|
||||||
} else if accept("case") || accept("default") {
|
} else if accept("case") || accept("default") {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
@@ -248,6 +252,32 @@ func parseTryCatch() {
|
|||||||
appendOut("};", true)
|
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.
|
// Everything that does not start with a keyword.
|
||||||
func parseStatement() {
|
func parseStatement() {
|
||||||
// empty block
|
// empty block
|
||||||
|
|||||||
@@ -115,6 +115,20 @@ func TestParserNegationFunctionCall(t *testing.T) {
|
|||||||
equal(t, got, want)
|
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 {
|
func getCompiled(t *testing.T, file string) string {
|
||||||
code, err := ioutil.ReadFile(file)
|
code, err := ioutil.ReadFile(file)
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ var keywords = []string{
|
|||||||
"default",
|
"default",
|
||||||
"return",
|
"return",
|
||||||
"try",
|
"try",
|
||||||
"catch"}
|
"catch",
|
||||||
|
"exitwith",
|
||||||
|
"waituntil"}
|
||||||
|
|
||||||
var whitespace = []byte{' ', '\n', '\t'}
|
var whitespace = []byte{' ', '\n', '\t'}
|
||||||
var identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
var identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||||
|
|||||||
3
test/parser_exitwith.asl
Normal file
3
test/parser_exitwith.asl
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
exitwith {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
1
test/parser_waituntil.asl
Normal file
1
test/parser_waituntil.asl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
waituntil(x = x+1; x < 100);
|
||||||
Reference in New Issue
Block a user