Skip to content

Commit

Permalink
fix: Disallow tabs in source code.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Dec 3, 2023
1 parent 3ce65d6 commit aec52e1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
3 changes: 0 additions & 3 deletions cimple.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -96,7 +94,6 @@ executable dump-tokens
, bytestring
, cimple
, groom
, text

executable include-graph
default-language: Haskell2010
Expand Down
8 changes: 2 additions & 6 deletions src/Language/Cimple/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 8 additions & 2 deletions src/Language/Cimple/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ tokens :-
<ppSC> \"[^\"]*\" { mkL LitString }
<ppSC> \n { mkL PpNewline `andBegin` 0 }
<ppSC> \\\n ;
<ppSC> $white ;
<ppSC> " " ;
<ppSC> $white { mkE ErrorToken }

<ignoreSC> "//!TOKSTYLE+" { mkL IgnEnd `andBegin` 0 }
<ignoreSC> ([^\/]+|.|\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 }
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ haskell_binary(
deps = [
"//hs-cimple",
"//third_party/haskell:base",
"//third_party/haskell:bytestring",
"//third_party/haskell:groom",
],
)
Expand Down

0 comments on commit aec52e1

Please sign in to comment.