Started to add special function to inline code (issue #6).

This commit is contained in:
Marvin Blum
2015-10-28 17:59:38 +01:00
parent bba215cd8d
commit 1cbcda4261
5 changed files with 24 additions and 5 deletions

View File

@@ -171,6 +171,18 @@ waitUntil {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
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.

View File

@@ -1,4 +1 @@
switch x {
case 1:
x = 1;
}
var inline_code = code("var x = 5;");

View File

@@ -45,7 +45,8 @@ var keywords = []string{
"try",
"catch",
"exitwith",
"waituntil"}
"waituntil",
"code"}
var whitespace = []byte{' ', '\n', '\t', '\r'}
var identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"

View File

@@ -77,6 +77,14 @@ func TestTokenizerIdentifier(t *testing.T) {
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) {
if len(*got) != len(*want) {
t.Error("Length of tokens got and expected tokens not equal, was:")

1
test/tokenizer_code.asl Normal file
View File

@@ -0,0 +1 @@
var x = code("var x = 5;");