Debian Codegraph @

src/Text/Regex/Properties.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties of regular expressions and their semantics
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 open import Relation.Binary.Bundles using (DecPoset)
10
11 module Text.Regex.Properties {a e r} (P? : DecPoset a e r) where
12
13 open import Data.List.Base using (List; []; _∷_)
14 open import Data.List.Relation.Unary.All using (all?)
15 open import Data.List.Relation.Unary.Any using (any?)
16 open import Data.Product.Base using (_×_; _,_; uncurry)
17 open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
18 open import Function.Base using (_$_)
19
20 open import Relation.Nullary.Decidable
21 using (Dec; yes; no; map′; ¬?; _×-dec_; _⊎-dec_)
22 open import Relation.Nullary.Negation
23 using (¬_; contradiction)
24
25 import Relation.Unary as U
26 open import Relation.Binary.Definitions using (Decidable)
27
28 open DecPoset P? renaming (Carrier to A)
29 open import Text.Regex.Base preorder
30 open import Data.List.Relation.Binary.Pointwise.Base using ([])
31 open import Data.List.Relation.Ternary.Appending.Propositional {A = A}
32 open import Data.List.Relation.Ternary.Appending.Propositional.Properties {A = A}
33
34 ------------------------------------------------------------------------
35 -- Publicly re-export core properties
36
37 open import Text.Regex.Properties.Core preorder public
38
39 ------------------------------------------------------------------------
40 -- Decidability results
41
42 []∈?_ : U.Decidable ([] ∈_)
43 []∈? ε = yes ε
44 []∈? [ rs ] = no (λ ())
45 []∈? [^ rs ] = no (λ ())
46 []∈? (e ∣ f) = map′ sum (λ where (sum pr) → pr)
47 $ ([]∈? e) ⊎-dec ([]∈? f)
48 []∈? (e ∙ f) = map′ (uncurry (prod ([]++ []))) []∈e∙f-inv
49 $ ([]∈? e) ×-dec ([]∈? f)
50 []∈? (e ⋆) = yes (star (sum (inj₁ ε)))
51
52 infix 4 _∈ᴿ?_ _∉ᴿ?_ _∈?ε _∈?[_] _∈?[^_]
53
54 _∈ᴿ?_ : Decidable _∈ᴿ_
55 c ∈ᴿ? [ a ] = map′ [_] (λ where [ eq ] → eq) (c ≟ a)
56 c ∈ᴿ? (lb ─ ub) = map′ (uncurry _─_) (λ where (ge ─ le) → ge , le)
57 $ (lb ≤? c) ×-dec (c ≤? ub)
58
59 _∉ᴿ?_ : Decidable _∉ᴿ_
60 a ∉ᴿ? r = ¬? (a ∈ᴿ? r)
61
62 _∈?ε : U.Decidable (_∈ ε)
63 [] ∈?ε = yes ε
64 (a ∷ _) ∈?ε = no (λ ())
65
66 _∈?[_] : ∀ w rs → Dec (w ∈ [ rs ])
67 [] ∈?[ rs ] = no (λ ())
68 (a ∷ b ∷ _) ∈?[ rs ] = no (λ ())
69 (a ∷ []) ∈?[ rs ] = map′ [_] (λ where [ p ] → p)
70 $ any? (a ∈ᴿ?_) rs
71
72 _∈?[^_] : ∀ w rs → Dec (w ∈ [^ rs ])
73 [] ∈?[^ rs ] = no (λ ())
74 (a ∷ []) ∈?[^ rs ] = map′ [^_] (λ where [^ p ] → p) $ all? (a ∉ᴿ?_) rs
75 (a ∷ b ∷ _) ∈?[^ rs ] = no (λ ())