check lexer state invariants on EOF

This commit is contained in:
Ilya Rezvov
2018-01-19 14:51:36 -08:00
parent 9d6bd7f097
commit 56ea29a659
+7 -1
View File
@@ -9,6 +9,7 @@ import qualified Data.ByteString.Lazy as LBS
import qualified Data.Char as Char
import qualified Data.ByteString.Lazy.UTF8 as LBSUtf8
import Control.Applicative ((<$>))
import Control.Monad (when)
}
@@ -350,6 +351,11 @@ scanner str = runAlex str loop
loop = do
lex <- alexMonadScan
case lex of
Lexeme _ EOF -> return [lex]
Lexeme _ EOF -> do
strFlag <- getLexerStringFlag
when strFlag $ alexError "End of file reached before string literal end"
commentDepth <- getLexerCommentDepth
when (commentDepth > 0) $ alexError "End of file reached before block comment end"
return [lex]
otherwise -> (lex :) <$> loop
}