Skip to content

Commit f616381

Browse files
Merge pull request #9 from LindenRegex/vs/autoformalization/fix-semantics
Align with spec: fix semantic issues and missing assertions
2 parents cb79b54 + a7d33fc commit f616381

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

mechanization/props/StrictlyNullable.v

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ Proof.
375375
CompiledQuantifier_max (compileQuantifier q))%NoI); [ discriminate |].
376376
inversion COMPILE as [M].
377377
clear COMPILE M m.
378+
change (countLeftCapturingParensBefore (Quantified r q) ctx)
379+
with (countLeftCapturingParensBefore r ctx).
378380
apply repeat_matcher_sn with (root:=root); auto.
379381
unfold repeatMatcherFuel. lia.
380382
(* concatenation *)
@@ -417,7 +419,7 @@ Proof.
417419
rewrite NOFAIL. rewrite Nat.add_sub.
418420
(* the update is independent of the direction *)
419421
match goal with
420-
| [ |- context[(if ?c then ?i else ?e)]] => replace (if c then i else e) with e
422+
| [ |- context[(if ?c then ?i else ?e)]] => replace (if c then i else e) with i
421423
end.
422424
2: { destruct dir; auto. } simpl.
423425
destruct (List.Update.Nat.One.update (CaptureRange_or_undefined (CaptureRange.make (endIndex y) (endIndex y))) (captures y) (countLeftCapturingParensBefore (Group name r) ctx)) eqn:UPD.
@@ -567,6 +569,9 @@ Proof.
567569
unfold Coercions.wrap_Matcher in COMPILESTAR. inversion COMPILESTAR as [STAR]. clear COMPILESTAR.
568570
apply strictly_nullable_repeatmatcher' with (x:=x) (c:=c) (root:=root) in SUBSTAR; auto.
569571
simpl in SUBSTAR. rewrite PeanoNat.Nat.add_0_r in SUBSTAR.
570-
unfold repeatMatcher. rewrite SUBSTAR. auto.
572+
unfold repeatMatcher.
573+
change (countLeftCapturingParensBefore (Quantified r (Greedy Star)) ctx)
574+
with (countLeftCapturingParensBefore r ctx).
575+
rewrite SUBSTAR. auto.
571576
Qed.
572577
End StriclyNullable.

mechanization/spec/Semantics.v

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ Module Semantics. Section main.
387387
(*>> 3. Return the union of CharSets A and B. <<*)
388388
CharSet.union A B
389389

390-
(** >> NonemptyClassRangesNoDash :: ClassAtomNoDash - ClassAtom ClassRanges <<*)
390+
(** >> [OMITTED] NonemptyClassRangesNoDash :: ClassAtomNoDash - ClassAtom ClassRanges <<*)
391391
(*>> 1. Let A be CompileToCharSet of ClassAtomNoDash with argument rer. <<*)
392392
(*>> 2. Let B be CompileToCharSet of ClassAtom with argument rer. <<*)
393393
(*>> 3. Let C be CompileToCharSet of ClassRanges with argument rer. <<*)
@@ -512,15 +512,15 @@ Module Semantics. Section main.
512512
(*>> 9. If greedy is false, then <<*)
513513
if greedy is false then
514514
(*>> a. Let z be c(x). <<*)
515-
let! z =<< c x in
515+
let z := c x in
516516
(*>> b. If z is not failure, return z. <<*)
517517
if z != failure
518518
then z else
519519
(*>> c. Return m(xr, d). <<*)
520520
m xr d
521521
else
522522
(*>> 10. Let z be m(xr, d). <<*)
523-
let! z =<< m xr d in
523+
let z := m xr d in
524524
(*>> 11. If z is not failure, return z. <<*)
525525
if z != failure
526526
then z else
@@ -614,7 +614,7 @@ Module Semantics. Section main.
614614
(*>> 3. Assert: q.[[Min]] ≤ q.[[Max]]. <<*)
615615
assert! (CompiledQuantifier_min q <=? CompiledQuantifier_max q)%NoI;
616616
(*>> 4. Let parenIndex be CountLeftCapturingParensBefore(Term). <<*)
617-
let parenIndex := countLeftCapturingParensBefore r ctx in
617+
let parenIndex := countLeftCapturingParensBefore self ctx in
618618
(*>> 5. Let parenCount be CountLeftCapturingParensWithin(Atom). <<*)
619619
let parenCount := countLeftCapturingParensWithin r (Quantified_inner qu :: ctx) in
620620
(*>> 6. Return a new Matcher with parameters (x, c) that captures m, q, parenIndex, and parenCount and performs the following steps when called: <<*)
@@ -647,7 +647,7 @@ Module Semantics. Section main.
647647
(*>> d. Let e be x's endIndex. <<*)
648648
let e := MatchState.endIndex x in
649649
(*>> e. If e = 0, or if rer.[[Multiline]] is true and the character Input[e - 1] is matched by LineTerminator, then <<*)
650-
if! (e =? 0)%Z ||! ((RegExpRecord.multiline rer is true) &&! (let! c =<< input[(e-1)%Z] in CharSet.contains Characters.line_terminators c)) then
650+
if! (e =? 0)%Z ||! ((RegExpRecord.multiline rer is true) &&! (let! d =<< input[(e-1)%Z] in CharSet.contains Characters.line_terminators d)) then
651651
(*>> i. Return c(x). <<*)
652652
c x
653653
else
@@ -667,7 +667,7 @@ Module Semantics. Section main.
667667
(*>> e. Let InputLength be the number of elements in Input. <<*)
668668
let inputLength := List.length input in
669669
(*>> f. If e = InputLength, or if rer.[[Multiline]] is true and the character Input[e] is matched by LineTerminator, then <<*)
670-
if! (e =? inputLength)%Z ||! ((RegExpRecord.multiline rer is true) &&! (let! c =<< input[e] in CharSet.contains Characters.line_terminators c)) then
670+
if! (e =? inputLength)%Z ||! ((RegExpRecord.multiline rer is true) &&! (let! d =<< input[e] in CharSet.contains Characters.line_terminators d)) then
671671
(*>> i. Return c(x). <<*)
672672
c x
673673
else
@@ -846,7 +846,7 @@ Module Semantics. Section main.
846846
(*>> 1. Let ch be the character matched by PatternCharacter. <<*)
847847
let ch := c in
848848
(*>> 2. Let A be a one-element CharSet containing the character ch. <<*)
849-
let A := CharSet.singleton c in
849+
let A := CharSet.singleton ch in
850850
(*>> 3. Return CharacterSetMatcher(rer, A, false, direction). <<*)
851851
characterSetMatcher rer A false direction
852852

@@ -901,6 +901,7 @@ Module Semantics. Section main.
901901
(*>> vii. Else, <<*)
902902
else
903903
(*>> 1. Assert: direction is backward. <<*)
904+
assert! (direction == backward) ;
904905
(*>> 2. Assert: ye ≤ xe. <<*)
905906
assert! (ye <=? xe)%Z ;
906907
(*>> 3. Let r be the CaptureRange (ye, xe). <<*)
@@ -932,16 +933,16 @@ Module Semantics. Section main.
932933
(*>> 2. Let ch be the character whose character value is cv. <<*)
933934
let ch := Character.from_numeric_value cv in
934935
(*>> 3. Let A be a one-element CharSet containing the character ch. <<*)
935-
let a := CharSet.singleton ch in
936+
let A := CharSet.singleton ch in
936937
(*>> 4. Return CharacterSetMatcher(rer, A, false, direction). <<*)
937-
characterSetMatcher rer a false direction
938+
characterSetMatcher rer A false direction
938939

939940
(** >> AtomEscape :: CharacterClassEscape <<*)
940941
| AtomEsc (ACharacterClassEsc cce) =>
941942
(*>> 1. Let A be CompileToCharSet of CharacterClassEscape with argument rer. <<*)
942-
let! a =<< compileToCharSet cce rer in
943+
let! A =<< compileToCharSet cce rer in
943944
(*>> 2. Return CharacterSetMatcher(rer, A, false, direction). <<*)
944-
characterSetMatcher rer a false direction
945+
characterSetMatcher rer A false direction
945946

946947
(** >> AtomEscape :: k GroupName <<*)
947948
| AtomEsc (GroupEsc gn) =>

0 commit comments

Comments
 (0)