@@ -51,6 +51,7 @@ import Control.Exception
51
51
52
52
%token
53
53
' import' { TReserved _ " import" }
54
+ ' submodule' { TReserved _ " submodule" }
54
55
' and' { TReserved _ " and" }
55
56
' as' { TReserved _ " as" }
56
57
' hiding' { TReserved _ " hiding" }
@@ -89,6 +90,7 @@ import Control.Exception
89
90
' {' { TPunct _ " {" }
90
91
' }' { TPunct _ " }" }
91
92
' :' { TPunct _ " :" }
93
+ ' ::' { TPunct _ " ::" }
92
94
' ,' { TPunct _ " ," }
93
95
' .' { TPunct _ " ." }
94
96
' \\ ' { TPunct _ " \\ " }
@@ -134,11 +136,12 @@ StmtSemi :: { Stmt }
134
136
: fst (Stmt , opt (' ;' )) { $1 }
135
137
136
138
Import :: { Import }
137
- : string mbAs mbImportSpec { Import (Left (unpack $ tokStr $1 )) (fst $2 ) (fst $3 ) (maxSpan [tokPos $1 , snd $2 , snd $3 ])}
139
+ : string mbAs mbImportSpec { buildImport False $1 $2 $3 }
140
+ | ' submodule' string mbAs mbImportSpec { buildImport True $2 $3 $4 }
138
141
-- TODO : allow imports by module name instead of path
139
142
140
143
mbAs :: { (Maybe P.ModName, Pos) }
141
- : ' as' name { (Just (P.packModName [tokStr $2 ]) , maxSpan [ $1 , $2 ] ) }
144
+ : ' as' QName { (Just (P.packModName (fst $2 )) , maxSpan' $1 (snd $2) ) }
142
145
| {- empty -} { (Nothing, Unknown) }
143
146
144
147
mbImportSpec :: { (Maybe P.ImportSpec, Pos) }
@@ -271,6 +274,9 @@ Context :: { Type }
271
274
FieldType :: { (Name, Type) }
272
275
: name ' :' Type { (tokStr $1, $3) }
273
276
277
+ QName :: { ([Text], Pos) }
278
+ : sepBy1(name, ' ::' ) { (map tokStr $1, maxSpan (map tokPos $1)) }
279
+
274
280
-- Parameterized productions, most come directly from the Happy manual.
275
281
fst(p, q) : p q { $1 }
276
282
snd(p, q) : p q { $2 }
@@ -356,6 +362,22 @@ parseError toks = case toks of
356
362
[] -> Left UnexpectedEOF
357
363
t : _ -> Left (UnexpectedToken t)
358
364
365
+ -- | Cons up an import.
366
+ buildImport ::
367
+ Bool ->
368
+ Token Pos ->
369
+ (Maybe P.ModName, Pos) ->
370
+ (Maybe P.ImportSpec, Pos) ->
371
+ Import
372
+ buildImport issub modName (mbAsName, asPos) (mbSpec, specPos) =
373
+ Import {
374
+ iIsSubmodule = issub,
375
+ iModule = Left (unpack $ tokStr modName),
376
+ iAs = mbAsName,
377
+ iSpec = mbSpec,
378
+ iPos = maxSpan [tokPos modName, asPos, specPos]
379
+ }
380
+
359
381
-- | As seen by the parser, a " function name" is an arbitrary pattern.
360
382
-- This is because we use the same syntax for function and value bindings:
361
383
-- in " let (a, b) = e" the " (a, b)" can and should be an arbitrary pattern.
0 commit comments