-
Notifications
You must be signed in to change notification settings - Fork 26
/
Example.hs
99 lines (42 loc) · 1.3 KB
/
Example.hs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
-- For best results in ghci
-- :set -XTypeApplications
-- :set -XDataKinds
-- :set -XQuasiQuotes
-- :set -XFlexibleContexts
{-# LANGUAGE TemplateHaskell, QuasiQuotes,
DataKinds, GADTs, TypeFamilies,
TypeApplications, AllowAmbiguousTypes #-}
module RegexpExample where
import RegexpParser
import Data.Maybe (fromJust)
-- A regular expression for selecting the directories "dir" basename "base"
-- and extension "ext" from a filepath
path = [re|/?((?P<dir>[^/]+)/)*(?P<base>[^\./]+)(?P<ext>\..*)?|]
-- match the regular expression against the string
-- returning a dictionary of the matched substrings
filename = "dth/regexp/Example.hs"
dict = fromJust (match path filename)
-- Access the components of the dictionary
x = getField @"base" dict
y = getField @"dir" dict
z = getField @"ext" dict
--w = getField @"f" dict
------------------------------
-- Type computation examples
--
ra = rmark @"a" (rstar rany)
rb = rmark @"b" rany
ex1 = rb `rseq` ra
ex2 = ra `ralt` (rb `rseq` ra)
ex3 = rstar (ra `rseq` rb)
--------------------------------
-- Indexed types examples
--
entry1 :: Entry "base" Once
entry1 = E "Example"
entry2 = E @"ext" (Just "hs")
entry3 = E @"dir" ["dth", "regexp"]
d = entry1 :> entry3 :> entry2 :> Nil
------------------------------------
--
--