hydrogen-cli 0.11 → 0.12
raw patch · 10 files changed
+156/−24 lines, 10 filesdep +hydrogen-datadep +hydrogen-multimapdep ~hydrogen-cli-argsdep ~hydrogen-parsingdep ~hydrogen-prelude
Dependencies added: hydrogen-data, hydrogen-multimap
Dependency ranges changed: hydrogen-cli-args, hydrogen-parsing, hydrogen-prelude, hydrogen-syntax
Files
- help/dump.txt +41/−4
- help/help.txt +3/−2
- help/init.txt +0/−0
- help/run.txt +0/−0
- hydrogen-cli.cabal +9/−5
- src/H/Common.hs +29/−0
- src/H/Dump.hs +54/−9
- src/H/Init.hs +2/−0
- src/H/Run.hs +12/−0
- src/h.hs +6/−4
help/dump.txt view
@@ -2,13 +2,50 @@ dump the output of different parsing stages. -One of the following switches must be specified:+One of the following switches must be specified as <type>: - -T --tokens Print a list of parsed tokens- -L --layout Print the layout tree- -D --data Read a hydrogen data document+ -1 --tokens Print a list of parsed tokens+ -2 --layout Print the layout tree+ -3 --values --layout + identifies built-in datatypes +Options:++ -s --spaces Which characters to identify as space.+ Defaults to " " (the space character only)++ -c --comments The character sequence that starts single-line comments.+ Defaults to ";;"++ -O --opening-braces+ The characters which make up opening braces.+ Defaults to "([{"++ -C --closing-braces+ The characters which make up closing braces.+ Defaults to ")]}"++ -S --special Characters that are regarded special (i.e. tokens+ in their own right).+ Defaults to ",;"++ -X --special-syntax+ For which characters special layout rules should+ be enabled. This will just enable/disable some+ special parsing rules for "{" and the --special+ characters.+ Defaults to "{;"++ -i --indent-token+ What indents should be translated to.+ Defaults to ";;"++ -F --fold-specials+ Which of the --special characters should be folded+ (i.e. eliminate consecutive tokens)+ Defaults to ";"+ Examples: h dump -T file.hy cat file.hy | h dump -L+
help/help.txt view
@@ -2,6 +2,7 @@ Available commands are: - dump, help+ dump, help, init, run -Use `hy help <command>` for further information.+`h help <command>` shows further information for a given command.+
+ help/init.txt view
+ help/run.txt view
hydrogen-cli.cabal view
@@ -1,5 +1,5 @@ name: hydrogen-cli-version: 0.11+version: 0.12 homepage: https://scravy.de/hydrogen-cli/ synopsis: Hydrogen Data license: MIT@@ -19,13 +19,17 @@ executable h main-is: h.hs other-modules: Paths_hydrogen_cli+ , H.Common , H.Dump , H.Init+ , H.Run build-depends: base ==4.7.*- , hydrogen-cli-args ==0.11- , hydrogen-parsing ==0.11- , hydrogen-prelude ==0.11- , hydrogen-syntax ==0.11+ , hydrogen-cli-args ==0.12+ , hydrogen-data ==0.12+ , hydrogen-multimap ==0.1+ , hydrogen-parsing ==0.12+ , hydrogen-prelude ==0.12+ , hydrogen-syntax ==0.12 hs-source-dirs: src ghc-options: -Wall default-language: Haskell2010
+ src/H/Common.hs view
@@ -0,0 +1,29 @@+module H.Common (+ module Hydrogen.Prelude+ , module Hydrogen.CliArgs+ , Tool+ , LogLevel (..)+ , getOpts+ , onFiles+ , (>+>)+ , (<+<)+ ) where++import Hydrogen.Prelude hiding (log)+import Hydrogen.CliArgs hiding (getOpts)+import Hydrogen.Parsing++type Tool = (LogLevel -> String -> IO ()) -> [String] -> IO ()++data LogLevel = WARN | INFO | FINE | FINER | FINEST+ deriving (Eq, Ord, Enum, Show, Read, Generic, Typeable)++onFiles :: (String -> IO ()) -> [String] -> IO ()+onFiles f = \case+ [] -> getContents >>= f+ fs -> mapM_ (readFile >=> f) fs++getOpts :: [String] -> [Option] -> OptArgs+getOpts = flip getOpts'++
src/H/Dump.hs view
@@ -5,26 +5,67 @@ import Hydrogen.Parsing hiding (parse, token) import Hydrogen.Syntax.Parser import Hydrogen.Syntax.Types+import Hydrogen.Data+import qualified Hydrogen.MultiMap as MultiMap main :: Tool main _ args = do - let (_, switches, files) = getOpts args [- 'T' ~: switch "tokens"- , 'L' ~: switch "layout"- , 'P' ~: switch "parse"+ let (options, switches, files) = getOpts args [+ '1' ~: switch "tokens"+ , '2' ~: switch "layout"+ , '3' ~: switch "values"+ , '4' ~: switch "program"+ , 's' ~: optarg "spaces"+ , 'c' ~: optarg "comments"+ , 'O' ~: optarg "opening-braces"+ , 'C' ~: optarg "closing-braces"+ , 'i' ~: optarg "indent-token"+ , 'S' ~: optarg "special"+ , 'X' ~: optarg "special-syntax"+ , 'F' ~: optarg "fold-specials" ] - report = concatMap showMessage+ tokenizerConfig = foldl setConfig default_ (MultiMap.toList' options) where+ setConfig b = \case+ ("spaces", x) -> b { cfgSpaces = x }+ ("special", x) -> b { cfgSpecialCharacters = x }+ ("comments", x) -> b { cfgComments = x }+ ("fold-specials", x) -> b { cfgFoldSpecials = x }+ ("opening-braces", x) -> b { cfgOpeningBraces = x }+ ("closing-braces", x) -> b { cfgClosingBraces = x }+ ("special-syntax", x) -> b { cfgSpecialSemantics = x }+ _ -> b+ layoutConfig = foldl setConfig default_ (MultiMap.toList' options)+ where+ setConfig b = \case+ ("indent-token", x) -> b { cfgIndentToken = x }+ _ -> b++ layoutConfig' = layoutConfig {+ cfgValueTokens = readValue+ , cfgBlockTransformer = \case+ Block Grouping "" [] -> Value (mkValue ()) ""+ x -> x+ }++ report = concatMap showMessage . nub+ where showMessage (pos, message) = printf "%4d%4d %s\n" (sourceLine pos) (sourceColumn pos) message func- | switches ? "tokens" = either report showTokens . tokenize "-"- | switches ? "layout" = either report showLayout . parse "-"- | switches ? "parse" = either report showLayout . parse "-"- | otherwise = const "Need -T, -L, or -P"+ | switches ? "tokens"+ = either report showTokens . parseTokens tokenizerConfig "-"+ | switches ? "layout"+ = either report showLayout . parse' tokenizerConfig layoutConfig "-"+ | switches ? "values"+ = either report showLayout . parse' tokenizerConfig layoutConfig' "-"+ | switches ? "program"+ = either report showLayout . parse' tokenizerConfig layoutConfig' "-"+ | otherwise+ = const "Need -1, -2, -3, or -4" showTokens = concatMap showToken showToken (pos, token) = printf "%4d%4d %s\n"@@ -39,6 +80,10 @@ Block t x pops -> printf "%4d%4d %s%s %s\n" (sourceLine pos) (sourceColumn pos) indent (show t) x : showPOPs (" " ++ indent) (ps : backlog) pops+ Value v s -> printf "%4d%4d %s%s (%s)\n"+ (sourceLine pos) (sourceColumn pos) indent (show v) s+ : showPOPs indent backlog ps+ [] | null backlog -> [] | otherwise -> showPOPs (drop 2 indent) (tail backlog) (head backlog)
src/H/Init.hs view
@@ -8,4 +8,6 @@ let (_options, _switches, _files) = getOpts args [ ] + + return ()
+ src/H/Run.hs view
@@ -0,0 +1,12 @@+module H.Run where++import H.Common++main :: Tool+main _ args = do+ + let (_options, _switches, _files) = getOpts args [+ ]+ + return ()+
src/h.hs view
@@ -9,6 +9,7 @@ import qualified H.Dump as Dump import qualified H.Init as Init+import qualified H.Run as Run showVersion :: IO ()@@ -63,10 +64,11 @@ "help" -> showHelp topic - "escape" -> mapM_ (putStrLn . escapeFileName) (drop 1 args)- "unescape" -> mapM_ (maybe (return ()) putStrLn . unescapeFileName) (drop 1 args)+ "escape" -> mapM_ (putStrLn . escapeFileName) (drop 1 args)+ "unescape" -> mapM_ (maybe (return ()) putStrLn . unescapeFileName) (drop 1 args) - "dump" -> run Dump.main- "init" -> run Init.main+ "dump" -> run Dump.main+ "init" -> run Init.main+ "run" -> run Run.main cmd -> unknownCommand cmd