ref: 3b5c7213c743da1cfe48ab4581fffb6b2a96d72e
parent: 31514568372404f818cf0109de773c925fd5f366
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Tue Feb 20 12:52:42 EST 2024
Allow module without the module header.
--- a/src/MicroHs/Lex.hs
+++ b/src/MicroHs/Lex.hs
@@ -322,5 +322,15 @@
popLayout :: LexState -> LexState
popLayout (LS f) = snd (f Pop)
+-- Insert TBrace if no 'module'/'{'+lexStart :: [Token] -> [Token]
+lexStart ts =
+ case skip ts of
+ TIdent _ [] "module" : _ -> ts
+ TSpec _ '{' : _ -> ts+ rs -> TBrace (tokensLoc ts) : rs
+ where skip (TIndent _ : rs) = rs
+ skip rs = rs
+
lexTopLS :: String -> LexState
-lexTopLS s = LS $ layoutLS (lex (mkLoc 1 1) s) []
+lexTopLS s = LS $ layoutLS (lexStart $ lex (mkLoc 1 1) s) []
--- a/src/MicroHs/Parse.hs
+++ b/src/MicroHs/Parse.hs
@@ -58,8 +58,12 @@
exps <- (pSpec '(' *> esepEndBy pExportItem (pSpec ',') <* pSpec ')')<|< pure [ExpModule mn]
pKeyword "where"
- defs <- pBlock pDef
+ defs <- pBlock pDef
pure $ EModule mn exps defs
+ <|< do
+ defs <- pBlock pDef
+ --let loc = getSLoc defs
+ pure $ EModule (mkIdent "Main") [ExpValue $ mkIdent "main"] defs
-- Possibly qualified alphanumeric identifier
pQIdent :: P Ident
@@ -145,7 +149,7 @@
"let", "module", "newtype", "of", "primitive", "then", "type", "where"]
pSpec :: Char -> P ()
-pSpec c = () <$ satisfy [c] is
+pSpec c = () <$ satisfy (showToken $ TSpec (0,0) c) is
where
is (TSpec _ d) = c == d
is _ = False
--
⑨