Skip to content

Commit a28890a

Browse files
committed
fix issues with row types and other
1 parent 836d758 commit a28890a

File tree

2 files changed

+108
-106
lines changed

2 files changed

+108
-106
lines changed

src/purescript.coffee

Lines changed: 76 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ purescriptGrammar =
114114
include: '#data_ctor'
115115
,
116116
include: '#infix_op'
117-
,
118-
include: '#double_colon_inlined_signature'
119117
,
120118
include: '#constants_numeric_decimal'
121119
,
@@ -133,10 +131,12 @@ purescriptGrammar =
133131
include: '#markup_newline'
134132
,
135133
include: '#double_colon_parens'
134+
,
135+
include: '#double_colon_inlined'
136136
,
137137
include: '#double_colon_orphan'
138138
,
139-
include: '#comments'
139+
include: '#comments'
140140
,
141141
name: 'keyword.other.arrow'
142142
match: /\<-|-\>/
@@ -535,42 +535,45 @@ purescriptGrammar =
535535
0: name: 'punctuation.definition.string.end'
536536
]
537537

538-
# double_colon_parens:
539-
# patterns: [
540-
# # Note recursive regex matching nested parens
541-
# match: [
542-
# '\\(',
543-
# '(?<paren>(?:[^()]|\\(\\g<paren>\\))*)',
544-
# '(::|∷)',
545-
# '(?<paren2>(?:[^()]|\\(\\g<paren2>\\))*)',
546-
# '\\)'
547-
# ].join('')
548-
# captures:
549-
# 1: patterns: [
550-
# include: '$self'
551-
# ]
552-
# 2: name: 'keyword.other.double-colon'
553-
# 3: {name: 'meta.type-signature', patterns: [include: '#type_signature']}
554-
# ]
555-
556-
double_colon_inlined_signature:
538+
# for inline signatures with parens
539+
double_colon_parens:
557540
patterns: [
558-
patterns: [
559-
match: '(SomeType)\s*({doubleColon})(.*)'
560-
captures:
561-
1: name: 'meta.type-signature'
562-
2: name: 'keyword.other.double-colon'
563-
3: {name: 'meta.type-signature', patterns: [include: '#type_signature']}
541+
# Note recursive regex matching nested parens
542+
match: [
543+
'\\(',
544+
'(?<paren>(?:[^()]|\\(\\g<paren>\\))*)',
545+
'(::|∷)',
546+
'(?<paren2>(?:[^()]|\\(\\g<paren2>\\))*)',
547+
'\\)'
548+
].join('')
549+
captures:
550+
1: patterns: [
551+
include: '$self'
552+
]
553+
2: name: 'keyword.other.double-colon'
554+
3: {name: 'meta.type-signature', patterns: [include: '#type_signature']}
555+
]
564556

565-
]
566-
,
557+
# for inline signatures without parens
558+
double_colon_inlined:
559+
patterns: [
560+
# signatures in ide tooptips (starts from new line)
561+
# patterns: [
562+
# match: '^({classNameOne})(?: +)({doubleColon})(.*)'
563+
# captures:
564+
# 1: {name: 'meta.type-signature', patterns: [include: '#type_signature']}
565+
# 2: name: 'keyword.other.double-colon'
566+
# 3: {name: 'meta.type-signature', patterns: [include: '#type_signature']}
567+
# ]
568+
# ,
567569
patterns: [
568-
match: '({doubleColon})(.*)(<-)'
570+
match: '({doubleColon})(.*)(?=<-|")'
569571
captures:
570572
1: name: 'keyword.other.double-colon'
571-
2: {name: 'meta.type-signature', patterns: [ include: '#type_signature']}
572-
3: name: 'keyword.other.double-colon'
573+
2: {name: 'meta.type-signature', patterns: [
574+
include: '#type_signature'
573575

576+
]}
574577
]
575578
,
576579
patterns: [
@@ -587,61 +590,13 @@ purescriptGrammar =
587590

588591
]
589592
]
590-
591-
_double_colon_inlined_signature:
592-
patterns: [
593-
# Note recursive regex matching nested parens
594-
# match: '\\((?<paren>(?:[^()]|\\(\\g<paren>\\))*)(::|∷)(?<paren2>(?:[^()]|\\(\\g<paren2>\\))*)\\)'
595-
match: [
596-
# '\\(',
597-
# '(?<paren>(?:[^()]|\\(\\g<paren>\\))*)',
598-
'(::|∷)',
599-
#'(?<paren2>(?:[^()]|\\(\\g<paren2>\\))*)',
600-
'(.*)',
601-
# '\\)'
602-
].join('')
603-
captures:
604-
# 1: patterns: [
605-
# include: '$self'
606-
# ]
607-
1: name: 'keyword.other.double-colon'
608-
2: {name: 'meta.type-signature', patterns: [include: '#type_signature']}
609-
]
610-
611-
double_colon_parens:
612-
patterns: [
613-
# Note recursive regex matching nested parens
614-
# Here we will only match parens with :: inside
615-
match: [
616-
'\\(',
617-
# '(?<paren>(?:[^()]|\\(\\g<paren>\\))*)',
618-
'(?<paren>(?:[^()]*(::|∷)[^()]*|\\(\\g<paren>\\)*))',
619-
# '(::|∷)',
620-
# '(?<paren2>(?:[^()]|\\(\\g<paren2>\\))*)',
621-
'\\)'
622-
].join('')
623-
# match: [
624-
# '\\((?<paren>(?:[^()]|\\(\\g<paren>\\))*)',
625-
# '(::|∷)',
626-
# '(?<paren2>(?:[^()]|\\(\\g<paren2>\\))*)',
627-
# '\\)'
628-
# ].join('')
629-
captures:
630-
1: patterns: [
631-
# include: "#string_double_quoted"
632-
# ,
633-
# include: '#double_colon_inlined_signature'
634-
#,
635-
include: '$self'
636-
]
637-
]
638-
639593
double_colon_orphan:
640594
patterns: [
641595
begin: ///
642-
^
643596
( \s* )
644597
(?: ( :: | ∷ ) )
598+
( \s* )
599+
$
645600
///
646601
beginCaptures:
647602
2: name: 'keyword.other.double-colon'
@@ -653,6 +608,23 @@ purescriptGrammar =
653608
include: '#type_signature'
654609
]
655610
]
611+
# double_colon_orphan:
612+
# patterns: [
613+
# begin: ///
614+
# ^
615+
# ( \s* )
616+
# (?: ( :: | ∷ ) )
617+
# ///
618+
# beginCaptures:
619+
# 2: name: 'keyword.other.double-colon'
620+
# end: ///
621+
# ^
622+
# (?! \1 {indentChar}* | {indentChar}* $ )
623+
# ///
624+
# patterns: [
625+
# include: '#type_signature'
626+
# ]
627+
# ]
656628

657629
markup_newline:
658630
patterns: [
@@ -793,14 +765,21 @@ purescriptGrammar =
793765
because there doesn't seem to be a correct way to distinguish row type declaration
794766
from another types put in brackets.
795767
###
796-
begin: /\((?= \s*({functionNameOne}|"{functionNameOne}"|"{classNameOne}")\s*(::|∷))/
797-
end: / \)/
768+
# begin: /\((?= \s*({functionNameOne}|"{functionNameOne}"|"{classNameOne}")\s*(::|∷))/
769+
# end: / \)/
770+
begin: /\((?=\s*({functionNameOne}|"{functionNameOne}"|"{classNameOne}")\s*(::|∷))/
771+
end: /(?=^\S)/
772+
798773
#applyEndPatternsLast: true
799774
patterns: [
800-
# name: 'punctuation.separator.comma.purescript'
801-
# match: ','
802-
# ,
803-
include: '#record_field_declaration'
775+
name: 'punctuation.separator.comma.purescript'
776+
match: ','
777+
,
778+
include: '#comments'
779+
,
780+
include: '#record_field_declaration'
781+
,
782+
include: '#type_signature'
804783
]
805784
]
806785

@@ -821,16 +800,19 @@ purescriptGrammar =
821800
match: ','
822801
,
823802
include: '#comments'
803+
824804
,
825805
include: '#record_field_declaration'
806+
,
807+
include: '#type_signature'
826808
]
827809
]
828810

829811
record_field_declaration:
830812
name: 'meta.record-field.type-declaration'
831813
begin: /{recordFieldDeclaration}/
832814
# we use end pattern of " )" with space (as as row type ending)
833-
end: /(?={recordFieldDeclaration}|}| \))/
815+
end: /(?={recordFieldDeclaration}|}| \)|{indentBlockEnd})/
834816
# applyEndPatternsLast: true
835817
contentName: 'meta.type-signature'
836818
beginCaptures:
@@ -845,16 +827,13 @@ purescriptGrammar =
845827
]
846828
2: name: 'keyword.other.double-colon'
847829
patterns: [
848-
# # row type pipe
849-
# match: /\|(?=\s*{functionNameOne})/
850-
# captures:
851-
# 0: name: 'punctuation.separator.pipe'
852-
# ,
853830
include: '#record_types'
854831
# ,
855832
# include: '#row_types'
856833
,
857834
include: '#type_signature'
835+
# ,
836+
# include: '#record_field_declaration'
858837
,
859838
include: '#comments'
860839
]
@@ -878,8 +857,8 @@ purescriptGrammar =
878857
patterns: [
879858
include: "#record_types"
880859
,
881-
include: '#row_types'
882-
,
860+
# include: '#row_types'
861+
# ,
883862
name: 'meta.class-constraints'
884863
match: concat /\(/,
885864
list('classConstraints',/{classConstraint}/,/,/),

test/Main.purs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ infixl 7 type Product as :*:
110110
infixl 2 Inl as $%
111111
infixr 2 Inr as %$
112112

113+
114+
113115
-- type class signatures
114116

115117

@@ -139,7 +141,7 @@ class Functor v
139141
unmount :: m. v m -> v m -> T Void E
140142

141143

142-
-- class with type, breaks highlighting
144+
-- class with row type
143145
class RowTypeClass (rl :: RL.RowList Type) where
144146
rowListCodec :: forall proxy. proxy rl -> Record ri -> CA.JPropCodec (Record ro)
145147

@@ -187,8 +189,6 @@ instance functorA :: Functor A where
187189
instance functorA :: Functor A where
188190
map = split -- comment
189191

190-
191-
192192
-- chained instances
193193

194194

@@ -209,15 +209,15 @@ else instance showA :: MyShow a where
209209
else newtype instance showA :: MyShow a where
210210

211211

212-
213212
-- Records with fields that are reserved words
214213

215214

216215
-- quoted row type
217216
type QuotedRow a =
218217
( "A" :: Int
219218
-- comment
220-
, "B" :: { nested :: Number }
219+
, "B" :: { nested :: Number, nested2 :: { x :: Maybe (Array Int) } | a }
220+
, "C" :: { | (c :: Int) }
221221
{- block comment inside -}
222222
, c :: Either (Maybe Bad) Int
223223
, d :: Some.Int -- comment
@@ -290,8 +290,14 @@ updateRec = rec
290290
}
291291

292292

293-
-- row type parens are not highlighted as it doesn't seem necessary
294-
type RowLine a = ( name :: String, age :: { nested :: Number } | a )
293+
type RowLineSpacing a = ( name :: String, age :: { nested :: Number } | a )
294+
295+
296+
--one line row type with no spaces after/before braces
297+
type RowLine a = (names :: Maybe (Array String), age :: { nested :: Number } | a)
298+
type RowLine a = { | }
299+
type RowLine a = { | a }
300+
type RowLine a = { | (a :: Maybe (Array a)) }
295301

296302

297303
type RowRecord a
@@ -331,6 +337,7 @@ quoted =
331337
{ "A": "a" -- comment
332338
, "B": fn (1 :: Int) x 2 -- typed param in parens
333339
, "C": 1 :: Int -- typed param without parens
340+
, "C": (1 :: Maybe (Array Int) ) x (1 :: Int)
334341
, a: 2
335342
}
336343

@@ -350,6 +357,14 @@ foreign import createSource ::
350357
proxy = Proxy :: Proxy Int -- k is Type
351358

352359

360+
-- orphan inline signature
361+
x = 1
362+
::
363+
Int
364+
x = {a: 1} ::
365+
{ | (a :: Int) }
366+
367+
353368
-- row type
354369
intAtFoo :: forall r. Variant ( foo :: Int | r )
355370
intAtFoo = inj (Proxy :: Proxy "foo") 42
@@ -384,13 +399,17 @@ toStr x = do
384399
gotConfig :: AVar { a :: Unit } <- AVar.empty
385400

386401

387-
SomeType :: ( a :: Int )
402+
-- signatures in ide tooltips
403+
SomeType :: (a :: Int)
388404

389405

406+
-- we may not distinct Type names from type ctors
407+
-- so we highlight as ctors
390408
AVar :: Type Type
391409

392410

393-
addIf true = singleton
411+
--
412+
-- addIf true = singleton
394413
addIf false = const []
395414

396415

@@ -447,6 +466,10 @@ decimal = 41.0
447466

448467
hex = 0xE0
449468

469+
-- quotes after type def
470+
px = Proxy :: Proxy """fdsfsdf
471+
fdsfdsfsdf
472+
"""
450473

451474
multiString = """
452475

0 commit comments

Comments
 (0)