diff --git a/.gitignore b/.gitignore index b1604b6..0a249ca 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,7 @@ hsrc/Syntax/Lexer.hs hsrc/Syntax/Parser.hs bang + +.cabal-sandbox/ +dist/ +cabal.sandbox.config diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..05bdb4b --- /dev/null +++ b/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2016, Adam Wick + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Adam Wick nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/bang.cabal b/bang.cabal new file mode 100644 index 0000000..513c3dc --- /dev/null +++ b/bang.cabal @@ -0,0 +1,27 @@ +name: bang +version: 0.1.0.0 +synopsis: A fun little language to explore building a compiler. Again. +homepage: http://github.com/acw/bang +license: BSD3 +license-file: LICENSE +author: Adam Wick +maintainer: Adam Wick + +category: Development +build-type: Simple +cabal-version: >=1.10 + + +executable bang + main-is: Main.hs + build-depends: base >= 4.8 && < 4.9, + bytestring >= 0.10 && < 0.11, + cmdargs >= 0.10.14 && < 0.12 + hs-source-dirs: src + build-tools: alex, happy + default-language: Haskell2010 + other-extensions: DeriveDataTypeable + other-modules: + Paths_bang, + Syntax.CommandLine + diff --git a/hsrc/Main.hs b/src/Main.hs similarity index 93% rename from hsrc/Main.hs rename to src/Main.hs index 25efe81..5bf3b3e 100644 --- a/hsrc/Main.hs +++ b/src/Main.hs @@ -1,3 +1,11 @@ +import Syntax.CommandLine + +main :: IO () +main = getCommand >>= \ mode -> + putStrLn (show mode) + + +{- import Control.Exception import Control.Monad import qualified Data.ByteString as S @@ -53,3 +61,4 @@ loadModule path = do case runParser path txt parseModule of Left err -> printError err >> exitWith (ExitFailure 1) Right ast -> return ast +-} diff --git a/hsrc/Makefile b/src/Makefile similarity index 100% rename from hsrc/Makefile rename to src/Makefile diff --git a/hsrc/Syntax/AST.hs b/src/Syntax/AST.hs similarity index 100% rename from hsrc/Syntax/AST.hs rename to src/Syntax/AST.hs diff --git a/src/Syntax/CommandLine.hs b/src/Syntax/CommandLine.hs new file mode 100644 index 0000000..8bbd750 --- /dev/null +++ b/src/Syntax/CommandLine.hs @@ -0,0 +1,47 @@ +{-# LANGUAGE DeriveDataTypeable #-} +module Syntax.CommandLine( + Bang(..), getCommand + ) + where + +import Data.Version(showVersion) +import Paths_bang(version) +import System.Console.CmdArgs hiding (verbosity) + +data Bang = Bang { + verbosity :: Word + , files :: [FilePath] + , mode :: BangMode + } + deriving (Data, Typeable, Show, Eq) + +data BangMode = Lex | Parse + deriving (Data, Typeable, Show, Eq) + +lexer :: Bang +lexer = Bang { + verbosity = 0 &= name "verbose" &= name "v" + , files = [] &= args + , mode = Lex + } &= name "lex" + +parser :: Bang +parser = Bang { + verbosity = 0 &= name "verbose" &= name "v" + , files = [] &= args + , mode = Parse + } &= name "parse" + +bang :: Bang +bang = modes [lexer, parser] + &= versionArg [explicit, name "version", summary programInfo] + &= summary (programInfo ++ ", " ++ copyright) + &= help "A nifty little compiler for a new language" + &= helpArg [explicit, name "help", name "h", name "?"] + &= program "bang" + where + programInfo = "bang version " ++ showVersion version + copyright = "(C) 2016 Adam Wick" + +getCommand :: IO Bang +getCommand = cmdArgs bang diff --git a/hsrc/Syntax/Lexer.x b/src/Syntax/Lexer.x similarity index 100% rename from hsrc/Syntax/Lexer.x rename to src/Syntax/Lexer.x diff --git a/hsrc/Syntax/Makefile b/src/Syntax/Makefile similarity index 100% rename from hsrc/Syntax/Makefile rename to src/Syntax/Makefile diff --git a/hsrc/Syntax/Parser.y b/src/Syntax/Parser.y similarity index 100% rename from hsrc/Syntax/Parser.y rename to src/Syntax/Parser.y diff --git a/hsrc/Syntax/ParserCore.hs b/src/Syntax/ParserCore.hs similarity index 100% rename from hsrc/Syntax/ParserCore.hs rename to src/Syntax/ParserCore.hs