Skip to content

Commit

Permalink
Merge pull request #34 from vircoys/feat-list-literal-expr
Browse files Browse the repository at this point in the history
feat: List initialization supports all expressions as its elements #33
  • Loading branch information
coanor authored Jun 20, 2023
2 parents daa0f9f + fba125e commit 3a82402
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 217 deletions.
3 changes: 3 additions & 0 deletions pkg/engine/op_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ for a = 0; a < 12; a = a + 1 {
a = a - 1
}
add_key("list_", [1,2, {"a": [1,2 , 2 /1]}, {}])
`

scripts, errs := ParseScript(map[string]string{
Expand Down Expand Up @@ -113,5 +115,6 @@ for a = 0; a < 12; a = a + 1 {
"ef": int64(6),
"len1": int64(2),
"len2": int64(3),
"list_": "[1,2,{\"a\":[1,2,2]},{}]",
}, pt.Fields)
}
7 changes: 3 additions & 4 deletions pkg/parser/gram.y
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ NIL NULL IF ELIF ELSE
paren_expr
index_expr
attr_expr
/* in_expr */
expr
map_init
map_init_start
Expand Down Expand Up @@ -383,12 +384,12 @@ list_init : list_init_start RIGHT_BRACKET
}
;

list_init_start : LEFT_BRACKET array_elem
list_init_start : LEFT_BRACKET expr
{
$$ = yylex.(*parser).newListInitStartExpr($1.Pos)
$$ = yylex.(*parser).newListInitAppendExpr($$, $2)
}
| list_init_start COMMA array_elem
| list_init_start COMMA expr
{
$$ = yylex.(*parser).newListInitAppendExpr($$, $3)
}
Expand Down Expand Up @@ -432,8 +433,6 @@ array_elem : bool_literal
| identifier
;



/*
literal:
bool
Expand Down
Loading

0 comments on commit 3a82402

Please sign in to comment.