Debian Codegraph @

tests/text/regex/Main.agda

raw
1 {-# OPTIONS --guardedness #-}
2
3 module Main where
4
5 open import Data.Bool.Base using (true; false)
6 open import Data.List.Base using (_∷_; [])
7 open import Data.List.Relation.Binary.Infix.Heterogeneous using (toView; MkView)
8 open import Data.String using (String; toList; fromList; lines; concat)
9 open import IO
10 open import Function.Base using (_$_; case_of_)
11 open import Relation.Binary.PropositionalEquality using (_≡_)
12 open import Relation.Nullary
13 open import Text.Regex.String
14
15 show : ∀ e {xs} → Dec (Match (Span e _≡_) xs (Regex.expression e)) → String
16 show _ (no _) = "No match found"
17 show e (yes match) = case toView (toInfix e (match .Match.related)) of λ where
18 (MkView pref x suff) → concat
19 $ "Match found: "
20 ∷ fromList pref
21 ∷ "["
22 ∷ fromList (match .Match.list)
23 ∷ "]"
24 ∷ fromList suff
25 ∷ []
26
27 agdaFile : Exp
28 agdaFile = [ 'a' ─ 'z' ∷ 'A' ─ 'Z' ∷ [] ] +
29 ∙ singleton '.'
30 ∙ singleton 'a'
31 ∙ singleton 'g'
32 ∙ singleton 'd'
33 ∙ singleton 'a'
34
35 buildDir : Exp
36 buildDir = singleton '_'
37 ∙ ([ 'a' ─ 'z' ∷ 'A' ─ 'Z' ∷ [] ] + ∙ singleton '/') +
38
39 regex : Regex
40 regex .Regex.fromStart = false
41 regex .Regex.tillEnd = false
42 regex .Regex.expression
43 = agdaFile ∣ buildDir
44
45 main : Main
46 main = run $ do
47 text ← readFiniteFile "run"
48 List.forM′ (lines text) $ λ l →
49 putStrLn (show regex $ search (toList l) regex)