diff options
Diffstat (limited to 'src/LambdaCube/Compiler/Lexer.hs')
-rw-r--r-- | src/LambdaCube/Compiler/Lexer.hs | 11 |
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 | ||
208 | namespace' = namespaceLevel <$> namespace | ||
209 | |||
208 | tick = (\case TypeLevel -> switchTick; _ -> id) . fromMaybe ExpLevel . namespaceLevel | 210 | tick = (\case TypeLevel -> switchTick; _ -> id) . fromMaybe ExpLevel . namespaceLevel |
209 | 211 | ||
210 | tick' c = (`tick` c) <$> namespace | 212 | tick' c = (`tick` c) <$> namespace |
211 | 213 | ||
214 | switchNamespace = \case ExpLevel -> TypeLevel; TypeLevel -> ExpLevel | ||
215 | |||
212 | switchTick ('\'': n) = n | 216 | switchTick ('\'': n) = n |
213 | switchTick n = '\'': n | 217 | switchTick n = '\'': n |
214 | 218 | ||
@@ -217,7 +221,7 @@ modifyLevel f = local $ (first . second) $ \(Namespace l p) -> Namespace (f <$> | |||
217 | typeNS, expNS, switchNS :: P a -> P a | 221 | typeNS, expNS, switchNS :: P a -> P a |
218 | typeNS = modifyLevel $ const TypeLevel | 222 | typeNS = modifyLevel $ const TypeLevel |
219 | expNS = modifyLevel $ const ExpLevel | 223 | expNS = modifyLevel $ const ExpLevel |
220 | switchNS = modifyLevel $ \case ExpLevel -> TypeLevel; TypeLevel -> ExpLevel | 224 | switchNS = modifyLevel $ switchNamespace |
221 | 225 | ||
222 | ifNoCNamespace p = namespace >>= \ns -> if constructorNamespace ns then mzero else p | 226 | ifNoCNamespace 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 | ||
239 | upperCase_ = identifier (tick' =<< maybeStartWith (=='\'') ((:) <$> upperLetter <*> many identLetter)) <?> "uppercase ident" | 243 | upperCase = identifier (tick' =<< maybeStartWith (=='\'') ((:) <$> upperLetter <*> many identLetter)) <?> "uppercase ident" |
240 | lowerCase = identifier ((:) <$> lowerLetter <*> many identLetter) <?> "lowercase ident" | 244 | lowerCase = identifier ((:) <$> lowerLetter <*> many identLetter) <?> "lowercase ident" |
241 | backquotedIdent = identifier ((:) <$ char '`' <*> identStart <*> many identLetter <* char '`') <?> "backquoted ident" | 245 | backquotedIdent = identifier ((:) <$ char '`' <*> identStart <*> many identLetter <* char '`') <?> "backquoted ident" |
242 | symbols = operator (some opLetter) <?> "symbols" | 246 | symbols = operator (some opLetter) <?> "symbols" |
@@ -250,8 +254,7 @@ patVar = second f <$> lowerCase where | |||
250 | lhsOperator = lcSymbols <|> backquotedIdent | 254 | lhsOperator = lcSymbols <|> backquotedIdent |
251 | rhsOperator = symbols <|> backquotedIdent | 255 | rhsOperator = symbols <|> backquotedIdent |
252 | varId = lowerCase <|> parens (symbols <|> backquotedIdent) | 256 | varId = lowerCase <|> parens (symbols <|> backquotedIdent) |
253 | upperCase = upperCase_ | 257 | upperLower = lowerCase <|> upperCase <|> parens symbols |
254 | upperLower = lowerCase <|> upperCase_ <|> parens (symbols <|> backquotedIdent) | ||
255 | 258 | ||
256 | --qIdent = {-qualified_ todo-} (lowerCase <|> upperCase) | 259 | --qIdent = {-qualified_ todo-} (lowerCase <|> upperCase) |
257 | 260 | ||