sel_patterns.v 1.06 KB
Newer Older
Robbert Krebbers's avatar
Robbert Krebbers committed
1
From fast_string Require Export fast_string_lib.
2
From iris.proofmode Require Import tokens.
3
Set Default Proof Using "Type".
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Inductive sel_pat :=
  | SelPure
  | SelPersistent
  | SelSpatial
  | SelName : string  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.
19
20
21
22
23
24
25
26
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 (SelName s :: k)
  | TPure :: ts => parse_go ts (SelPure :: k)
  | TAlways :: ts => parse_go ts (SelPersistent :: k)
  | TSep :: ts => parse_go ts (SelSpatial :: k)
  | _ => None
27
  end.
28
29
Definition parse (s : string) : option (list sel_pat) :=
  parse_go (tokenize s) [].
30
31
32
33
34

Ltac parse s :=
  lazymatch type of s with
  | list sel_pat => s
  | list string => eval vm_compute in (SelName <$> s)
35
36
37
38
  | string =>
     lazymatch eval vm_compute in (parse s) with
     | Some ?pats => pats | _ => fail "invalid sel_pat" s
     end
39
40
  end.
End sel_pat.