diff options
Diffstat (limited to 'src/LambdaCube/Compiler/Lexer.hs')
-rw-r--r-- | src/LambdaCube/Compiler/Lexer.hs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/LambdaCube/Compiler/Lexer.hs b/src/LambdaCube/Compiler/Lexer.hs index c47ba1ce..fe3015a6 100644 --- a/src/LambdaCube/Compiler/Lexer.hs +++ b/src/LambdaCube/Compiler/Lexer.hs | |||
@@ -141,7 +141,16 @@ lexemeWithoutSpace p = do | |||
141 | 141 | ||
142 | -- TODO?: eliminate; when eliminated, the SPos in parser state can be eliminated too | 142 | -- TODO?: eliminate; when eliminated, the SPos in parser state can be eliminated too |
143 | appRange :: Parse r w (SI -> a) -> Parse r w a | 143 | appRange :: Parse r w (SI -> a) -> Parse r w a |
144 | appRange p = (\fi p1 a p2 -> a $ RangeSI $ Range fi p1 p2) <$> asks fileInfo <*> getSPos <*> p <*> get | 144 | appRange p = (\fi p1 a p2 -> a $ RangeSI $ Range fi p1 p2) <$> asks fileInfo <*> getSPos <*> p <*> getLexemeEnd |
145 | |||
146 | getLexemeEnd = get | ||
147 | |||
148 | noSpaceBefore p = try $ do | ||
149 | pos <- getLexemeEnd | ||
150 | x <- p | ||
151 | guard $ case sourceInfo x of | ||
152 | RangeSI (Range _ pos' _) -> pos == pos' | ||
153 | return x | ||
145 | 154 | ||
146 | lexeme_ p = lexemeWithoutSpace p <* whiteSpace | 155 | lexeme_ p = lexemeWithoutSpace p <* whiteSpace |
147 | 156 | ||
@@ -224,9 +233,9 @@ upperLower = lowerCase <|> upperCase_ <|> parens symbols | |||
224 | 233 | ||
225 | ----------------------------------------------------------- operators and identifiers | 234 | ----------------------------------------------------------- operators and identifiers |
226 | 235 | ||
227 | reservedOp name = lexeme $ try $ string name *> notFollowedBy opLetter | 236 | reservedOp name = fst <$> lexeme_ (try $ string name *> notFollowedBy opLetter) |
228 | 237 | ||
229 | reserved name = lexeme $ try $ string name *> notFollowedBy identLetter | 238 | reserved name = fst <$> lexeme_ (try $ string name *> notFollowedBy identLetter) |
230 | 239 | ||
231 | expect msg p i = i >>= \n -> if p n then unexpected (msg ++ " " ++ show n) else return n | 240 | expect msg p i = i >>= \n -> if p n then unexpected (msg ++ " " ++ show n) else return n |
232 | 241 | ||