1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
From stdpp Require Export strings.
From iris.proofmode Require Import base tokens.
From iris.prelude Require Import options.
Inductive sel_pat :=
| SelPure
| SelIntuitionistic
| SelSpatial
| SelIdent : ident → sel_pat.
Fixpoint sel_pat_pure (ps : list sel_pat) : bool :=
match ps with
| [] => false
| SelPure :: ps => true
| _ :: ps => sel_pat_pure ps
end.
Module sel_pat.
Fixpoint parse_go (ts : list token) (k : list sel_pat) : option (list sel_pat) :=
match ts with
| [] => Some (reverse k)
| TName s :: ts => parse_go ts (SelIdent s :: k)
| TPure None :: ts => parse_go ts (SelPure :: k)
| TIntuitionistic :: ts => parse_go ts (SelIntuitionistic :: k)
| TSep :: ts => parse_go ts (SelSpatial :: k)
| _ => None
end.
Definition parse (s : string) : option (list sel_pat) :=
parse_go (tokenize s) [].
Ltac parse s :=
lazymatch type of s with
| sel_pat => constr:([s])
| list sel_pat => s
| ident => constr:([SelIdent s])
| list ident => eval vm_compute in (SelIdent <$> s)
| list string => eval vm_compute in (SelIdent ∘ INamed <$> s)
| string =>
lazymatch eval vm_compute in (parse s) with
| Some ?pats => pats
| _ => fail "sel_pat.parse: cannot parse" s "as a selection pattern"
end
| ?X => fail "sel_pat.parse: the term" s
"is expected to be a selection pattern"
"(usually a string),"
"but has unexpected type" X
end.
End sel_pat.
|