blob: ab86164be2a1a34fe86d9c6535023445ecf9a4b3 (
plain) (
blame)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
module Data.JLD.Model.Keyword (
Keyword (..),
parseKeyword,
isKeyword,
isNotKeyword,
allKeywords,
isKeywordLike,
) where
import Data.JLD.Prelude hiding (show)
import Data.Char (isAlpha)
import Data.Foldable qualified as F
import Data.Text qualified as T (all, null, uncons)
import Text.Show (Show (..))
data Keyword
= KeywordAny
| KeywordBase
| KeywordContainer
| KeywordContext
| KeywordDefault
| KeywordDirection
| KeywordEmbed
| KeywordExplicit
| KeywordFirst
| KeywordGraph
| KeywordId
| KeywordImport
| KeywordIncluded
| KeywordIndex
| KeywordJson
| KeywordLanguage
| KeywordList
| KeywordMerged
| KeywordNest
| KeywordNone
| KeywordNull
| KeywordOmitDefault
| KeywordPrefix
| KeywordPreserve
| KeywordPropagate
| KeywordProtected
| KeywordRequireAll
| KeywordReverse
| KeywordSet
| KeywordType
| KeywordValue
| KeywordVersion
| KeywordVocab
deriving (Eq, Ord)
instance Show Keyword where
show = \case
KeywordAny -> "@any"
KeywordBase -> "@base"
KeywordContainer -> "@container"
KeywordContext -> "@context"
KeywordDefault -> "@default"
KeywordDirection -> "@direction"
KeywordEmbed -> "@embed"
KeywordExplicit -> "@explicit"
KeywordFirst -> "@first"
KeywordGraph -> "@graph"
KeywordId -> "@id"
KeywordImport -> "@import"
KeywordIncluded -> "@included"
KeywordIndex -> "@index"
KeywordJson -> "@json"
KeywordLanguage -> "@language"
KeywordList -> "@list"
KeywordMerged -> "@merged"
KeywordNest -> "@nest"
KeywordNone -> "@none"
KeywordNull -> "@null"
KeywordOmitDefault -> "@omitDefault"
KeywordPrefix -> "@prefix"
KeywordPreserve -> "@preserve"
KeywordPropagate -> "@propagate"
KeywordProtected -> "@protected"
KeywordRequireAll -> "@requireAll"
KeywordReverse -> "@reverse"
KeywordSet -> "@set"
KeywordType -> "@type"
KeywordValue -> "@value"
KeywordVersion -> "@version"
KeywordVocab -> "@vocab"
parseKeyword :: Text -> Maybe Keyword
parseKeyword = \case
"@any" -> Just KeywordAny
"@base" -> Just KeywordBase
"@container" -> Just KeywordContainer
"@context" -> Just KeywordContext
"@default" -> Just KeywordDefault
"@direction" -> Just KeywordDirection
"@embed" -> Just KeywordEmbed
"@explicit" -> Just KeywordExplicit
"@first" -> Just KeywordFirst
"@graph" -> Just KeywordGraph
"@id" -> Just KeywordId
"@import" -> Just KeywordImport
"@included" -> Just KeywordIncluded
"@index" -> Just KeywordIndex
"@json" -> Just KeywordJson
"@language" -> Just KeywordLanguage
"@list" -> Just KeywordList
"@merged" -> Just KeywordMerged
"@nest" -> Just KeywordNest
"@none" -> Just KeywordNone
"@null" -> Just KeywordNull
"@omitDefault" -> Just KeywordOmitDefault
"@prefix" -> Just KeywordPrefix
"@preserve" -> Just KeywordPreserve
"@propagate" -> Just KeywordPropagate
"@protected" -> Just KeywordProtected
"@requireAll" -> Just KeywordRequireAll
"@reverse" -> Just KeywordReverse
"@set" -> Just KeywordSet
"@type" -> Just KeywordType
"@value" -> Just KeywordValue
"@version" -> Just KeywordVersion
"@vocab" -> Just KeywordVocab
_ -> Nothing
isKeyword :: Foldable f => Text -> f Keyword -> Bool
isKeyword (parseKeyword -> Just keyword) (F.elem keyword -> True) = True
isKeyword _ _ = False
isNotKeyword :: Foldable f => Text -> f Keyword -> Bool
isNotKeyword s = isKeyword s .> not
allKeywords :: Foldable f => f Text -> f Keyword -> Bool
allKeywords values keywords = all (`isKeyword` keywords) values
isKeywordLike :: Text -> Bool
isKeywordLike (T.uncons -> Just ('@', res)) = not (T.null res) && T.all isAlpha res
isKeywordLike _ = False
|