From 336b180d74c8599472c3ebd3dd74d5ef247e6a98 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sat, 19 Oct 2019 13:27:29 -0400 Subject: [PATCH] lexer handles carriage returns (closes #51) --- src/Language/SystemVerilog/Parser/Lex.x | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Language/SystemVerilog/Parser/Lex.x b/src/Language/SystemVerilog/Parser/Lex.x index 7818778..2465130 100644 --- a/src/Language/SystemVerilog/Parser/Lex.x +++ b/src/Language/SystemVerilog/Parser/Lex.x @@ -527,7 +527,7 @@ alexInitUserState = LS [] "" Map.empty [] [] [] -- public-facing lexer entrypoint lexFile :: [String] -> Env -> FilePath -> IO (Either String ([Token], Env)) lexFile includePaths env path = do - str <- readFile path + str <- readFile path >>= return . normalize let result = runAlex str $ setEnv >> alexMonadScan >> get return $ case result of Left msg -> Left msg @@ -622,7 +622,13 @@ includeSearch file = do -- read in the given file loadFile :: FilePath -> Alex String -loadFile = return . unsafePerformIO . readFile +loadFile = return . normalize . unsafePerformIO . readFile + +-- removes carriage returns before newlines +normalize :: String -> String +normalize ('\r' : '\n' : rest) = '\n' : (normalize rest) +normalize (ch : chs) = ch : (normalize chs) +normalize [] = [] isIdentChar :: Char -> Bool isIdentChar ch =