Skip to content

Commit 295e4b3

Browse files
committed
Merge branch 'allow-raw-strings-as-record-keys' of https://github.com/i-am-the-slime/purescript-language-cst-parser into i-am-the-slime-allow-raw-strings-as-record-keys
2 parents 2085622 + b562e39 commit 295e4b3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/PureScript/CST/Parser.purs

+2
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,8 @@ parseIdentBinder = do
850850

851851
parseLabel :: Parser (Name Label)
852852
parseLabel = expectMap case _ of
853+
tok@{ value: TokRawString label } ->
854+
Just $ Name { token: tok, name: Label label }
853855
tok@{ value: TokString _ label } ->
854856
Just $ Name { token: tok, name: Label label }
855857
tok@{ value: TokLowerName Nothing label } ->

test/Main.purs

+26-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import Prim hiding (Type)
55

66
import Data.Array as Array
77
import Data.Array.NonEmpty as NonEmptyArray
8-
import Data.Maybe (maybe)
8+
import Data.Maybe (Maybe(..), maybe)
99
import Data.String (Pattern(..))
1010
import Data.String as String
1111
import Data.String.CodeUnits as SCU
1212
import Effect (Effect)
1313
import Effect.Class.Console as Console
1414
import Node.Process as Process
1515
import PureScript.CST (RecoveredParserResult(..), parseBinder, parseDecl, parseExpr, parseModule, parseType)
16-
import PureScript.CST.Types (Binder, Declaration(..), DoStatement(..), Expr(..), LetBinding(..), Module(..), ModuleBody(..), Type)
16+
import PureScript.CST.Types (Binder, Declaration(..), DoStatement(..), Expr(..), Label(..), LetBinding(..), Module(..), ModuleBody(..), Name(..), RecordLabeled(..), Separated(..), Token(..), Type, Wrapped(..))
1717

1818
class ParseFor f where
1919
parseFor :: String -> RecoveredParserResult f
@@ -120,3 +120,27 @@ main = do
120120
true
121121
_ ->
122122
false
123+
124+
assertParse "Records with raw string labels"
125+
"{ \"\"\"key\"\"\": val }"
126+
case _ of
127+
ParseSucceeded
128+
( ExprRecord
129+
( Wrapped
130+
{ value: Just
131+
( Separated
132+
{ head: RecordField
133+
( Name
134+
{ name: Label "key", token: { value: TokRawString "key" } }
135+
)
136+
_
137+
_
138+
}
139+
)
140+
}
141+
)
142+
)
143+
->
144+
true
145+
_ ->
146+
false

0 commit comments

Comments
 (0)