basic parsing stub using optparse-applicative
This commit is contained in:
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
.stack-work
|
.stack-work
|
||||||
tests/runnable/*
|
tests/runnable/*
|
||||||
|
.idea
|
||||||
+15
-2
@@ -7,6 +7,10 @@ import qualified Language.Wasm.Lexer as Lexer
|
|||||||
import qualified Language.Wasm.Parser as Parser
|
import qualified Language.Wasm.Parser as Parser
|
||||||
import qualified Language.Wasm.Binary as Binary
|
import qualified Language.Wasm.Binary as Binary
|
||||||
|
|
||||||
|
import Options.Applicative
|
||||||
|
import Data.Semigroup ((<>))
|
||||||
|
import Wasm.WasmParser
|
||||||
|
|
||||||
data OutputMode = WasmBinary | JSWrapper deriving (Show, Eq)
|
data OutputMode = WasmBinary | JSWrapper deriving (Show, Eq)
|
||||||
|
|
||||||
data WasmConfig = WasmConfig {
|
data WasmConfig = WasmConfig {
|
||||||
@@ -24,6 +28,15 @@ compile input output = do
|
|||||||
Left reason ->
|
Left reason ->
|
||||||
putStrLn $ "Cannot complie module: " ++ reason
|
putStrLn $ "Cannot complie module: " ++ reason
|
||||||
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = parseArgs =<< execParser opts
|
||||||
putStrLn "There is no WASM!"
|
where
|
||||||
|
opts = info (sample <**> helper)
|
||||||
|
( fullDesc
|
||||||
|
<> progDesc "Print a greeting for TARGET"
|
||||||
|
<> header "hello - a test for optparse-applicative" )
|
||||||
|
|
||||||
|
parseArgs :: WasmParser -> IO ()
|
||||||
|
parseArgs (WasmParser h False n) = putStrLn $ "Hello, " ++ h ++ replicate n '!'
|
||||||
|
parseArgs _ = return ()
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
module Wasm.WasmParser where
|
||||||
|
|
||||||
|
import Options.Applicative
|
||||||
|
import Data.Semigroup ((<>))
|
||||||
|
|
||||||
|
data WasmParser = WasmParser
|
||||||
|
{ hello :: String
|
||||||
|
, quiet :: Bool
|
||||||
|
, enthusiasm :: Int }
|
||||||
|
|
||||||
|
sample :: Parser WasmParser
|
||||||
|
sample = WasmParser
|
||||||
|
<$> strOption
|
||||||
|
( long "hello"
|
||||||
|
<> metavar "TARGET"
|
||||||
|
<> help "Target for the greeting" )
|
||||||
|
<*> switch
|
||||||
|
( long "quiet"
|
||||||
|
<> short 'q'
|
||||||
|
<> help "Whether to be quiet" )
|
||||||
|
<*> option auto
|
||||||
|
( long "enthusiasm"
|
||||||
|
<> help "How enthusiastically to greet"
|
||||||
|
<> showDefault
|
||||||
|
<> value 1
|
||||||
|
<> metavar "INT" )
|
||||||
@@ -33,6 +33,7 @@ library
|
|||||||
, vector >= 0.12
|
, vector >= 0.12
|
||||||
, ieee754 >= 0.8
|
, ieee754 >= 0.8
|
||||||
, deepseq >= 1.4
|
, deepseq >= 1.4
|
||||||
|
, optparse-applicative >= 0.14
|
||||||
build-tools:
|
build-tools:
|
||||||
alex >=3.1.3
|
alex >=3.1.3
|
||||||
, happy >=1.9.4
|
, happy >=1.9.4
|
||||||
@@ -58,6 +59,9 @@ executable wasm
|
|||||||
, wasm ==0.1.0
|
, wasm ==0.1.0
|
||||||
, optparse-applicative >= 0.13
|
, optparse-applicative >= 0.13
|
||||||
, bytestring >=0.10 && <0.11
|
, bytestring >=0.10 && <0.11
|
||||||
|
other-modules:
|
||||||
|
Wasm.WasmParser
|
||||||
|
|
||||||
|
|
||||||
test-suite test
|
test-suite test
|
||||||
type: exitcode-stdio-1.0
|
type: exitcode-stdio-1.0
|
||||||
|
|||||||
Reference in New Issue
Block a user