Skip to content

Commit 2273226

Browse files
committed
Do not tolerate SELF on the left of right-associative levels
1 parent 5e80978 commit 2273226

7 files changed

Lines changed: 114 additions & 50 deletions

File tree

gramlib/grammar.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,9 @@ let rec continue_parser_of_levels entry clevn =
14521452
in
14531453
let p2 = parser_of_tree entry (succ clevn) alevn tree in
14541454
fun gstate levfrom levn bp a strm ->
1455+
(* Adjust levfrom based on its associativity. *)
1456+
let levfrom = if levfrom = Some clevn && lev.assoc <> LeftA
1457+
then Some(clevn - 1) else levfrom in
14551458
(* Apply the lsuffix continuation if the level is in the interval [levn;levfrom] *)
14561459
if levn > clevn then
14571460
(* Skip rules before [levn] *)

test-suite/ltac2/fragile_matching.v

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ End RealCodeTest.
117117
Module Parsing.
118118
(* additional parsing tests not from ocaml *)
119119

120-
(* the first command should not parse as the second *)
121-
Ltac2 Eval fun x => match x with _ :: _ | _ as x => x end.
122-
Fail Ltac2 Eval fun x => match x with _ :: _ | (_ as x) => x end.
123-
124120
(* #21045 *)
125121
Ltac2 Eval match [10; 20; 30; 40] with x :: y :: z => x :: y :: z | _ => [] end.
126122

test-suite/output-coqtop/StrictAssociativity.out

Lines changed: 98 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,13 @@ This tolerance will be eventually removed. Insert parentheses or try to lower
172172
the level at which the top symbol of this expression is parsed.
173173
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
174174

175-
Rocq < Rocq < Reject 60 (F E)
176-
: Parsing
175+
Rocq < Rocq < Toplevel input, characters 20-25:
176+
> Check Reject 60 [2 atom2 post12 ].
177+
> ^^^^^
178+
Error: In custom:Top.expr, tolerating this expression at a higher level than
179+
expected. This tolerance will be eventually removed. Insert parentheses or
180+
try to lower the level at which the top symbol of this expression is parsed.
181+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
177182

178183
Rocq < Accept 61 (F E)
179184
: Parsing
@@ -208,8 +213,13 @@ This tolerance will be eventually removed. Insert parentheses or try to lower
208213
the level at which the top symbol of this expression is parsed.
209214
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
210215

211-
Rocq < Rocq < Reject 80 (G E E)
212-
: Parsing
216+
Rocq < Rocq < Toplevel input, characters 20-25:
217+
> Check Reject 80 [3 atom3 op22 atom2 ].
218+
> ^^^^^
219+
Error: In custom:Top.expr, tolerating this expression at a higher level than
220+
expected. This tolerance will be eventually removed. Insert parentheses or
221+
try to lower the level at which the top symbol of this expression is parsed.
222+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
213223

214224
Rocq < Toplevel input, characters 30-35:
215225
> Check Reject 81 [3 atom2 op22 atom3 ].
@@ -230,8 +240,13 @@ This tolerance will be eventually removed. Insert parentheses or try to lower
230240
the level at which the top symbol of this expression is parsed.
231241
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
232242

233-
Rocq < Rocq < Reject 90 (G E E)
234-
: Parsing
243+
Rocq < Rocq < Toplevel input, characters 20-25:
244+
> Check Reject 90 [2 atom2 op12 atom2 ].
245+
> ^^^^^
246+
Error: In custom:Top.expr, tolerating this expression at a higher level than
247+
expected. This tolerance will be eventually removed. Insert parentheses or
248+
try to lower the level at which the top symbol of this expression is parsed.
249+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
235250

236251
Rocq < Toplevel input, characters 30-35:
237252
> Check Reject 91 [2 atom1 op12 atom3 ].
@@ -279,20 +294,40 @@ This tolerance will be eventually removed. Insert parentheses or try to lower
279294
the level at which the top symbol of this expression is parsed.
280295
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
281296

282-
Rocq < Rocq < Reject 110 (F (G E E))
283-
: Parsing
297+
Rocq < Rocq < Toplevel input, characters 27-32:
298+
> Check Reject 110 [2 pre22 atom2 op12 atom2 ].
299+
> ^^^^^
300+
Error: In custom:Top.expr, tolerating this expression at a higher level than
301+
expected. This tolerance will be eventually removed. Insert parentheses or
302+
try to lower the level at which the top symbol of this expression is parsed.
303+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
284304

285-
Rocq < Reject 111 (G (F E) E)
286-
: Parsing
305+
Rocq < Toplevel input, characters 20-31:
306+
> Check Reject 111 [2 pre21 atom1 op12 atom2 ].
307+
> ^^^^^^^^^^^
308+
Error: In custom:Top.expr, tolerating this expression at a higher level than
309+
expected. This tolerance will be eventually removed. Insert parentheses or
310+
try to lower the level at which the top symbol of this expression is parsed.
311+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
287312

288313
Rocq < Accept 112 (F (G E E))
289314
: Parsing
290315

291-
Rocq < Rocq < Reject 120 (G (F E) E)
292-
: Parsing
316+
Rocq < Rocq < Toplevel input, characters 21-33:
317+
> Check Reject 120 [2 atom2 post12 op12 atom2 ].
318+
> ^^^^^^^^^^^^
319+
Error: In custom:Top.expr, tolerating this expression at a higher level than
320+
expected. This tolerance will be eventually removed. Insert parentheses or
321+
try to lower the level at which the top symbol of this expression is parsed.
322+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
293323

294-
Rocq < Reject 121 (G (F E) E)
295-
: Parsing
324+
Rocq < Toplevel input, characters 20-32:
325+
> Check Reject 121 [2 atom1 post12 op12 atom2 ].
326+
> ^^^^^^^^^^^^
327+
Error: In custom:Top.expr, tolerating this expression at a higher level than
328+
expected. This tolerance will be eventually removed. Insert parentheses or
329+
try to lower the level at which the top symbol of this expression is parsed.
330+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
296331

297332
Rocq < Accept 122 (G (F E) E)
298333
: Parsing
@@ -311,8 +346,13 @@ try to lower the level at which the top symbol of this expression is parsed.
311346
Rocq < Accept 132 (G E (F E))
312347
: Parsing
313348

314-
Rocq < Rocq < Reject 140 (G E (F E))
315-
: Parsing
349+
Rocq < Rocq < Toplevel input, characters 32-37:
350+
> Check Reject 140 [2 atom1 op12 atom2 post12 ].
351+
> ^^^^^
352+
Error: In custom:Top.expr, tolerating this expression at a higher level than
353+
expected. This tolerance will be eventually removed. Insert parentheses or
354+
try to lower the level at which the top symbol of this expression is parsed.
355+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
316356

317357
Rocq < Accept 141 (G E (F E))
318358
: Parsing
@@ -383,8 +423,13 @@ the level at which the top symbol of this expression is parsed.
383423
Rocq < Accept 182 (F (G E E))
384424
: Parsing
385425

386-
Rocq < Rocq < Reject 190 (G E (G E E))
387-
: Parsing
426+
Rocq < Rocq < Toplevel input, characters 32-37:
427+
> Check Reject 190 [2 atom1 op12 atom2 op12 atom2 ].
428+
> ^^^^^
429+
Error: In custom:Top.expr, tolerating this expression at a higher level than
430+
expected. This tolerance will be eventually removed. Insert parentheses or
431+
try to lower the level at which the top symbol of this expression is parsed.
432+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
388433

389434
Rocq < Accept 191 (G E (G E E))
390435
: Parsing
@@ -849,11 +894,13 @@ where
849894
?A : [ |- Type]
850895
?Goal : [ |- ?A]
851896

852-
Rocq < Rocq < Reject 1100 ?Goal
853-
: Parsing
854-
where
855-
?A : [ |- Type]
856-
?Goal : [ |- ?A]
897+
Rocq < Rocq < Toplevel input, characters 25-30:
898+
> Check Reject 1100 ltac:(atom2 + atom2).
899+
> ^^^^^
900+
Error: In ltac_expr, tolerating this expression at a higher level than
901+
expected. This tolerance will be eventually removed. Insert parentheses or
902+
try to lower the level at which the top symbol of this expression is parsed.
903+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
857904

858905
Rocq < Toplevel input, characters 32-37:
859906
> Check Reject 1101 ltac:(atom1 + atom3).
@@ -875,17 +922,21 @@ where
875922
?A : [ |- Type]
876923
?Goal : [ |- ?A]
877924

878-
Rocq < Rocq < Reject 1110 ?Goal
879-
: Parsing
880-
where
881-
?A : [ |- Type]
882-
?Goal : [ |- ?A]
925+
Rocq < Rocq < Toplevel input, characters 31-36:
926+
> Check Reject 1110 ltac:(pre22 atom2 + atom2).
927+
> ^^^^^
928+
Error: In ltac_expr, tolerating this expression at a higher level than
929+
expected. This tolerance will be eventually removed. Insert parentheses or
930+
try to lower the level at which the top symbol of this expression is parsed.
931+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
883932

884-
Rocq < Reject 1111 ?Goal
885-
: Parsing
886-
where
887-
?A : [ |- Type]
888-
?Goal : [ |- ?A]
933+
Rocq < Toplevel input, characters 24-35:
934+
> Check Reject 1111 ltac:(pre21 atom1 + atom2).
935+
> ^^^^^^^^^^^
936+
Error: In ltac_expr, tolerating this expression at a higher level than
937+
expected. This tolerance will be eventually removed. Insert parentheses or
938+
try to lower the level at which the top symbol of this expression is parsed.
939+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
889940

890941
Rocq < Accept 1112 ?Goal
891942
: Parsing
@@ -899,17 +950,21 @@ where
899950
?A : [ |- Type]
900951
?Goal : [ |- ?A]
901952

902-
Rocq < Rocq < Reject 1120 ?Goal
903-
: Parsing
904-
where
905-
?A : [ |- Type]
906-
?Goal : [ |- ?A]
953+
Rocq < Rocq < Toplevel input, characters 25-37:
954+
> Check Reject 1120 ltac:(atom1 post12 + atom2).
955+
> ^^^^^^^^^^^^
956+
Error: In ltac_expr, tolerating this expression at a higher level than
957+
expected. This tolerance will be eventually removed. Insert parentheses or
958+
try to lower the level at which the top symbol of this expression is parsed.
959+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
907960

908-
Rocq < Reject 1121 ?Goal
909-
: Parsing
910-
where
911-
?A : [ |- Type]
912-
?Goal : [ |- ?A]
961+
Rocq < Toplevel input, characters 32-37:
962+
> Check Reject 1121 ltac:(atom1 + atom2 post12).
963+
> ^^^^^
964+
Error: In ltac_expr, tolerating this expression at a higher level than
965+
expected. This tolerance will be eventually removed. Insert parentheses or
966+
try to lower the level at which the top symbol of this expression is parsed.
967+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
913968

914969
Rocq < Accept 1122 ?Goal
915970
: Parsing

test-suite/output/Notations4.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ Inductive Expr :=
4949
| One : Expr.
5050

5151
Declare Custom Entry expr.
52+
Notation "x + y" := (Add x y) (in custom expr at level 2, left associativity).
5253
Notation "[ expr ]" := expr (expr custom expr at level 2).
5354
Notation "1" := One (in custom expr at level 0).
5455
Notation "x y" := (Mul x y) (in custom expr at level 1, left associativity).
55-
Notation "x + y" := (Add x y) (in custom expr at level 2, left associativity).
5656
Notation "( x )" := x (in custom expr at level 0, x at level 2).
5757
Notation "{ x }" := x (in custom expr at level 0, x constr).
5858
Notation "x" := x (in custom expr at level 0, x ident).

test-suite/output/PrintNotation.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Notation "_ $ _" at level 123 with arguments constr at next level, constr
22
at next level, no associativity.
3+
File "./output/PrintNotation.v", line 8, characters 9-14:
4+
Warning: In term, tolerating this expression at a higher level than expected.
5+
This tolerance will be eventually removed. Insert parentheses or try to lower
6+
the level at which the top symbol of this expression is parsed.
7+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
38
bar (bar ?f ?f0) ?f1
49
: foo
510
where
@@ -8,6 +13,11 @@ where
813
?f1 : [ |- foo]
914
Notation "_ $ _" at level 123 with arguments constr at next level, constr
1015
at next level, no associativity.
16+
File "./output/PrintNotation.v", line 17, characters 9-14:
17+
Warning: In term, tolerating this expression at a higher level than expected.
18+
This tolerance will be eventually removed. Insert parentheses or try to lower
19+
the level at which the top symbol of this expression is parsed.
20+
[level-tolerance,deprecated-since-9.2,deprecated,parsing,default]
1121
bar (bar ?f ?f0) ?f1
1222
: foo
1323
where

test-suite/output/ltac2_match.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
File "./output/ltac2_match.v", line 12, characters 41-42:
1+
File "./output/ltac2_match.v", line 12, characters 43-44:
22
Warning: This pattern is redundant. [redundant-pattern,ltac2,default]
33
File "./output/ltac2_match.v", line 34, characters 5-51:
44
Warning: This clause is redundant. [redundant-pattern,ltac2,default]

test-suite/output/ltac2_match.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Ltac2 rec autre x := match x with
99
| D,D,_ => 3
1010
| (D|(F _ _)|(H _)|K _),_,_ => 4
1111
| (_, (D|I|E _|F _ _|H _|K _), _) => 8
12-
| (J,J,((C|D) as x |E x|F _ x)) | (J,_,((C|J) as x)) => autre (x,x,x)
12+
| (J,J,(((C|D) as x) |E x|F _ x)) | (J,_,((C|J) as x)) => autre (x,x,x)
1313
| (J, J, (I|H _|K _)) => 9
1414
| I,_,_ => 6
1515
| E _,_,_ => 7

0 commit comments

Comments
 (0)