Skip to content

Commit

Permalink
fix grammar: Operator inside of function args reported as error (#64)
Browse files Browse the repository at this point in the history
Example:
ARule(){

x := count({x} & {y})

}

was reported as an error

Signed-off-by: Vincent Gramer <[email protected]>
  • Loading branch information
vgramer authored Nov 10, 2020
1 parent e00aa17 commit 16fcf24
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 37 deletions.
75 changes: 38 additions & 37 deletions src/main/grammar/Rego.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -64,41 +64,42 @@
COMMENT = 'regexp:[ \t]*#[^\r\n]*'
]
}
module ::= package import* policy
package ::= "package" ref
import ::= "import" ref ( "as" var )?
policy ::= rule*
rule ::= "default"? rule-head rule-body*
rule-head ::= var ( "(" rule-args? ")" )? ("[" term "]" )? ( ( ":=" | "=" ) term )?
rule-args ::= term ( "," term )*
rule-body ::= ( else ( "=" term )? )? "{" query "}"
query ::=( literal |';' )+
literal ::= ( some-decl | expr | "not" expr ) with-modifier*
with-modifier ::= "with" term "as" term
some-decl ::= "some" var ( "," var )*
expr ::= expr2 ((':=' | '=') expr2)?
expr2 ::= expr-infix | (expr-call ref-arg*) | term
expr-call ::= var ref-arg-dot* "(" ( term ( "," term )* )? ")"
expr-infix ::= ( term "=" )? term infix-operator term
term ::= ref | var | scalar | array | object | set | array-compr | object-compr | set-compr
array-compr ::= "[" term "|" query "]"
set-compr ::= "{" term "|" query "}"
object-compr ::= "{" object-item "|" query "}"
infix-operator ::= bool-operator | arith-operator | bin-operator
bool-operator ::= "==" | "!=" | "<" | ">" | ">=" | "<="
arith-operator ::= "+" | "-" | "*" | "/" | "%"
bin-operator ::= "&" | "|"
ref ::= ( expr-call | array | object | set | array-compr | object-compr | set-compr |var ) ref-arg*
ref-arg ::= ref-arg-dot | ref-arg-brack
ref-arg-brack ::= "[" ( scalar | var | array | object | set | "_" ) "]"
ref-arg-dot ::= "." var
var ::= ASCII_LETTER
scalar ::= string | NUMBER | TRUE | FALSE | NULL
string ::= STRING_TOKEN| RAW_STRING
array ::= '[' term? ( ',' term )* ','? ']'
object ::= '{' object-item? ( ',' object-item )* ','? '}'
object-item ::= ( scalar | ref | var ) ":" term
set ::= empty-set | non-empty-set
non-empty-set ::= "{" term ( "," term )* ','? "}"
empty-set ::= "set(" ")"
module ::= package import* policy
package ::= "package" ref
import ::= "import" ref ( "as" var )?
policy ::= rule*
rule ::= "default"? rule-head rule-body*
rule-head ::= var ( "(" rule-args? ")" )? ("[" term "]" )? ( ( ":=" | "=" ) term )?
rule-args ::= term ( "," term )*
rule-body ::= ( else ( "=" term )? )? "{" query "}"
query ::=( literal |';' )+
literal ::= ( some-decl | expr | "not" expr ) with-modifier*
with-modifier ::= "with" term "as" term
some-decl ::= "some" var ( "," var )*
expr ::= expr2 ((':=' | '=') expr2)?
expr2 ::= expr-infix | (expr-call ref-arg*) | term
term-or-infix-op ::= term (infix-operator term)?
expr-call ::= var ref-arg-dot* "(" ( term-or-infix-op ( "," term-or-infix-op )* )? ")"
expr-infix ::= ( term "=" )? term infix-operator term
term ::= ref | var | scalar | array | object | set | array-compr | object-compr | set-compr
array-compr ::= "[" term "|" query "]"
set-compr ::= "{" term "|" query "}"
object-compr ::= "{" object-item "|" query "}"
infix-operator ::= bool-operator | arith-operator | bin-operator
bool-operator ::= "==" | "!=" | "<" | ">" | ">=" | "<="
arith-operator ::= "+" | "-" | "*" | "/" | "%"
bin-operator ::= "&" | "|"
ref ::= ( expr-call | array | object | set | array-compr | object-compr | set-compr |var ) ref-arg*
ref-arg ::= ref-arg-dot | ref-arg-brack
ref-arg-brack ::= "[" ( scalar | var | array | object | set | "_" ) "]"
ref-arg-dot ::= "." var
var ::= ASCII_LETTER
scalar ::= string | NUMBER | TRUE | FALSE | NULL
string ::= STRING_TOKEN| RAW_STRING
array ::= '[' term? ( ',' term )* ','? ']'
object ::= '{' object-item? ( ',' object-item )* ','? '}'
object-item ::= ( scalar | ref | var ) ":" term
set ::= empty-set | non-empty-set
non-empty-set ::= "{" term ( "," term )* ','? "}"
empty-set ::= "set(" ")"

Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,16 @@ aRule {
l = fun_array(1)[0].a
m = fun_array(1)[0].a[0]
}

filterFunc(x) {
true
}

testing_complex_function_args{
# testing accectiing infix operation as arg. Issue #63
x := count({"x"} & {"y"})

# testing "complex" args
myset := {1, 2, 3}
array.slice([1, 2, 3, 4 ], count({x | myset[x]; filterFunc(x)} & {2}), 3)
}

0 comments on commit 16fcf24

Please sign in to comment.