Set membership is now a full-fledged expression.
It used to be tied to the test expression of a conditional.
This commit is contained in:
parent
fef4337e83
commit
c0800a64ef
29
AST.ml
29
AST.ml
@ -407,7 +407,7 @@ and fail_instr = {
|
|||||||
|
|
||||||
and conditional = {
|
and conditional = {
|
||||||
kwd_if : kwd_if;
|
kwd_if : kwd_if;
|
||||||
test : test_expr;
|
test : expr;
|
||||||
kwd_then : kwd_then;
|
kwd_then : kwd_then;
|
||||||
ifso : if_clause;
|
ifso : if_clause;
|
||||||
terminator : semi option;
|
terminator : semi option;
|
||||||
@ -419,10 +419,6 @@ and if_clause =
|
|||||||
ClauseInstr of instruction
|
ClauseInstr of instruction
|
||||||
| ClauseBlock of (instructions * semi option) braces reg
|
| ClauseBlock of (instructions * semi option) braces reg
|
||||||
|
|
||||||
and test_expr =
|
|
||||||
GenExpr of expr
|
|
||||||
| SetMem of set_membership reg
|
|
||||||
|
|
||||||
and set_membership = {
|
and set_membership = {
|
||||||
set : expr;
|
set : expr;
|
||||||
kwd_contains : kwd_contains;
|
kwd_contains : kwd_contains;
|
||||||
@ -519,6 +515,7 @@ and expr =
|
|||||||
|
|
||||||
and set_expr =
|
and set_expr =
|
||||||
SetInj of set_injection reg
|
SetInj of set_injection reg
|
||||||
|
| SetMem of set_membership reg
|
||||||
|
|
||||||
and set_injection = {
|
and set_injection = {
|
||||||
opening : opening;
|
opening : opening;
|
||||||
@ -705,7 +702,8 @@ and map_expr_to_region = function
|
|||||||
| MapInj {region; _} -> region
|
| MapInj {region; _} -> region
|
||||||
|
|
||||||
and set_expr_to_region = function
|
and set_expr_to_region = function
|
||||||
SetInj {region; _} -> region
|
SetInj {region; _}
|
||||||
|
| SetMem {region; _} -> region
|
||||||
|
|
||||||
and logic_expr_to_region = function
|
and logic_expr_to_region = function
|
||||||
BoolExpr e -> bool_expr_to_region e
|
BoolExpr e -> bool_expr_to_region e
|
||||||
@ -1093,7 +1091,7 @@ and print_conditional node =
|
|||||||
let {kwd_if; test; kwd_then; ifso; terminator;
|
let {kwd_if; test; kwd_then; ifso; terminator;
|
||||||
kwd_else; ifnot} = node in
|
kwd_else; ifnot} = node in
|
||||||
print_token kwd_if "if";
|
print_token kwd_if "if";
|
||||||
print_test_expr test;
|
print_expr test;
|
||||||
print_token kwd_then "then";
|
print_token kwd_then "then";
|
||||||
print_if_clause ifso;
|
print_if_clause ifso;
|
||||||
print_terminator terminator;
|
print_terminator terminator;
|
||||||
@ -1110,16 +1108,6 @@ and print_if_clause = function
|
|||||||
print_terminator terminator;
|
print_terminator terminator;
|
||||||
print_token rbrace "}"
|
print_token rbrace "}"
|
||||||
|
|
||||||
and print_test_expr = function
|
|
||||||
GenExpr e -> print_expr e
|
|
||||||
| SetMem m -> print_set_membership m
|
|
||||||
|
|
||||||
and print_set_membership {value; _} =
|
|
||||||
let {set; kwd_contains; element} = value in
|
|
||||||
print_expr set;
|
|
||||||
print_token kwd_contains "contains";
|
|
||||||
print_expr element
|
|
||||||
|
|
||||||
and print_case_instr (node : case_instr) =
|
and print_case_instr (node : case_instr) =
|
||||||
let {kwd_case; expr; kwd_of;
|
let {kwd_case; expr; kwd_of;
|
||||||
lead_vbar; cases; kwd_end} = node in
|
lead_vbar; cases; kwd_end} = node in
|
||||||
@ -1235,6 +1223,13 @@ and print_map_expr = function
|
|||||||
|
|
||||||
and print_set_expr = function
|
and print_set_expr = function
|
||||||
SetInj inj -> print_set_injection inj
|
SetInj inj -> print_set_injection inj
|
||||||
|
| SetMem mem -> print_set_membership mem
|
||||||
|
|
||||||
|
and print_set_membership {value; _} =
|
||||||
|
let {set; kwd_contains; element} = value in
|
||||||
|
print_expr set;
|
||||||
|
print_token kwd_contains "contains";
|
||||||
|
print_expr element
|
||||||
|
|
||||||
and print_map_lookup {path; index} =
|
and print_map_lookup {path; index} =
|
||||||
let {lbracket; inside; rbracket} = index.value in
|
let {lbracket; inside; rbracket} = index.value in
|
||||||
|
7
AST.mli
7
AST.mli
@ -391,7 +391,7 @@ and fail_instr = {
|
|||||||
|
|
||||||
and conditional = {
|
and conditional = {
|
||||||
kwd_if : kwd_if;
|
kwd_if : kwd_if;
|
||||||
test : test_expr;
|
test : expr;
|
||||||
kwd_then : kwd_then;
|
kwd_then : kwd_then;
|
||||||
ifso : if_clause;
|
ifso : if_clause;
|
||||||
terminator : semi option;
|
terminator : semi option;
|
||||||
@ -403,10 +403,6 @@ and if_clause =
|
|||||||
ClauseInstr of instruction
|
ClauseInstr of instruction
|
||||||
| ClauseBlock of (instructions * semi option) braces reg
|
| ClauseBlock of (instructions * semi option) braces reg
|
||||||
|
|
||||||
and test_expr =
|
|
||||||
GenExpr of expr
|
|
||||||
| SetMem of set_membership reg
|
|
||||||
|
|
||||||
and set_membership = {
|
and set_membership = {
|
||||||
set : expr;
|
set : expr;
|
||||||
kwd_contains : kwd_contains;
|
kwd_contains : kwd_contains;
|
||||||
@ -503,6 +499,7 @@ and expr =
|
|||||||
|
|
||||||
and set_expr =
|
and set_expr =
|
||||||
SetInj of set_injection reg
|
SetInj of set_injection reg
|
||||||
|
| SetMem of set_membership reg
|
||||||
|
|
||||||
and set_injection = {
|
and set_injection = {
|
||||||
opening : opening;
|
opening : opening;
|
||||||
|
35
Parser.mly
35
Parser.mly
@ -641,7 +641,7 @@ proc_call:
|
|||||||
fun_call { $1 }
|
fun_call { $1 }
|
||||||
|
|
||||||
conditional:
|
conditional:
|
||||||
If test_expr Then if_clause option(SEMI) Else if_clause {
|
If expr Then if_clause option(SEMI) Else if_clause {
|
||||||
let region = cover $1 (if_clause_to_region $7) in
|
let region = cover $1 (if_clause_to_region $7) in
|
||||||
let value = {
|
let value = {
|
||||||
kwd_if = $1;
|
kwd_if = $1;
|
||||||
@ -668,22 +668,6 @@ if_clause:
|
|||||||
ClauseBlock {value; region}
|
ClauseBlock {value; region}
|
||||||
}
|
}
|
||||||
|
|
||||||
test_expr:
|
|
||||||
expr { GenExpr $1 }
|
|
||||||
| set_membership { SetMem $1 }
|
|
||||||
|
|
||||||
set_membership:
|
|
||||||
expr Contains expr {
|
|
||||||
let start = expr_to_region $1
|
|
||||||
and stop = expr_to_region $3 in
|
|
||||||
let region = cover start stop in
|
|
||||||
let value = {
|
|
||||||
set = $1;
|
|
||||||
kwd_contains = $2;
|
|
||||||
element = $3}
|
|
||||||
in {region; value}
|
|
||||||
}
|
|
||||||
|
|
||||||
case_instr:
|
case_instr:
|
||||||
Case expr Of option(VBAR) cases End {
|
Case expr Of option(VBAR) cases End {
|
||||||
let region = cover $1 $6 in
|
let region = cover $1 $6 in
|
||||||
@ -794,13 +778,26 @@ expr:
|
|||||||
| conj_expr { $1 }
|
| conj_expr { $1 }
|
||||||
|
|
||||||
conj_expr:
|
conj_expr:
|
||||||
conj_expr And comp_expr {
|
conj_expr And set_membership {
|
||||||
let start = expr_to_region $1
|
let start = expr_to_region $1
|
||||||
and stop = expr_to_region $3 in
|
and stop = expr_to_region $3 in
|
||||||
let region = cover start stop
|
let region = cover start stop
|
||||||
and value = {arg1 = $1; op = $2; arg2 = $3}
|
and value = {arg1 = $1; op = $2; arg2 = $3}
|
||||||
in ELogic (BoolExpr (And {region; value}))
|
in ELogic (BoolExpr (And {region; value}))
|
||||||
}
|
}
|
||||||
|
| set_membership { $1 }
|
||||||
|
|
||||||
|
set_membership:
|
||||||
|
core_expr Contains set_membership {
|
||||||
|
let start = expr_to_region $1
|
||||||
|
and stop = expr_to_region $3 in
|
||||||
|
let region = cover start stop in
|
||||||
|
let value = {
|
||||||
|
set = $1;
|
||||||
|
kwd_contains = $2;
|
||||||
|
element = $3}
|
||||||
|
in ESet (SetMem {region; value})
|
||||||
|
}
|
||||||
| comp_expr { $1 }
|
| comp_expr { $1 }
|
||||||
|
|
||||||
comp_expr:
|
comp_expr:
|
||||||
@ -926,7 +923,7 @@ unary_expr:
|
|||||||
|
|
||||||
core_expr:
|
core_expr:
|
||||||
Int { EArith (Int $1) }
|
Int { EArith (Int $1) }
|
||||||
| var { EVar $1 }
|
| var { EVar $1 } (* TODO: Path *)
|
||||||
| String { EString (String $1) }
|
| String { EString (String $1) }
|
||||||
| Bytes { EBytes $1 }
|
| Bytes { EBytes $1 }
|
||||||
| C_False { ELogic (BoolExpr (False $1)) }
|
| C_False { ELogic (BoolExpr (False $1)) }
|
||||||
|
Loading…
Reference in New Issue
Block a user