Skip to content

Commit

Permalink
Merge f9adf94 into 142659d
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Aug 25, 2018
2 parents 142659d + f9adf94 commit e86bf0e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 27 deletions.
3 changes: 2 additions & 1 deletion BUILD.bazel
Expand Up @@ -29,13 +29,14 @@ haskell_library(
"-Wno-unused-imports",
],
src_strip_prefix = "src",
version = "0.0.1",
version = "0.0.2",
visibility = ["//visibility:public"],
deps = [
"//third_party/haskell:array",
"//third_party/haskell:base",
"//third_party/haskell:deepseq",
"//third_party/haskell:filepath",
"@haskell_groom//:groom",
"@haskell_language_c//:language-c",
],
)
Expand Down
25 changes: 10 additions & 15 deletions src/Tokstyle/Cimple.hs
@@ -1,21 +1,16 @@
module Tokstyle.Cimple (main) where

--import Text.Groom (groom)
import Tokstyle.Cimple.Lexer (alexScanTokens, runAlex)
import Text.Groom (groom)
import Tokstyle.Cimple.Lexer (runAlex)
import Tokstyle.Cimple.Parser (parseCimple)


parseFile :: FilePath -> IO ()
parseFile source = do
putStrLn $ "Processing " ++ source
contents <- readFile source
putStrLn . groom $ runAlex contents parseCimple


main :: [String] -> IO ()
main sources = do
putStrLn "[=] reading..."
contents <- mapM readFile sources
{-
putStrLn "[=] lexing..."
let tokens = map alexScanTokens contents
mapM_ (putStrLn . groom) tokens
-}
putStrLn "[=] parsing..."
let ast = map (`runAlex` parseCimple) contents
-- mapM_ (putStrLn . groom) ast
mapM_ print ast
return ()
main = mapM_ parseFile
4 changes: 3 additions & 1 deletion src/Tokstyle/Cimple/Lexer.x
Expand Up @@ -71,6 +71,7 @@ tokens :-

-- Standard C (ish).
<ppSC> defined { mkL PpDefined }
<ppSC> \"[^\"]*\" { mkL LitString }
<ppSC> \n { mkL PpNewline `andBegin` 0 }
<ppSC> \\\n ;
<ppSC> $white ;
Expand Down Expand Up @@ -129,6 +130,7 @@ tokens :-
<0,ppSC> "bool" { mkL IdStdType }
<0,ppSC> "char" { mkL IdStdType }
<0,ppSC> "double" { mkL IdStdType }
<0,ppSC> "float" { mkL IdStdType }
<0,ppSC> "int" { mkL IdStdType }
<0,ppSC> "long int" { mkL IdStdType }
<0,ppSC> "long signed int" { mkL IdStdType }
Expand All @@ -154,7 +156,7 @@ tokens :-
<0,ppSC> [a-z][a-z0-9_]*_cb { mkL IdFuncType }
<0,ppSC> [a-z][A-Za-z0-9_]* { mkL IdVar }
<0,ppSC> [0-9]+[LU]* { mkL LitInteger }
<0,ppSC> [0-9]+"."[0-9]+ { mkL LitInteger }
<0,ppSC> [0-9]+"."[0-9]+f? { mkL LitInteger }
<0,ppSC> 0x[0-9a-fA-F]+[LU]* { mkL LitInteger }
<0,ppSC> "=" { mkL PctEq }
<0,ppSC> "==" { mkL PctEqEq }
Expand Down
1 change: 1 addition & 0 deletions src/Tokstyle/Cimple/Parser.y
Expand Up @@ -459,6 +459,7 @@ MemberDecls
MemberDecl :: { () }
MemberDecl
: QualType DeclSpec(ConstExpr) ';' { () }
| QualType DeclSpec(ConstExpr) ':' LIT_INTEGER ';' { () }
| PreprocIfdef(MemberDecls) { () }

TypedefDecl :: { () }
Expand Down
23 changes: 14 additions & 9 deletions src/Tokstyle/Sources.hs
Expand Up @@ -3,15 +3,19 @@ module Tokstyle.Sources (sources) where
sources :: [String]
sources = map ("../c-toxcore/" ++)
[ "toxav/audio.c"
{-, "toxav/audio.h"-}
{-, "toxav/bwcontroller.c"-}
{-, "toxav/bwcontroller.h"-}
{-, "toxav/groupav.c"-}
{-, "toxav/msi.c"-}
{-, "toxav/rtp.c"-}
{-, "toxav/toxav.c"-}
{-, "toxav/toxav_old.c"-}
{-, "toxav/video.c"-}
, "toxav/audio.h"
, "toxav/bwcontroller.c"
, "toxav/bwcontroller.h"
, "toxav/groupav.c"
, "toxav/groupav.h"
, "toxav/msi.c"
, "toxav/msi.h"
, "toxav/rtp.c"
, "toxav/rtp.h"
, "toxav/toxav.c"
, "toxav/toxav_old.c"
, "toxav/video.c"
, "toxav/video.h"
, "toxcore/DHT.c"
, "toxcore/DHT.h"
, "toxcore/LAN_discovery.c"
Expand Down Expand Up @@ -39,6 +43,7 @@ sources = map ("../c-toxcore/" ++)
, "toxcore/mono_time.c"
, "toxcore/mono_time.h"
, "toxcore/net_crypto.c"
, "toxcore/net_crypto.h"
, "toxcore/network.c"
, "toxcore/network.h"
, "toxcore/onion.c"
Expand Down
4 changes: 4 additions & 0 deletions test/Tokstyle/CimpleSpec.hs
Expand Up @@ -16,3 +16,7 @@ spec =
it "should parse a type declaration" $ do
let ast = runAlex "typedef struct Foo { int x; } Foo;" parseCimple
ast `shouldBe` Right [()]

it "should parse a struct with bit fields" $ do
let ast = runAlex "typedef struct Foo { int x : 123; } Foo;" parseCimple
ast `shouldBe` Right [()]
3 changes: 2 additions & 1 deletion tokstyle.cabal
@@ -1,5 +1,5 @@
name: tokstyle
version: 0.0.1
version: 0.0.2
synopsis: TokTok C code style checker
description: TokTok C code style checker
homepage: https://toktok.github.io/tokstyle
Expand Down Expand Up @@ -33,6 +33,7 @@ library
, array
, deepseq
, filepath
, groom
, language-c
hs-source-dirs: src

Expand Down

0 comments on commit e86bf0e

Please sign in to comment.