language-bash 0.6.2 → 0.7.0
raw patch · 6 files changed
+21/−29 lines, 6 files
Files
- language-bash.cabal +2/−2
- src/Language/Bash/Expand.hs +3/−3
- src/Language/Bash/Parse.hs +8/−8
- src/Language/Bash/Parse/Internal.hs +4/−5
- src/Language/Bash/Word.hs +4/−9
- tests/Tests.hs +0/−2
language-bash.cabal view
@@ -1,5 +1,5 @@ name: language-bash-version: 0.6.2+version: 0.7.0 category: Language license: BSD3 license-file: LICENSE@@ -10,7 +10,7 @@ cabal-version: >= 1.8 homepage: http://github.com/knrafto/language-bash/ bug-reports: http://github.com/knrafto/language-bash/issues-tested-with: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.1, GHC == 7.10.2+tested-with: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.1, GHC == 7.10.2, GHC == 8.0.2 synopsis: Parsing and pretty-printing Bash shell scripts description: A library for parsing, pretty-printing, and manipulating
src/Language/Bash/Expand.hs view
@@ -113,7 +113,7 @@ start = prefix <$> string "{}" <*> expr "" </> expr "" - expr delims = foldr ($) [""] <$> many (exprPart delims)+ expr delims = foldr ($) [[]] <$> many (exprPart delims) exprPart delims = cross <$ char '{' <*> brace delims <* char '}' </> prefix <$> emptyBrace@@ -121,7 +121,7 @@ brace delims = concat <$> braceParts delims </> sequenceExpand- </> map (\s -> "{" ++ s ++ "}") <$> expr ",}"+ </> map (\s -> stringToWord "{" ++ s ++ stringToWord "}") <$> expr ",}" -- The first part of the outermost brace expression is not delimited by -- a close brace.@@ -145,7 +145,7 @@ b <- string ".." *> sequencePart c <- optional (string ".." *> sequencePart) inc <- traverse readNumber c- map fromString <$> (numExpand a b inc <|> charExpand a b inc)+ map stringToWord <$> (numExpand a b inc <|> charExpand a b inc) where sequencePart = many1 (satisfy' isAlphaNum)
src/Language/Bash/Parse.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE OverloadedStrings, RecordWildCards #-}+{-# LANGUAGE RecordWildCards #-} -- | Bash script and input parsing. module Language.Bash.Parse ( parse@@ -19,7 +19,7 @@ import Language.Bash.Operator import Language.Bash.Parse.Internal import Language.Bash.Syntax-import Language.Bash.Word (fromString, unquote)+import Language.Bash.Word (unquote, stringToWord) -- | User state. data U = U { postHeredoc :: Maybe (State D U) }@@ -116,10 +116,10 @@ heredocOp <- heredocOperator w <- anyWord let heredocDelim = unquote w- heredocDelimQuoted = fromString heredocDelim /= w+ heredocDelimQuoted = stringToWord heredocDelim /= w h <- heredoc (heredocOp == HereStrip) heredocDelim hereDocument <- if heredocDelimQuoted- then return (fromString h)+ then return (stringToWord h) else heredocWord h return Heredoc{..} @@ -214,7 +214,7 @@ addRedir (Command c rs) = Command c (stderrRedir : rs) - stderrRedir = Redir (Just (IONumber 2)) OutAnd "1"+ stderrRedir = Redir (Just (IONumber 2)) OutAnd (stringToWord "1") -- | Parse a compound list of commands. compoundList :: Parser List@@ -351,11 +351,11 @@ , [Infix (Cond.Or <$ operator "||") AssocLeft] ] - condWord = anyWord `satisfying` (/= "]]")- <|> fromString <$> anyOperator+ condWord = anyWord `satisfying` (/= stringToWord "]]")+ <|> stringToWord <$> anyOperator <?> "word" - condOperator op = condWord `satisfying` (== fromString op) <?> op+ condOperator op = condWord `satisfying` (== stringToWord op) <?> op unaryOp = selectOperator condOperator <?> "unary operator" binaryOp = selectOperator condOperator <?> "binary operator"
src/Language/Bash/Parse/Internal.hs view
@@ -4,7 +4,6 @@ , LambdaCase , CPP , MultiParamTypeClasses- , OverloadedStrings , PatternGuards , RecordWildCards #-}@@ -137,7 +136,7 @@ -- | Shell reserved words. reservedWords :: [Word]-reservedWords =+reservedWords = map stringToWord [ "!", "[[", "]]", "{", "}" , "if", "then", "else", "elif", "fi" , "case", "esac", "for", "select", "while", "until"@@ -147,7 +146,7 @@ -- | Shell assignment builtins. These builtins can take assignments as -- arguments. assignBuiltins :: [Word]-assignBuiltins =+assignBuiltins = map stringToWord [ "alias", "declare", "export", "eval" , "let", "local", "readonly", "typeset" ]@@ -175,8 +174,8 @@ anyWord = try (rat _anyWord) <?> "word" -- | Parse the given word.-word :: Monad m => Word -> ParsecT D u m Word-word w = anyWord `satisfying` (== w) <?> prettyText w+word :: Monad m => String -> ParsecT D u m Word+word w = anyWord `satisfying` (== stringToWord w) <?> prettyText w -- | Parse a reversed word. reservedWord :: Monad m => ParsecT D u m Word
src/Language/Bash/Word.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE DeriveDataTypeable- , FlexibleInstances , CPP , OverloadedStrings , RecordWildCards@@ -8,7 +7,7 @@ #-} -- | Bash words and substitutions. module Language.Bash.Word- ( + ( -- * Words Word , Span(..)@@ -21,7 +20,7 @@ -- * Process , ProcessSubstOp(..) -- * Manipulation- , fromString+ , stringToWord , unquote ) where @@ -30,7 +29,6 @@ #endif import Data.Data (Data)-import qualified Data.String import Data.Typeable (Typeable) import Text.PrettyPrint @@ -40,9 +38,6 @@ -- | A Bash word, broken up into logical spans. type Word = [Span] -instance Data.String.IsString Word where- fromString = fromString- -- | An individual unit of a word. data Span -- | A normal character.@@ -252,8 +247,8 @@ pretty = prettyOperator -- | Convert a string to an unquoted word.-fromString :: String -> Word-fromString = map Char+stringToWord :: String -> Word+stringToWord = map Char -- | Remove all quoting characters from a word. unquote :: Word -> String
tests/Tests.hs view
@@ -44,8 +44,6 @@ prop_expandsLikeBash = monadicIO $ forAllM braceExpr $ \str -> do bash <- run $ expandWithBash str let check = unwords . filter (not . null) $ testExpand str- run $ putStrLn bash- run $ putStrLn check QCM.assert (bash == check) properties :: TestTree