Rethinking the rethinking.

This commit is contained in:
2016-04-26 17:29:17 -07:00
parent 5a5902af6b
commit 079796ecc3
12 changed files with 119 additions and 0 deletions

4
.gitignore vendored
View File

@@ -6,3 +6,7 @@
hsrc/Syntax/Lexer.hs hsrc/Syntax/Lexer.hs
hsrc/Syntax/Parser.hs hsrc/Syntax/Parser.hs
bang bang
.cabal-sandbox/
dist/
cabal.sandbox.config

30
LICENSE Normal file
View File

@@ -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.

2
Setup.hs Normal file
View File

@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

27
bang.cabal Normal file
View File

@@ -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 <awick@uhsure.com>
maintainer: Adam Wick <awick@uhsure.com>
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

View File

@@ -1,3 +1,11 @@
import Syntax.CommandLine
main :: IO ()
main = getCommand >>= \ mode ->
putStrLn (show mode)
{-
import Control.Exception import Control.Exception
import Control.Monad import Control.Monad
import qualified Data.ByteString as S import qualified Data.ByteString as S
@@ -53,3 +61,4 @@ loadModule path = do
case runParser path txt parseModule of case runParser path txt parseModule of
Left err -> printError err >> exitWith (ExitFailure 1) Left err -> printError err >> exitWith (ExitFailure 1)
Right ast -> return ast Right ast -> return ast
-}

47
src/Syntax/CommandLine.hs Normal file
View File

@@ -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