Skip to content

Commit 29d7d4d

Browse files
author
jared
committed
Improved documentation for the parser
1 parent 49e035f commit 29d7d4d

File tree

1 file changed

+14
-1
lines changed
  • lambda-buffers-frontend/src/LambdaBuffers/Frontend

1 file changed

+14
-1
lines changed

lambda-buffers-frontend/src/LambdaBuffers/Frontend/Parsec.hs

+14-1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ runParser p = runParserT (junk *> p <* eof) ()
216216

217217
-- * Lexical elements
218218

219+
--
220+
-- - Functions which have @parse@ as a prefix simply parse the token
221+
--
222+
-- - Functions which have @token@ as a prefix wrap the corresponding @parse@
223+
-- function with the 'token' function.
224+
219225
parseModuleNamePart :: Stream s m Char => Parser s m (ModuleNamePart SourceInfo)
220226
parseModuleNamePart = withSourceInfo . label' "module part name" $ ModuleNamePart <$> pModuleNamePart
221227

@@ -391,6 +397,11 @@ parseField :: Stream s m Char => Parser s m (Field SourceInfo)
391397
parseField = withSourceInfo . label' "record field" $ do
392398
fn <- tokenFieldName
393399
_ <- token $ char ':'
400+
-- TODO: strictly speaking, there's a bug with this when parsing
401+
-- > record A a = { fieldName :-- a }
402+
-- since this will parse the @:--@ as @:@ and @--@ will start a comment.
403+
-- Technically, the specification says that this should parse as the token
404+
-- @:-@, and then the remaining @-@ should parse error.
394405
Field fn <$> parseTyTopLevel
395406

396407
parseTyDef :: Stream s m Char => Parser s m (TyDef SourceInfo)
@@ -527,9 +538,11 @@ parseImport = label' "import statement" $ do
527538
mayNames = fmap snd mayBracketSrcInfoAndNames
528539

529540
return $
530-
Import isQual modName mayNames mayModAlias $ -- Get the rightmost position of the rightmost parsed token
541+
Import isQual modName mayNames mayModAlias $
531542
srcInfo
532543
{ to =
544+
-- Get the rightmost position of the rightmost parsed token
545+
-- Note: the 'fromJust' clearly never fails.
533546
fromJust $
534547
fmap to mayBracketSrcInfo
535548
<|> ( case mayModAlias of

0 commit comments

Comments
 (0)