mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 03:50:25 +00:00
Issue #21.
This commit is contained in:
12
README.md
12
README.md
@@ -252,18 +252,14 @@ The following features are not implemented yet, but will be in 1.1.0 or a future
|
|||||||
|
|
||||||
* scopes
|
* scopes
|
||||||
* else if
|
* else if
|
||||||
* arrays within expressions (like someArray-[someEntity])
|
* selector in expression
|
||||||
|
|
||||||
scopes won't be supported, since they are a stupid concept and can be replaced by functions.
|
scopes won't be supported, since they are a stupid concept and can be replaced by functions.
|
||||||
There is a simple workaround for arrays within expressions:
|
|
||||||
|
Selectors in expressions do not work (yet):
|
||||||
|
|
||||||
```
|
```
|
||||||
// want: ... forEach allCurators-[myCurator];
|
var x = ([1, 2, 3]-[1, 2])[0]; // should result in 3
|
||||||
|
|
||||||
var myCuratorArray = [myCurator]; // or a more complex expression within array
|
|
||||||
foreach allCurators-myCuratorArray {
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contribute
|
## Contribute
|
||||||
|
|||||||
@@ -70,34 +70,35 @@ func (c *Compiler) parseVar() {
|
|||||||
if c.accept("=") {
|
if c.accept("=") {
|
||||||
c.next()
|
c.next()
|
||||||
c.appendOut(" = ", false)
|
c.appendOut(" = ", false)
|
||||||
|
c.parseExpression(true)
|
||||||
if c.accept("[") {
|
|
||||||
c.parseArray()
|
|
||||||
} else {
|
|
||||||
c.parseExpression(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.expect(";")
|
c.expect(";")
|
||||||
c.appendOut(";", true)
|
c.appendOut(";", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Compiler) parseArray() {
|
func (c *Compiler) parseArray(out bool) string {
|
||||||
|
output := ""
|
||||||
c.expect("[")
|
c.expect("[")
|
||||||
c.appendOut("[", false)
|
output += "["
|
||||||
|
|
||||||
if !c.accept("]") {
|
if !c.accept("]") {
|
||||||
c.parseExpression(true)
|
output += c.parseExpression(false)
|
||||||
|
|
||||||
for c.accept(",") {
|
for c.accept(",") {
|
||||||
c.next()
|
c.next()
|
||||||
c.appendOut(",", false)
|
output += ","+c.parseExpression(false)
|
||||||
c.parseExpression(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.expect("]")
|
c.expect("]")
|
||||||
c.appendOut("]", false)
|
output += "]"
|
||||||
|
|
||||||
|
if out {
|
||||||
|
c.appendOut(output, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Compiler) parseIf() {
|
func (c *Compiler) parseIf() {
|
||||||
@@ -463,6 +464,8 @@ func (c *Compiler) parseIdentifier() string {
|
|||||||
name := c.get().Token
|
name := c.get().Token
|
||||||
c.next()
|
c.next()
|
||||||
output = "(" + c.parseFunctionCall(false, name) + ")"
|
output = "(" + c.parseFunctionCall(false, name) + ")"
|
||||||
|
} else if c.accept("[") {
|
||||||
|
output += c.parseArray(false)
|
||||||
} else if c.seek("[") {
|
} else if c.seek("[") {
|
||||||
output += "("+c.get().Token
|
output += "("+c.get().Token
|
||||||
c.next()
|
c.next()
|
||||||
|
|||||||
@@ -161,6 +161,13 @@ func TestParserPreprocessor(t *testing.T) {
|
|||||||
equal(t, got, want)
|
equal(t, got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParserExpressionArray(t *testing.T) {
|
||||||
|
got := getCompiled(t, "test/parser_expression_array.asl")
|
||||||
|
want := "x = [1,2,3]-[2,3];\r\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)
|
||||||
|
|
||||||
|
|||||||
1
test/parser_expression_array.asl
Normal file
1
test/parser_expression_array.asl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
var x = [1, 2, 3]-[2, 3];
|
||||||
Reference in New Issue
Block a user