mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Started to add special function to inline code (issue #6).
This commit is contained in:
12
README.md
12
README.md
@@ -171,6 +171,18 @@ waitUntil {condition};
|
|||||||
waitUntil {expression;condition};
|
waitUntil {expression;condition};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**code**
|
||||||
|
|
||||||
|
The code function is used to compile inline code. This does **not** replace SQF compile buildin function, but will return the contained ASL code as SQF.
|
||||||
|
|
||||||
|
```
|
||||||
|
// input:
|
||||||
|
var x = code("var y = 5;"); // pass as string
|
||||||
|
|
||||||
|
// output:
|
||||||
|
x = {y = 5;};
|
||||||
|
```
|
||||||
|
|
||||||
## List of all keywords
|
## 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 function names should not be used neither.
|
Keywords should not be used as identifiers. Here is a full list of all keywords in ASL. Remember that build in function names should not be used neither.
|
||||||
|
|||||||
@@ -1,4 +1 @@
|
|||||||
switch x {
|
var inline_code = code("var x = 5;");
|
||||||
case 1:
|
|
||||||
x = 1;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ var keywords = []string{
|
|||||||
"try",
|
"try",
|
||||||
"catch",
|
"catch",
|
||||||
"exitwith",
|
"exitwith",
|
||||||
"waituntil"}
|
"waituntil",
|
||||||
|
"code"}
|
||||||
|
|
||||||
var whitespace = []byte{' ', '\n', '\t', '\r'}
|
var whitespace = []byte{' ', '\n', '\t', '\r'}
|
||||||
var identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
var identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||||
|
|||||||
@@ -77,6 +77,14 @@ func TestTokenizerIdentifier(t *testing.T) {
|
|||||||
compareTokens(t, &got, &want)
|
compareTokens(t, &got, &want)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTokenizerInlineCode(t *testing.T) {
|
||||||
|
got := getTokens(t, "test/tokenizer_code.asl")
|
||||||
|
want := []string{"var", "x", "=", "code", "(", "\"var x = 5;\"", ")", ";"}
|
||||||
|
|
||||||
|
compareLength(t, &got, &want)
|
||||||
|
compareTokens(t, &got, &want)
|
||||||
|
}
|
||||||
|
|
||||||
func compareLength(t *testing.T, got *[]Token, want *[]string) {
|
func compareLength(t *testing.T, got *[]Token, want *[]string) {
|
||||||
if len(*got) != len(*want) {
|
if len(*got) != len(*want) {
|
||||||
t.Error("Length of tokens got and expected tokens not equal, was:")
|
t.Error("Length of tokens got and expected tokens not equal, was:")
|
||||||
|
|||||||
1
test/tokenizer_code.asl
Normal file
1
test/tokenizer_code.asl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
var x = code("var x = 5;");
|
||||||
Reference in New Issue
Block a user