@@ -53,9 +53,10 @@ type Parser s m a = ParsecT s () m a
53
53
-- - nonterm -> alt1 | ... | altn
54
54
--
55
55
--
56
- -- Tokens form the vocabulary of Lambda Buffer Files. There are classes of
57
- -- tokens (keyword, modulename, longmodulename, tyname, longtyname, varname,
58
- -- punctuation, fieldname, classname, longclassname) as follows.
56
+ -- Tokens form the vocabulary of Lambda Buffer Files. The classes of *tokens*
57
+ -- (keyword, modulename, longmodulename, tyname, longtyname, varname,
58
+ -- punctuation, fieldname, classname, longclassname) are as follows.
59
+ -- Note that some of the tokens overlap but may be distinguished via parsing.
59
60
--
60
61
-- keyword -> 'module' | 'sum' | 'prod' | 'record' | 'opaque' | 'class' | 'instance' | 'import' | 'qualified' | 'as'
61
62
-- modulename -> upperCamelCase
@@ -80,16 +81,22 @@ type Parser s m a = ParsecT s () m a
80
81
-- line comments. At each point, the longest possible token satisfying the
81
82
-- token definitions is read.
82
83
--
84
+ -- A *line comment* is any sequence of characters which begins with '--'
85
+ -- followed by zero or more printable Unicode character to the first end of
86
+ -- line ('\n' or '\r\n').
87
+ --
83
88
-- Finally, the grammar for Lambda Buffer Files is as follows.
84
89
--
90
+ -- start -> module
91
+ --
85
92
-- module -> 'module' modulename imports statements
86
93
--
87
94
-- import -> 'import' [ 'qualified' ] longmodulename
88
95
-- [ 'as' longmodulename ]
89
96
-- [ '(' [ { tyname ',' } tyname [','] ] ')' ]
90
97
-- imports -> { import }
91
98
--
92
- -- statements -> [ { statement newlines1 } statement [ newlines1 ] ]
99
+ -- statements -> { statement }
93
100
-- statement -> tydef
94
101
-- | classdef
95
102
-- | instanceclause
@@ -114,7 +121,7 @@ type Parser s m a = ParsecT s () m a
114
121
-- opaquetydef -> 'opaque' tyname { varname }
115
122
--
116
123
-- classdef -> 'class' [ classexps '<=' ] classname { varname }
117
- -- // Warning: this part makes it not LL(1)!
124
+ -- // Warning: this is not LL(1)!
118
125
-- // In the future, we should shift to some form of
119
126
-- // an LALR(1) parser.
120
127
-- classexp -> classref { varname }
@@ -174,8 +181,8 @@ type Parser s m a = ParsecT s () m a
174
181
-- * Primitives
175
182
176
183
{- | @'token' pa@ runs the parser @pa@ with 'try' followed by 'junk' to remove
177
- whitespace. Moreover, this gets the SourceInfo of the parsed token w/o the
178
- whitespace
184
+ whitespace. Moreover, this gets the ' SourceInfo' of the parsed token without
185
+ the whitespace
179
186
180
187
See [Note: Parser Implementation].
181
188
-}
@@ -216,6 +223,12 @@ runParser p = runParserT (junk *> p <* eof) ()
216
223
217
224
-- * Lexical elements
218
225
226
+ --
227
+ -- - Functions which have @parse@ as a prefix simply parse the token
228
+ --
229
+ -- - Functions which have @token@ as a prefix wrap the corresponding @parse@
230
+ -- function with the 'token' function.
231
+
219
232
parseModuleNamePart :: Stream s m Char => Parser s m (ModuleNamePart SourceInfo )
220
233
parseModuleNamePart = withSourceInfo . label' " module part name" $ ModuleNamePart <$> pModuleNamePart
221
234
@@ -391,6 +404,11 @@ parseField :: Stream s m Char => Parser s m (Field SourceInfo)
391
404
parseField = withSourceInfo . label' " record field" $ do
392
405
fn <- tokenFieldName
393
406
_ <- token $ char ' :'
407
+ -- TODO: strictly speaking, there's a bug with this when parsing
408
+ -- > record A a = { fieldName :-- a }
409
+ -- since this will parse the @:--@ as @:@ and @--@ will start a comment.
410
+ -- Technically, the specification says that this should parse as the token
411
+ -- @:-@, and then the remaining @-@ should parse error.
394
412
Field fn <$> parseTyTopLevel
395
413
396
414
parseTyDef :: Stream s m Char => Parser s m (TyDef SourceInfo )
@@ -527,9 +545,11 @@ parseImport = label' "import statement" $ do
527
545
mayNames = fmap snd mayBracketSrcInfoAndNames
528
546
529
547
return $
530
- Import isQual modName mayNames mayModAlias $ -- Get the rightmost position of the rightmost parsed token
548
+ Import isQual modName mayNames mayModAlias $
531
549
srcInfo
532
550
{ to =
551
+ -- Get the rightmost position of the rightmost parsed token
552
+ -- Note: the 'fromJust' clearly never fails.
533
553
fromJust $
534
554
fmap to mayBracketSrcInfo
535
555
<|> ( case mayModAlias of
0 commit comments