-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMain.purs
More file actions
555 lines (371 loc) · 9.75 KB
/
Main.purs
File metadata and controls
555 lines (371 loc) · 9.75 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
-- start
{- Test file to visually assess syntax highlighting. -}
module Main.App where
module Main.App
( main
) where
import Prelude -- can comment
import Prelude hiding (div)
import Data.String as String
-- comment
import Data.String (Pattern) -- comment
import Data.String (Pattern(..), split) as String -- comment
-- multi-line import
import Data.String
( Pattern(..), split -- comment
) as String -- comment
import Something (fd)
-- Foreign import
foreign
foreign import --comment
foreign import data --comment
foreign import calculateInterest :: Number -> Number --comment
foreign import data F :: Type -> Type --comment
foreign import databaseName :: Db -> Name
-- import data with record type
foreign import data R :: { prop :: String }
-- line comments with no space between first char
--| some
-- comments with operators after
--# some
--! some
-- Containers
data D a = D1 a | D2 (Array a) --comment
--
data D1 a
= D1 a
| D2 (Array Some.Type)
{- comment inside -}
| D3 (Either Aff.Error Db.Client)
| D4
(Array Some.Type) --comment
| D5 String
Int
| S1 (forall f. f String -> f a)
type T = { a :: String } --comment
type T a = { n :: N a, b :: String }
newtype N a = N a
data Proxy :: forall k. k -> Type
data Proxy a = Proxy
-- newtype with multi-line kind signature
newtype MySub ::
forall k. (k -> Type) -> k -> Type --comment
newtype MySub vnode msg =
MySub (SubRec vnode msg)
-- infix operators (with numbers in hame)
-- operators that contain -- within
infixr 0 apply2 as :--> -- comment as :-->
infixl 0 apply2Flipped as <--:
---
data Sum a b
= Inl a
| Inr b --comment
data Product a b = Product a b
-- Type operators
infixl 6 type Sum as :+: -- comment
infixl 7 type Product as :*:
-- Ctor operators
infixl 2 Inl as $%
infixr 2 Inr as %$
-- type class signatures
class Category :: forall k. (k -> k -> Type) -> Constraint
class Semigroupoid a <= Category a where
identity :: forall t. a t t
-- type class without where
class ListToRow :: forall k. RowList k -> Row k -> Constraint
class ListToRow list row | list -> row
class Functor v <= Mountable vnode where
mount :: ∀ m. Element -> T Void (v m)
unmount :: ∀ m. v m -> v m -> T Void E
--| orphan keyword
class
-- multi-line type def
class Functor v
<= Mountable vnode where --comment
mount :: ∀ m. Element -> T Void (v m)
unmount :: ∀ m. v m -> v m -> T Void E
-- class with row type
class RowTypeClass (rl :: RL.RowList Type) where
rowListCodec :: forall proxy. proxy rl -> Record ri -> CA.JPropCodec (Record ro)
instance
instance listToRowCons
:: ( ListToRow tail tailRow
, Row.Cons label ty tailRow row ) --comment
=> ListToRow (Cons label ty tail) row
--orphan keyword
derive
derive instance newtypeMySub :: Newtype (MySub vnode msg) _ --comment
derive newtype
derive newtype instance semiringScore :: Semiring Score
-- instance without name
derive newtype instance Semiring Score
-- multi-line derive
derive instance genericCmd
:: Generic PhonerCmd _
-- attached derive clauses
newtype TodoId = TodoId UUID
derive (Newtype)
derive newtype (Eq, Ord, Show)
derive (ReadForeign, WriteForeign) via Int
data Color = Red | Green | Blue
derive (Eq, Ord, Show)
newtype Score = Score Int
derive newtype (Semiring, Ring)
newtype Wrapper = Wrapper String
derive (Generic)
derive (Encode, Decode) via String
derive newtype (Eq)
-- TODO: multi-line, double-colons
derive instance genericCmd ::
Generic PhonerCmd _
-- multi-line instance
instance encodeCmd
:: EncodeJson PhonerCmd where --comment
encodeJson a = genericEncodeJson a
instance functorA :: Functor A where
map = split
instance functorA :: Functor A where
map = split -- comment
-- chained instances
class MyShow a where
myShow :: a -> String
instance showString :: MyShow String where
myShow s = s
-- chained instances
else instance showBoolean :: MyShow Boolean where
myShow true = "true" --comment
myShow false = "false"
else instance showA :: MyShow a where
myShow _ = "Invalid"
else newtype instance showA :: MyShow a where
-- Records with fields that are reserved words
-- quoted row type
type QuotedRow a =
( "A" :: Int
-- comment
, "B" :: { nested :: Number, nested2 :: { x :: Maybe (Array Int) } | a }
, "C" :: { | (c :: Int) }
{- block comment inside -}
, c :: Either (Maybe Bad) Int
, d :: Some.Int -- comment
, e :: Some.Int -- comment
| a
) --som
data Rec =
{ module :: String -- comment
, import :: Either Error (Array String)
, import2 :: Either (Maybe Bad) Good
-- comment
, data :: String
, newtype :: String
}
-- https://github.com/purescript/purescript-in-purescript/blob/master/src/Language/PureScript/Keywords.purs
rec =
{ data: "data"
, type: "type"
, foreign: "foreign"
, import: "import"
, infixl: "infixl"
, infixr: "infixr"
, infix: "infix"
, class: "class"
, instance: "instance"
, case: case some of _ -> 1
, of: "of"
, if: "if"
, then: "then"
, else: "else"
, do: "do"
, let: "let"
-- no big reason to strive to make true/false not highlighted here
, true: "true"
, false: "false"
, in: "in"
, where: "where"
, forall: "forall"
, module: "module"
}
updateRec = rec
{ data = "data"
, type ="type" -- comment
, foreign = "foreign"
, import = "import"
, infixl = "infixl" -- comment
, infixr = "infixr"
, infix = "infix"
, class = "class"
, instance = "instance"
, case = case some of _ -> 1
, of = "of"
, if = if true then "true" else "false"
, then = "then"
, else = "else"
, do = "do"
, let = "let"
, true = true
, false = false
, in = "in"
, where = "where"
, forall = "forall"
, module = "module"
}
type RowLineSpacing a = ( name :: String, age :: { nested :: Number } | a )
--one line row type with no spaces after/before braces
type RowLine a = (names :: Maybe (Array String), age :: { nested :: Number } | a)
type RowLine a = { | }
type RowLine a = { | a }
type RowLine a = { | (a :: Maybe (Array a)) }
type RowRecord a
= Record
( RowLine ( some :: Either Error (Array a) )
)
type RowRecordLine = Record ( RowLine ( some :: String ) )
type EntireRecordCodec = T "Str" ( a :: String , "B" :: Boolean )
type NotRow a = Either Error (Array Int)
-- record with quoted fields
type Quoted =
{ "A" :: Int -- comment
, a :: Boolean
, "B" :: Number
, b :: Int -- comment
, "x" :: SmallCap
}
-- inlined record type def inside foreign import
foreign import createSource ::
String ->
{ onOpen :: Effect Unit
, onMessage :: SourceEvent -> Effect Unit
, onError :: SourceError -> Effect Unit
, withCredentials :: Boolean
} ->
Effect EventSource
-- no proper after quote
wow'X2 = 1
wow_X = 1
wow_2 = 1
-- typed hole
foo :: List Int -> List Int
foo = map ?myHole
-- infix functions
infixFun = 1 `add` 2
-- infix function with params
infixFun = 1 `flip add` 2
-- function declaration, do, where
toStr :: forall a. Functor a => { a :: a } -> Effect Unit --comment
toStr x = do
log $ show num
log $ show $ 1 `add` 2
where
-- indented type signature
num :: Int
num = ((something :: Int) :: Int)
str = "Str"
-- double_colon_inlined_signature
gotConfig :: AVar { a :: Unit } <- AVar.empty
-- INLINE SIGNATURES
-- inlined record type def
quoted ::
{ "A" :: Int -- comment
, a :: Boolean
, "B" :: Number
, b :: Int -- comment
, "x" :: SmallCap
}
quoted =
{ "A": "a" -- comment
, "B": fn (1 :: Int) x 2 -- typed param in parens
, "C": 1 :: Proxy "xxx" -- typed param without parens
, "C": (1 :: Maybe (Array Int) ) x (1 :: Proxy "xxx")
, a: 2
}
-- proxy
p :: Proxy "xxx"
p = Proxy
proxy = Proxy :: Proxy Int -- k is Type
-- orphan inline signature
x = 1
::
Int
x = {a: 1} ::
{ | (a :: Int) }
-- row type
-- no proper for ctor variant tag value (double_colon_inlined)
injFoo :: forall r. Variant ( foo :: Int | r )
injFoo = inj (Proxy :: Proxy "foo") P.ddd Cons (some)
-- operators inside type signature ==>
type Schema
= { widgets :: { id :: Int } ==> Array Widget --comment
}
px = Proxy :: Proxy "fdsfsdf"
-- quotes after type def
px = Proxy :: Proxy """fdsfsdf
fdsfdsfsdf
"""
px = Proxy :: Proxy """fdsfsdffdsfdsfsdf"""
px =
({ x = Set.empty :: Set X { x :: Int } } /\ X)
where
y = 1
-- double colons in string inside parens
x = ((x :: Int) "func1 ::" <> "func1 ::" <> ((show 1) :: Proxy "x" ))
-- code coloring after end of quotes
text = (" ::" + global)
text = (""" ::""" + global)
-- signatures in ide tooltips
SomeType :: (a :: Int)
-- we may not distinct Type names from type ctors
-- so we highlight as ctors
AVar :: Type → Type
--
-- addIf true = singleton
addIf false = const []
-- fn type signature without (arrow first style) :: in the same line lacks
-- highlighting it seems to be a bit harder case for proper handling maybe it's
-- also a sign that it is better not to have it in the code :-)
fn
-- line orphan signature
:: forall a. a -> String
fn a =
-- let in, case of
let b = "str"
in case a of
"1" -> b + "1"
_ -> b + a
-- arrow first signature multiline
_run
:: forall m
. Functor m
=> Config
-> SpecT Aff Unit m Unit
-> m TestEvents
_run c s = some
where
-- arrow first signature indented
some
:: Int
some = 1
-- if' fn and if statement with
if' = if true then "false" else "true"
-- true'
true' = if false then "false" else "true"
-- false'
false' = if false then true' else "false"
case' = if true
then if'
else "true"
-- constants
int = 1
decimal = 41.0
hex = 0xE0
-- quotes after type def
multiString = """
'text' "WOW" text
"""
multiStringOneLine = """ "WOW" text """
-- after mult-line string
class Foo (a :: Symbol)
replaceUnicode :: String -> String
replaceUnicode text =
text
(Pattern ":: forall") (Replacement ":: ∀")
--no proper after this