Commit f1c83a61 authored by Robbert Krebbers's avatar Robbert Krebbers

Simplify spec_patterns parser by using a mutual fixpoint.

parent d6e6d71e
...@@ -42,32 +42,29 @@ Inductive state := ...@@ -42,32 +42,29 @@ Inductive state :=
| StTop : state | StTop : state
| StAssert : spec_goal_kind bool list string state. | StAssert : spec_goal_kind bool list string state.
Fixpoint parse_go (ts : list token) (s : state) Fixpoint parse_go (ts : list token) (k : list spec_pat) : option (list spec_pat) :=
(k : list spec_pat) : option (list spec_pat) := match ts with
match s with | [] => Some (rev k)
| StTop => | TName s :: ts => parse_go ts (SName false s :: k)
match ts with | TBracketL :: TPersistent :: TBracketR :: ts => parse_go ts (SGoalPersistent :: k)
| [] => Some (rev k) | TBracketL :: TPure :: TBracketR :: ts => parse_go ts (SGoalPure :: k)
| TName s :: ts => parse_go ts StTop (SName false s :: k) | TBracketL :: ts => parse_goal ts GoalStd false [] k
| TBracketL :: TPersistent :: TBracketR :: ts => parse_go ts StTop (SGoalPersistent :: k) | TPvs :: TBracketL :: ts => parse_goal ts GoalPvs false [] k
| TBracketL :: TPure :: TBracketR :: ts => parse_go ts StTop (SGoalPure :: k) | TPvs :: ts => parse_go ts (SGoal GoalPvs true [] :: k)
| TBracketL :: ts => parse_go ts (StAssert GoalStd false []) k | TPersistent :: TName s :: ts => parse_go ts (SName true s :: k)
| TPvs :: TBracketL :: ts => parse_go ts (StAssert GoalPvs false []) k | TForall :: ts => parse_go ts (SForall :: k)
| TPvs :: ts => parse_go ts StTop (SGoal GoalPvs true [] :: k) | _ => None
| TPersistent :: TName s :: ts => parse_go ts StTop (SName true s :: k) end
| TForall :: ts => parse_go ts StTop (SForall :: k) with parse_goal (ts : list token) (kind : spec_goal_kind)
| _ => None (neg : bool) (ss : list string) (k : list spec_pat) : option (list spec_pat) :=
end match ts with
| StAssert kind neg ss => | TMinus :: ts => guard (¬neg ss = []); parse_goal ts kind true ss k
match ts with | TName s :: ts => parse_goal ts kind neg (s :: ss) k
| TMinus :: ts => guard (¬neg ss = []); parse_go ts (StAssert kind true ss) k | TBracketR :: ts => parse_go ts (SGoal kind neg (reverse ss) :: k)
| TName s :: ts => parse_go ts (StAssert kind neg (s :: ss)) k | _ => None
| TBracketR :: ts => parse_go ts StTop (SGoal kind neg (rev ss) :: k)
| _ => None
end
end. end.
Definition parse (s : string) : option (list spec_pat) := Definition parse (s : string) : option (list spec_pat) :=
parse_go (tokenize s) StTop []. parse_go (tokenize s) [].
Ltac parse s := Ltac parse s :=
lazymatch type of s with lazymatch type of s with
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment