From aec52e1005c4d813825c83f04851002fca94be8b Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 3 Dec 2023 12:25:41 +0000 Subject: [PATCH] fix: Disallow tabs in source code. --- cimple.cabal | 3 --- src/Language/Cimple/IO.hs | 8 ++------ src/Language/Cimple/Lexer.x | 10 ++++++++-- tools/BUILD.bazel | 1 - 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cimple.cabal b/cimple.cabal index 97a2f48..1b8f24b 100644 --- a/cimple.cabal +++ b/cimple.cabal @@ -81,10 +81,8 @@ executable dump-ast main-is: dump-ast.hs build-depends: base <5 - , bytestring , cimple , groom - , text executable dump-tokens default-language: Haskell2010 @@ -96,7 +94,6 @@ executable dump-tokens , bytestring , cimple , groom - , text executable include-graph default-language: Haskell2010 diff --git a/src/Language/Cimple/IO.hs b/src/Language/Cimple/IO.hs index 07fc664..28aa40f 100644 --- a/src/Language/Cimple/IO.hs +++ b/src/Language/Cimple/IO.hs @@ -64,13 +64,9 @@ parseFile source = addSource (Right ok) = Right (source, ok) -parseFiles' :: [FilePath] -> IO (Either String [TranslationUnit Text]) -parseFiles' sources = sequenceA <$> P.mapM parseFile sources - - parseFiles :: [FilePath] -> IO (Either String [TranslationUnit Text]) -parseFiles sources = fmap Program.toList . (>>= Program.fromList) <$> parseFiles' sources +parseFiles sources = sequenceA <$> P.mapM parseFile sources parseProgram :: [FilePath] -> IO (Either String (Program Text)) -parseProgram sources = (>>= Program.fromList) <$> parseFiles' sources +parseProgram sources = (>>= Program.fromList) <$> parseFiles sources diff --git a/src/Language/Cimple/Lexer.x b/src/Language/Cimple/Lexer.x index e76c2a8..130cf1b 100644 --- a/src/Language/Cimple/Lexer.x +++ b/src/Language/Cimple/Lexer.x @@ -116,14 +116,16 @@ tokens :- \"[^\"]*\" { mkL LitString } \n { mkL PpNewline `andBegin` 0 } \\\n ; - $white ; + " " ; + $white { mkE ErrorToken } "//!TOKSTYLE+" { mkL IgnEnd `andBegin` 0 } ([^\/]+|.|\n) { mkL IgnBody } <0,ppSC> "//"\n ; <0,ppSC> "// ".* ; -<0> $white+ ; +<0> [\ \n]+ ; +<0> $white { mkE ErrorToken } <0> "//!TOKSTYLE-" { mkL IgnStart `andBegin` ignoreSC } <0> "/*" { mkL CmtStart `andBegin` cmtSC } <0> "/**" { mkL CmtStartDoc `andBegin` cmtSC } @@ -310,6 +312,10 @@ mkL :: LexemeClass -> AlexInput -> Int64 -> Alex (Lexeme Text) mkL c (p, _, str, _) len = pure $ L p c (piece str) where piece = Text.decodeUtf8 . LBS.toStrict . LBS.take len +mkE :: LexemeClass -> AlexInput -> Int64 -> Alex (Lexeme Text) +mkE c (p, _, str, _) len = alexError $ show $ L p c (piece str) + where piece = Text.decodeUtf8 . LBS.toStrict . LBS.take len + lexemePosn :: Lexeme text -> AlexPosn lexemePosn (L p _ _) = p diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel index f172bb2..6092db8 100644 --- a/tools/BUILD.bazel +++ b/tools/BUILD.bazel @@ -19,7 +19,6 @@ haskell_binary( deps = [ "//hs-cimple", "//third_party/haskell:base", - "//third_party/haskell:bytestring", "//third_party/haskell:groom", ], )