Skip to content

Commit

Permalink
Provide a safe/defaulting element lookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
solidsnack committed Mar 17, 2013
1 parent 5f2970e commit 512cacb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions hs/Language/Bash/PrettyPrinter.hs
Expand Up @@ -72,6 +72,8 @@ instance (Annotation t) => PP (Expression t) where
pp (ARGVLength) = word "$#"
pp (Elements ident) = (word . quote . braces)
(bytes ident `append` "[@]")
pp (ElementsSafe ident) = (word . quote . braces_)
(bytes ident `append` "[@]")
pp (Keys ident) = (word . quote . braces)
('!' `cons` bytes ident `append` "[@]")
pp (Length ident) = (word . quote . braces)
Expand Down Expand Up @@ -188,6 +190,8 @@ braces b = "${" `append` b `snoc` '}'

braces0 b = "${" `append` b `append` ":-}"

braces_ b = concat ["${", b, ":+${", b, "}}"]

brackets b = cons '[' b `snoc` ']'

identpart (VarSpecial special) = (drop 1 . bytes) special
Expand Down
3 changes: 3 additions & 0 deletions hs/Language/Bash/Syntax.hs
Expand Up @@ -157,6 +157,7 @@ data Expression t = Literal Esc.Bash
| ARGVElements
| ARGVLength
| Elements Identifier
| ElementsSafe Identifier
| Keys Identifier
| Length VarName
| Trim Trim VarName (Expression t)
Expand Down Expand Up @@ -186,6 +187,7 @@ instance Functor Expression where
ARGVElements -> ARGVElements
ARGVLength -> ARGVLength
Elements ident -> Elements ident
ElementsSafe ident -> Elements ident
Keys ident -> Keys ident
Length ident -> Length ident
Trim trim v expr -> Trim trim v (fmap f expr)
Expand All @@ -208,6 +210,7 @@ instance Foldable Expression where
ARGVElements -> mempty
ARGVLength -> mempty
Elements _ -> mempty
ElementsSafe _ -> mempty
Keys _ -> mempty
Length _ -> mempty
Trim _ _ expr -> foldMap f expr
Expand Down
2 changes: 1 addition & 1 deletion hs/bash.cabal
@@ -1,5 +1,5 @@
name : bash
version : 0.1.6
version : 0.1.8
category : Language
license : BSD3
license-file : LICENSE
Expand Down

0 comments on commit 512cacb

Please sign in to comment.