Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overloading exists and forall similar to let operators #3149

Merged
merged 5 commits into from
Dec 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions ocaml/fstar-lib/FStar_Parser_LexFStar.ml
Original file line number Diff line number Diff line change
@@ -60,10 +60,10 @@ let () =
Hashtbl.add keywords "end" END ;
Hashtbl.add keywords "ensures" ENSURES ;
Hashtbl.add keywords "exception" EXCEPTION ;
Hashtbl.add keywords "exists" EXISTS ;
Hashtbl.add keywords "exists" (EXISTS false);
Hashtbl.add keywords "false" FALSE ;
Hashtbl.add keywords "friend" FRIEND ;
Hashtbl.add keywords "forall" FORALL ;
Hashtbl.add keywords "forall" (FORALL false);
Hashtbl.add keywords "fun" FUN ;
Hashtbl.add keywords "λ" FUN ;
Hashtbl.add keywords "function" FUNCTION ;
@@ -191,8 +191,8 @@ let () =
"}", RBRACE;
"$", DOLLAR;
(* New Unicode equivalents *)
"∀", FORALL;
"∃", EXISTS;
"∀", (FORALL false);
"∃", (EXISTS false);
"⊤", NAME "True";
"⊥", NAME "False";
"⟹", IMPLIES;
@@ -490,6 +490,34 @@ match%sedlex lexbuf with
| s -> LET_OP s
)

| "exists", Plus op_char ->
ensure_no_comment lexbuf (fun s ->
match BatString.lchop ~n:6 s with
| "" -> EXISTS false
| s -> EXISTS_OP s
)

| "∃", Plus op_char ->
ensure_no_comment lexbuf (fun s ->
match BatString.lchop ~n:1 s with
| "" -> EXISTS false
| s -> EXISTS_OP s
)

| "forall", Plus op_char ->
ensure_no_comment lexbuf (fun s ->
match BatString.lchop ~n:6 s with
| "" -> FORALL false
| s -> FORALL_OP s
)

| "∀", Plus op_char ->
ensure_no_comment lexbuf (fun s ->
match BatString.lchop ~n:1 s with
| "" -> FORALL false
| s -> FORALL_OP s
)

| "and", Plus op_char ->
ensure_no_comment lexbuf (fun s ->
match BatString.lchop ~n:3 s with
23 changes: 22 additions & 1 deletion ocaml/fstar-lib/FStar_Parser_Parse.mly
Original file line number Diff line number Diff line change
@@ -86,13 +86,19 @@ let parse_extension_blob (extension_name:string)
%token <string> AND_OP
%token <string> MATCH_OP
%token <string> IF_OP
%token <bool> EXISTS
%token <string> EXISTS_OP
%token <bool> FORALL
%token <string> FORALL_OP


/* [SEMICOLON_OP] encodes either:
- [;;], which used to be SEMICOLON_SEMICOLON, or
- [;<OP>], with <OP> a sequence of [op_char] (see FStar_Parser_LexFStar).
*/
%token <string option> SEMICOLON_OP

%token FORALL EXISTS ASSUME NEW LOGIC ATTRIBUTES
%token ASSUME NEW LOGIC ATTRIBUTES
%token IRREDUCIBLE UNFOLDABLE INLINE OPAQUE UNFOLD INLINE_FOR_EXTRACTION
%token NOEXTRACT
%token NOEQUALITY UNOPTEQUALITY PRAGMA_SET_OPTIONS PRAGMA_RESET_OPTIONS PRAGMA_PUSH_OPTIONS PRAGMA_POP_OPTIONS PRAGMA_RESTART_SOLVER PRAGMA_PRINT_EFFECTS_GRAPH
@@ -1074,6 +1080,16 @@ typ:
%inline quantifier:
| FORALL { fun x -> QForall x }
| EXISTS { fun x -> QExists x}
| op=FORALL_OP
{
let op = mk_ident("forall" ^ op, rr $loc(op)) in
fun (x,y,z) -> QuantOp (op, x, y, z)
}
| op=EXISTS_OP
{
let op = mk_ident("exists" ^ op, rr $loc(op)) in
fun (x,y,z) -> QuantOp (op, x, y, z)
}

trigger:
| { [] }
@@ -1541,6 +1557,11 @@ string:
| op=TILDE { mk_ident (op, rr $loc) }
| op=and_op {op}
| op=let_op {op}
| op=quantifier_op {op}

%inline quantifier_op:
| op=EXISTS_OP { mk_ident ("exists" ^ op, rr $loc) }
| op=FORALL_OP { mk_ident ("forall" ^ op, rr $loc) }

%inline and_op:
| op=AND_OP { mk_ident ("and" ^ op, rr $loc) }
57 changes: 48 additions & 9 deletions ocaml/fstar-lib/generated/FStar_Parser_AST.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions ocaml/fstar-lib/generated/FStar_Parser_AST_Util.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ocaml/fstar-lib/generated/FStar_Parser_Dep.ml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading