Skip to content

Commit

Permalink
Relax lookahead test for ltac2 { foo with ... } to allow qualids
Browse files Browse the repository at this point in the history
  • Loading branch information
SkySkimmer committed Sep 28, 2023
1 parent 045c362 commit 41c59ab
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion doc/tools/docgram/common.edit_mlg
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ DELETE: [
| test_array_opening
| test_array_closing
| test_variance_ident
| test_ident_with_or_lpar_or_rbrac
| test_qualid_with_or_lpar_or_rbrac
| test_leftsquarebracket_equal

(* unused *)
Expand Down
2 changes: 1 addition & 1 deletion doc/tools/docgram/fullGrammar
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,7 @@ ltac2_expr0: [
| "(" ")" (* ltac2 plugin *)
| array_literal (* ltac2 plugin *)
| list_literal (* ltac2 plugin *)
| "{" test_ident_with_or_lpar_or_rbrac ltac2_expr0 "with" tac2rec_fieldexprs "}" (* ltac2 plugin *)
| "{" test_qualid_with_or_lpar_or_rbrac ltac2_expr0 "with" tac2rec_fieldexprs "}" (* ltac2 plugin *)
| "{" tac2rec_fieldexprs "}" (* ltac2 plugin *)
| G_LTAC2_tactic_atom (* ltac2 plugin *)
]
Expand Down
6 changes: 6 additions & 0 deletions parsing/pcoq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ struct

let lk_ident_list = lk_list lk_ident

let lk_field n kwstate strm = match LStream.peek_nth kwstate n strm with
| Tok.FIELD _ -> Some (n+1)
| _ -> None

let lk_qualid = lk_ident >> lk_list lk_field

end

(** Grammar extensions *)
Expand Down
1 change: 1 addition & 0 deletions parsing/pcoq.mli
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module Lookahead : sig
val lk_nat : t
val lk_ident : t
val lk_name : t
val lk_qualid : t
val lk_ident_except : string list -> t
val lk_ident_list : t
end
Expand Down
8 changes: 4 additions & 4 deletions plugins/ltac2/g_ltac2.mlg
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ let test_ltac1_env =
lk_ident_list >> lk_kw "|-"
end

let test_ident_with_or_lpar_or_rbrac =
let test_qualid_with_or_lpar_or_rbrac =
let open Pcoq.Lookahead in
to_entry "test_ident_with_or_lpar_or_rbrac" begin
(lk_ident >> lk_kw "with") <+> lk_kw "(" <+> lk_kw "{"
to_entry "test_qualid_with_or_lpar_or_rbrac" begin
(lk_qualid >> lk_kw "with") <+> lk_kw "(" <+> lk_kw "{"
end

let test_array_opening =
Expand Down Expand Up @@ -226,7 +226,7 @@ GRAMMAR EXTEND Gram
{ CAst.make ~loc @@ CTacCst (AbsKn (Tuple 0)) }
| a = array_literal -> { a }
| a = list_literal -> { a }
| "{"; test_ident_with_or_lpar_or_rbrac; e = ltac2_expr LEVEL "0"; "with"; a = tac2rec_fieldexprs; "}" ->
| "{"; test_qualid_with_or_lpar_or_rbrac; e = ltac2_expr LEVEL "0"; "with"; a = tac2rec_fieldexprs; "}" ->
{ CAst.make ~loc @@ CTacRec (Some e, a) }
| "{"; a = tac2rec_fieldexprs; "}" ->
{ CAst.make ~loc @@ CTacRec (None, a) }
Expand Down
2 changes: 0 additions & 2 deletions plugins/ltac2/g_ltac2.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ val test_dollar_ident : unit Pcoq.Entry.t

val test_ltac1_env : unit Pcoq.Entry.t

val test_ident_with_or_lpar_or_rbrac : unit Pcoq.Entry.t

val test_array_opening : unit Pcoq.Entry.t

val test_array_closing : unit Pcoq.Entry.t
Expand Down
10 changes: 10 additions & 0 deletions test-suite/ltac2/default_record.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ Fail Ltac2 foobar () := { { a := (); b := () } with aa := () }.

Ltac2 varvar v := { v with aa := () }.
Print varvar.

(* From #17764 *)
Module Point.
Ltac2 Type t := { x : int ; y : int }.

Ltac2 origin : t := { x := 0; y := 0; }.

End Point.

Ltac2 Eval { Point.origin with Point.y := 1; }.

0 comments on commit 41c59ab

Please sign in to comment.