language-ninja-0.2.0: A library for dealing with the Ninja build language.

CopyrightCopyright 2017 Awake Security
LicenseApache-2.0
Maintaineropensource@awakesecurity.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Language.Ninja.AST.Expr

Contents

Description

This module contains a type representing a string that potentially contains variable references in the parsed Ninja AST, along with any supporting or related types.

Since: 0.1.0

Synopsis

Expr

data Expr ann Source #

An expression containing variable references in the Ninja language.

Since: 0.1.0

Constructors

Exprs !ann ![Expr ann]

Sequencing of expressions.

Since: 0.1.0

Lit !ann !Text

A literal string.

Since: 0.1.0

Var !ann !Text

A variable reference.

Since: 0.1.0

Instances

Functor Expr Source # 

Methods

fmap :: (a -> b) -> Expr a -> Expr b #

(<$) :: a -> Expr b -> Expr a #

Foldable Expr Source # 

Methods

fold :: Monoid m => Expr m -> m #

foldMap :: Monoid m => (a -> m) -> Expr a -> m #

foldr :: (a -> b -> b) -> b -> Expr a -> b #

foldr' :: (a -> b -> b) -> b -> Expr a -> b #

foldl :: (b -> a -> b) -> b -> Expr a -> b #

foldl' :: (b -> a -> b) -> b -> Expr a -> b #

foldr1 :: (a -> a -> a) -> Expr a -> a #

foldl1 :: (a -> a -> a) -> Expr a -> a #

toList :: Expr a -> [a] #

null :: Expr a -> Bool #

length :: Expr a -> Int #

elem :: Eq a => a -> Expr a -> Bool #

maximum :: Ord a => Expr a -> a #

minimum :: Ord a => Expr a -> a #

sum :: Num a => Expr a -> a #

product :: Num a => Expr a -> a #

Traversable Expr Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Expr a -> f (Expr b) #

sequenceA :: Applicative f => Expr (f a) -> f (Expr a) #

mapM :: Monad m => (a -> m b) -> Expr a -> m (Expr b) #

sequence :: Monad m => Expr (m a) -> m (Expr a) #

Annotated Expr Source #

The usual definition for Annotated.

Since: 0.1.0

Methods

annotation' :: (ann -> ann') -> Lens (Expr ann) (Expr ann') ann ann' Source #

(Monad m, ExprConstraint (Serial m) ann) => Serial m (Expr ann) Source #

Default Serial instance via Generic.

Since: 0.1.0

Methods

series :: Series m (Expr ann) #

(Monad m, ExprConstraint (CoSerial m) ann) => CoSerial m (Expr ann) Source #

Default CoSerial instance via Generic.

Since: 0.1.0

Methods

coseries :: Series m b -> Series m (Expr ann -> b) #

Eq ann => Eq (Expr ann) Source # 

Methods

(==) :: Expr ann -> Expr ann -> Bool #

(/=) :: Expr ann -> Expr ann -> Bool #

Data ann => Data (Expr ann) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Expr ann -> c (Expr ann) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Expr ann) #

toConstr :: Expr ann -> Constr #

dataTypeOf :: Expr ann -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Expr ann)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Expr ann)) #

gmapT :: (forall b. Data b => b -> b) -> Expr ann -> Expr ann #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Expr ann -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Expr ann -> r #

gmapQ :: (forall d. Data d => d -> u) -> Expr ann -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Expr ann -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Expr ann -> m (Expr ann) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Expr ann -> m (Expr ann) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Expr ann -> m (Expr ann) #

Show ann => Show (Expr ann) Source # 

Methods

showsPrec :: Int -> Expr ann -> ShowS #

show :: Expr ann -> String #

showList :: [Expr ann] -> ShowS #

Generic (Expr ann) Source # 

Associated Types

type Rep (Expr ann) :: * -> * #

Methods

from :: Expr ann -> Rep (Expr ann) x #

to :: Rep (Expr ann) x -> Expr ann #

(Arbitrary ann, ExprConstraint Arbitrary ann) => Arbitrary (Expr ann) Source #

Reasonable Arbitrary instance for Expr.

Since: 0.2.0

Methods

arbitrary :: Gen (Expr ann) #

shrink :: Expr ann -> [Expr ann] #

Hashable ann => Hashable (Expr ann) Source #

Default Hashable instance via Generic.

Since: 0.1.0

Methods

hashWithSalt :: Int -> Expr ann -> Int #

hash :: Expr ann -> Int #

ToJSON ann => ToJSON (Expr ann) Source #

Converts Exprs to {ann: …, exprs: […]}, Lit to {ann: …, lit: […]}, and Var to {ann: …, var: …}.

Since: 0.1.0

Methods

toJSON :: Expr ann -> Value #

toEncoding :: Expr ann -> Encoding #

toJSONList :: [Expr ann] -> Value #

toEncodingList :: [Expr ann] -> Encoding #

FromJSON ann => FromJSON (Expr ann) Source #

Inverse of the ToJSON instance.

Since: 0.1.0

Methods

parseJSON :: Value -> Parser (Expr ann) #

parseJSONList :: Value -> Parser [Expr ann] #

NFData ann => NFData (Expr ann) Source #

Default NFData instance via Generic.

Since: 0.1.0

Methods

rnf :: Expr ann -> () #

Data ann => Plated (Expr ann) Source #

The usual definition for Plated.

Since: 0.1.0

Methods

plate :: Traversal' (Expr ann) (Expr ann) #

type Rep (Expr ann) Source # 

_Exprs :: Prism' (Expr ann) (ann, [Expr ann]) Source #

A prism for the Exprs constructor.

Since: 0.1.0

_Lit :: Prism' (Expr ann) (ann, Text) Source #

A prism for the Lit constructor.

Since: 0.1.0

_Var :: Prism' (Expr ann) (ann, Text) Source #

A prism for the Var constructor.

Since: 0.1.0

askVar :: Env Text Text -> Text -> Text Source #

Look up the given variable in the given context, returning the empty string if the variable was not found.

Since: 0.1.0

askExpr :: Env Text Text -> Expr ann -> Text Source #

Evaluate the given Expr in the given context (Env Text Text).

Since: 0.1.0

addBind :: Text -> Expr ann -> Env Text Text -> Env Text Text Source #

Add a binding with the given name (Text) and value (Expr) to the given context.

Since: 0.1.0

addBinds :: [(Text, Expr ann)] -> Env Text Text -> Env Text Text Source #

Add bindings from a list. Note that this function evaluates all the right-hand-sides first, and then adds them all to the environment.

For example:

>>> :set -XOverloadedStrings
>>> let binds = [("x", Lit () "5"), ("y", Var () "x")]
>>> AST.headEnv (addBinds binds AST.makeEnv)
fromList [("x","5"),("y","")]

Since: 0.1.0

normalizeExpr :: forall ann. Monoid ann => Expr ann -> Expr ann Source #

Normalize an Expr by recursively flattening any Exprs nodes, removing empty Lit nodes, combining adjacent Lit nodes, and pulling out the interior of the top-level Exprs node if it has only one subnode.

The number of Exprs nodes in the output is guaranteed to be 0 or 1.

If it is 0, then there is exactly one node of any type in the output.

The output is thus isomorphic to (Maybe ann, [(ann, Either Text Text)]), where the Maybe ann represents the annotation of the top-level Exprs node if it exists.

Since: 0.1.0

type ExprConstraint c ann = (c Text, c ann) Source #

The set of constraints required for a given constraint to be automatically computed for a Expr.

Since: 0.1.0