summaryrefslogtreecommitdiff
path: root/src/LambdaCube/Compiler/Lexer.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/LambdaCube/Compiler/Lexer.hs')
-rw-r--r--src/LambdaCube/Compiler/Lexer.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/LambdaCube/Compiler/Lexer.hs b/src/LambdaCube/Compiler/Lexer.hs
index 83446799..f7c96bf6 100644
--- a/src/LambdaCube/Compiler/Lexer.hs
+++ b/src/LambdaCube/Compiler/Lexer.hs
@@ -205,10 +205,14 @@ data Namespace = Namespace
205 } 205 }
206 deriving (Show) 206 deriving (Show)
207 207
208namespace' = namespaceLevel <$> namespace
209
208tick = (\case TypeLevel -> switchTick; _ -> id) . fromMaybe ExpLevel . namespaceLevel 210tick = (\case TypeLevel -> switchTick; _ -> id) . fromMaybe ExpLevel . namespaceLevel
209 211
210tick' c = (`tick` c) <$> namespace 212tick' c = (`tick` c) <$> namespace
211 213
214switchNamespace = \case ExpLevel -> TypeLevel; TypeLevel -> ExpLevel
215
212switchTick ('\'': n) = n 216switchTick ('\'': n) = n
213switchTick n = '\'': n 217switchTick n = '\'': n
214 218
@@ -217,7 +221,7 @@ modifyLevel f = local $ (first . second) $ \(Namespace l p) -> Namespace (f <$>
217typeNS, expNS, switchNS :: P a -> P a 221typeNS, expNS, switchNS :: P a -> P a
218typeNS = modifyLevel $ const TypeLevel 222typeNS = modifyLevel $ const TypeLevel
219expNS = modifyLevel $ const ExpLevel 223expNS = modifyLevel $ const ExpLevel
220switchNS = modifyLevel $ \case ExpLevel -> TypeLevel; TypeLevel -> ExpLevel 224switchNS = modifyLevel $ switchNamespace
221 225
222ifNoCNamespace p = namespace >>= \ns -> if constructorNamespace ns then mzero else p 226ifNoCNamespace p = namespace >>= \ns -> if constructorNamespace ns then mzero else p
223 227
@@ -236,7 +240,7 @@ upperLetter = satisfy isUpper <|> ifNoCNamespace identStart
236 240
237--upperCase, lowerCase, symbols, colonSymbols, backquotedIdent :: P SName 241--upperCase, lowerCase, symbols, colonSymbols, backquotedIdent :: P SName
238 242
239upperCase_ = identifier (tick' =<< maybeStartWith (=='\'') ((:) <$> upperLetter <*> many identLetter)) <?> "uppercase ident" 243upperCase = identifier (tick' =<< maybeStartWith (=='\'') ((:) <$> upperLetter <*> many identLetter)) <?> "uppercase ident"
240lowerCase = identifier ((:) <$> lowerLetter <*> many identLetter) <?> "lowercase ident" 244lowerCase = identifier ((:) <$> lowerLetter <*> many identLetter) <?> "lowercase ident"
241backquotedIdent = identifier ((:) <$ char '`' <*> identStart <*> many identLetter <* char '`') <?> "backquoted ident" 245backquotedIdent = identifier ((:) <$ char '`' <*> identStart <*> many identLetter <* char '`') <?> "backquoted ident"
242symbols = operator (some opLetter) <?> "symbols" 246symbols = operator (some opLetter) <?> "symbols"
@@ -250,8 +254,7 @@ patVar = second f <$> lowerCase where
250lhsOperator = lcSymbols <|> backquotedIdent 254lhsOperator = lcSymbols <|> backquotedIdent
251rhsOperator = symbols <|> backquotedIdent 255rhsOperator = symbols <|> backquotedIdent
252varId = lowerCase <|> parens (symbols <|> backquotedIdent) 256varId = lowerCase <|> parens (symbols <|> backquotedIdent)
253upperCase = upperCase_ 257upperLower = lowerCase <|> upperCase <|> parens symbols
254upperLower = lowerCase <|> upperCase_ <|> parens (symbols <|> backquotedIdent)
255 258
256--qIdent = {-qualified_ todo-} (lowerCase <|> upperCase) 259--qIdent = {-qualified_ todo-} (lowerCase <|> upperCase)
257 260