Skip to content

Commit

Permalink
Merge pull request #2192 from mateuszbujalski/matbuj_record_field_att…
Browse files Browse the repository at this point in the history
…ributes

Allow attributes on record fields
  • Loading branch information
aseemr authored Feb 12, 2021
2 parents f84e0c8 + 022d294 commit 5a00b3c
Show file tree
Hide file tree
Showing 29 changed files with 1,191 additions and 376 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ Guidelines for the changelog:
a semicolon separated list of terms. The old syntax will soon
be deprecated.

* Attributes on binders are now using a different syntax `[@@@ a1; ... ; an]` i.e.,
@@@ instead of @@. This is a breaking change that enables
using attributes on explicit binders, record fields and more. See
https://github.com/FStarLang/FStar/pull/2192 for more details.

## Extraction

Expand Down
6 changes: 4 additions & 2 deletions src/ocaml-output/FStar_Parser_AST.ml

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

8 changes: 6 additions & 2 deletions src/ocaml-output/FStar_Parser_Dep.ml

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

23 changes: 16 additions & 7 deletions src/ocaml-output/FStar_Parser_ToDocument.ml

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

17 changes: 16 additions & 1 deletion src/ocaml-output/FStar_Syntax_Resugar.ml

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

32 changes: 17 additions & 15 deletions src/ocaml-output/FStar_ToSyntax_ToSyntax.ml

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

2 changes: 1 addition & 1 deletion src/parser/FStar.Parser.AST.fs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ type expr = term
type tycon =
| TyconAbstract of ident * list<binder> * option<knd>
| TyconAbbrev of ident * list<binder> * option<knd> * term
| TyconRecord of ident * list<binder> * option<knd> * list<(ident * term)>
| TyconRecord of ident * list<binder> * option<knd> * list<(ident * aqual * attributes_ * term)>
| TyconVariant of ident * list<binder> * option<knd> * list<(ident * option<term> * bool)> (* bool is whether it's using 'of' notation *)

type qualifier =
Expand Down
5 changes: 4 additions & 1 deletion src/parser/FStar.Parser.Dep.fs
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,10 @@ let collect_one
| TyconRecord (_, binders, k, identterms) ->
collect_binders binders;
iter_opt k collect_term;
List.iter (fun (_, t) -> collect_term t) identterms
List.iter (fun (_, aq, attrs, t) ->
collect_aqual aq;
attrs |> List.iter collect_term;
collect_term t) identterms
| TyconVariant (_, binders, k, identterms) ->
collect_binders binders;
iter_opt k collect_term;
Expand Down
8 changes: 4 additions & 4 deletions src/parser/FStar.Parser.ToDocument.fs
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,9 @@ and p_typeDecl pre = function
let comm, doc = p_typ_sep false false t in
comm, p_typeDeclPrefix pre true lid bs typ_opt, doc, jump2
| TyconRecord (lid, bs, typ_opt, record_field_decls) ->
let p_recordField (ps: bool) (lid, t) =
let p_recordField (ps: bool) (lid, aq, attrs, t) =
let comm, field =
with_comment_sep (p_recordFieldDecl ps) (lid, t)
with_comment_sep (p_recordFieldDecl ps) (lid, aq, attrs, t)
(extend_to_end_of_line t.range) in
let sep = if ps then semi else empty in
inline_comment_or_above comm field sep
Expand Down Expand Up @@ -829,8 +829,8 @@ and p_typeDeclPrefix kw eq lid bs typ_opt =
let binders = p_binders_list true bs in
with_kw (fun n -> prefix2 (prefix2 n (flow break1 binders)) typ)

and p_recordFieldDecl ps (lid, t) =
group (p_lident lid ^^ colon ^^ p_typ ps false t)
and p_recordFieldDecl ps (lid, aq, attrs, t) =
group (optional p_aqual aq ^^ p_attributes attrs ^^ p_lident lid ^^ colon ^^ p_typ ps false t)

and p_constructorBranch (uid, t_opt, use_of) =
let sep = if use_of then str "of" else colon in
Expand Down
1 change: 1 addition & 0 deletions src/parser/lex.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ rule token args = parse
}

| "///[@"
| "[@@@" { LBRACK_AT_AT_AT }
| "[@@" { LBRACK_AT_AT }
| "[@" { LBRACK_AT }
| "//" [^'\n''\r']*
Expand Down
3 changes: 2 additions & 1 deletion src/parser/ml/FStar_Parser_LexFStar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ let () =
"=", EQUALS;
"%[", PERCENT_LBRACK;
"!{", BANG_LBRACE;
"[@@@", LBRACK_AT_AT_AT;
"[@@", LBRACK_AT_AT;
"[@", LBRACK_AT;
"[", LBRACK;
Expand Down Expand Up @@ -383,7 +384,7 @@ let regexp op_token =
"u#" | "&" | "()" | "(" | ")" | "," | "~>" | "->" | "<--" |
"<-" | "<==>" | "==>" | "." | "?." | "?" | ".[|" | ".[" | ".(|" | ".(" |
"$" | "{:pattern" | ":" | "::" | ":=" | ";;" | ";" | "=" | "%[" |
"!{" | "[@@" | "[@" | "[|" | "{|" | "[" | "|>" | "]" | "|]" | "|}" | "{" | "|" | "}"
"!{" | "[@@@" | "[@@" | "[@" | "[|" | "{|" | "[" | "|>" | "]" | "|]" | "|}" | "{" | "|" | "}"

(* -------------------------------------------------------------------- *)
let regexp xinteger =
Expand Down
Loading

0 comments on commit 5a00b3c

Please sign in to comment.