···46464747-- | Convert an expression to a pattern.
4848--
4949+-- This is used in the parsing stage when a pattern
5050+-- is required, we parse as an expression, then coerce
5151+-- to a pattern.
5252+--
4953-- Obviously, not all expressions can be converted
5054-- in this way, but all valid patterns can be parsed
5155-- as an expression.
···5458-- using a separate parser for patterns has the benefit
5559-- that quite tricky things like tuple comma fixity is
5660-- handled the same in the patterns as the expressions
5757--- they match.
5858-checkPat :: Q.Exp T.SourcePos Var -> Parser (Q.Pattern Var)
6161+-- they match, and we don't have to duplicate parser
6262+-- logic.
6363+checkPat :: Monad m => Q.Exp T.SourcePos Var -> m (Q.Pattern Var)
5964checkPat exp =
6065 case exp of
6166 -- Variables are simple, just underscore default
+1
icicle-source/src/Icicle/Source/PrettyAnnot.hs
···8888 Lit{} -> False
8989 Fun f -> case f of
9090 BuiltinMath{} -> False
9191+ BuiltinText{} -> False
9192 BuiltinTime{} -> False
9293 BuiltinData{} -> True
9394 BuiltinArray{} -> True
+21-2
icicle-source/src/Icicle/Source/Query/Builtin.hs
···12121313data BuiltinFun
1414 = BuiltinMath !BuiltinMath
1515+ | BuiltinText !BuiltinText
1516 | BuiltinTime !BuiltinTime
1617 | BuiltinData !BuiltinData
1718 | BuiltinArray !BuiltinArray
1819 | BuiltinMap !BuiltinMap
1920 deriving (Show, Eq, Ord, Generic)
20212121--- | Functions wired into the Parser
2222--- these can't be introduced into
2222+-- | Functions wired into the Parser.
2323+-- These can't be introduced into
2324-- the environment as they are made
2425-- with KeyWords, and are instead
2526-- directly written in by the Parser.
···2829 [ fmap BuiltinTime [minBound..maxBound]
2930 ]
30313232+-- | Functions wired in through the type
3333+-- checker. These are parsed normally,
3434+-- but their definitions are wired in
3535+-- to their primitives.
3136listOfIntroducedFuns :: [BuiltinFun]
3237listOfIntroducedFuns = concat
3338 [ fmap BuiltinMath [minBound..maxBound]
3939+ , fmap BuiltinText [minBound..maxBound]
3440 , fmap BuiltinData [minBound..maxBound]
3541 , fmap BuiltinArray [minBound..maxBound]
3642 , fmap BuiltinMap [minBound..maxBound]
···5864 | Truncate
5965 deriving (Show, Eq, Ord, Enum, Bounded, Generic)
60666767+data BuiltinText
6868+ = StrLen
6969+ | ToLower
7070+ | ToUpper
7171+ deriving (Show, Eq, Ord, Enum, Bounded, Generic)
7272+6173data BuiltinTime
6274 = DaysBetween
6375 | DaysJulianEpoch
···94106instance NFData BuiltinData
95107instance NFData BuiltinMap
96108instance NFData BuiltinArray
109109+instance NFData BuiltinText
9711098111--------------------------------------------------------------------------------
99112100113instance Pretty BuiltinFun where
101114 pretty (BuiltinMath b) = pretty b
115115+ pretty (BuiltinText b) = pretty b
102116 pretty (BuiltinTime b) = pretty b
103117 pretty (BuiltinData b) = pretty b
104118 pretty (BuiltinArray b) = pretty b
···124138 pretty Ceiling = "ceil"
125139 pretty Round = "round"
126140 pretty Truncate = "trunc"
141141+142142+instance Pretty BuiltinText where
143143+ pretty StrLen = "strlen"
144144+ pretty ToLower = "tolower"
145145+ pretty ToUpper = "toupper"
127146128147instance Pretty BuiltinTime where
129148 pretty DaysBetween = "days between"
···4747builtinDefinitions a_fresh = do
4848 traverse (buildResolved a_fresh) listOfIntroducedFuns
49495050--- | Build an individual function from the its primitive definition.
5050+-- | Build an individual function from its primitive definition.
5151+--
5152-- This is a little bit tricky, as we can't under apply function
5253-- definitions, so we need to create the arguments to the function
5354-- as well. It's as if we wrote something like this in the prelude
+8
icicle-source/src/Icicle/Source/Query/Prim.hs
···111111 Fun (BuiltinMath Truncate)
112112 -> fNumDefinitely $ \at -> ([at], IntT)
113113114114+115115+ Fun (BuiltinText StrLen)
116116+ -> f0 [StringT] IntT
117117+ Fun (BuiltinText ToLower)
118118+ -> f0 [StringT] StringT
119119+ Fun (BuiltinText ToUpper)
120120+ -> f0 [StringT] StringT
121121+114122 Fun (BuiltinTime DaysBetween)
115123 -> f0 [TimeT, TimeT] IntT
116124 Fun (BuiltinTime DaysJulianEpoch)
+8
icicle-source/src/Icicle/Source/ToCore/Prim.hs
···109109110110 go (Fun (BuiltinMath f))
111111 = gomath f
112112+ go (Fun (BuiltinText f))
113113+ = gotext f
112114 go (Fun (BuiltinTime f))
113115 = gotime f
114116 go (Fun (BuiltinData f))
···214216 = convertError
215217 $ ConvertErrorPrimNoArguments ann 2 p
216218219219+ gotext StrLen
220220+ = return $ primmin $ Min.PrimText Min.PrimStrLen
221221+ gotext ToLower
222222+ = return $ primmin $ Min.PrimText Min.PrimStrToLower
223223+ gotext ToUpper
224224+ = return $ primmin $ Min.PrimText Min.PrimStrToUpper
217225218226 -- Source built-in primitives supported by other language fragments
219227 gotime DaysBetween