| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
Puppet.Parser
Contents
Description
Parse puppet source code from text.
- runPuppetParser :: String -> Text -> Either PuppetParseError (Vector Statement)
- type Parser = Parsec Void Text
- puppetParser :: Parser (Vector Statement)
- type PuppetParseError = ParseError Char Void
- prettyParseError :: Text -> ParseError Char Void -> PrettyError
- expression :: Parser Expression
- datatype :: Parser UDataType
- ppStatements :: Vector Statement -> Doc
- data Expression
- = Equal !Expression !Expression
- | Different !Expression !Expression
- | Not !Expression
- | And !Expression !Expression
- | Or !Expression !Expression
- | LessThan !Expression !Expression
- | MoreThan !Expression !Expression
- | LessEqualThan !Expression !Expression
- | MoreEqualThan !Expression !Expression
- | RegexMatch !Expression !Expression
- | NotRegexMatch !Expression !Expression
- | Contains !Expression !Expression
- | Addition !Expression !Expression
- | Substraction !Expression !Expression
- | Division !Expression !Expression
- | Multiplication !Expression !Expression
- | Modulo !Expression !Expression
- | RightShift !Expression !Expression
- | LeftShift !Expression !Expression
- | Lookup !Expression !Expression
- | Negate !Expression
- | ConditionalValue !Expression !(Vector (Pair SelectorCase Expression))
- | FunctionApplication !Expression !Expression
- | Terminal !UnresolvedValue
- data SelectorCase
- data UnresolvedValue
- = UBoolean !Bool
- | UString !Text
- | UInterpolable !(Vector Expression)
- | UUndef
- | UResourceReference !Text !Expression
- | UArray !(Vector Expression)
- | UHash !(Vector (Pair Expression Expression))
- | URegexp !CompRegex
- | UVariableReference !Text
- | UFunctionCall !Text !(Vector Expression)
- | UHOLambdaCall !HOLambdaCall
- | UNumber !Scientific
- | UDataType UDataType
- data LambdaFunc
- data HOLambdaCall = HOLambdaCall {}
- data ChainableRes
- class HasHOLambdaCall c where
- data LambdaParameter = LParam !(Maybe UDataType) !Text
- data LambdaParameters
- data CompRegex = CompRegex !Text !Regex
- data CollectorType
- data Virtuality
- data NodeDesc
- data LinkType
- = RRequire
- | RBefore
- | RNotify
- | RSubscribe
- data UDataType
- = UDTType
- | UDTString (Maybe Int) (Maybe Int)
- | UDTInteger (Maybe Int) (Maybe Int)
- | UDTFloat (Maybe Double) (Maybe Double)
- | UDTBoolean
- | UDTArray UDataType Int (Maybe Int)
- | UDTHash UDataType UDataType Int (Maybe Int)
- | UDTUndef
- | UDTScalar
- | UDTData
- | UDTOptional UDataType
- | UNotUndef
- | UDTVariant (NonEmpty UDataType)
- | UDTPattern (NonEmpty CompRegex)
- | UDTEnum (NonEmpty Expression)
- | UDTAny
- | UDTCollection
- | UDTRegexp (Maybe CompRegex)
- data SearchExpression
- data AttributeDecl
- data ArrowOp
- data ConditionalDecl = ConditionalDecl !(Vector (Pair Expression (Vector Statement))) !PPosition
- data ClassDecl = ClassDecl !Text !(Vector (Pair (Pair Text (Maybe UDataType)) (Maybe Expression))) !(Maybe Text) !(Vector Statement) !PPosition
- data ResDefaultDecl = ResDefaultDecl !Text !(Vector AttributeDecl) !PPosition
- data DepDecl = DepDecl !(Pair Text Expression) !(Pair Text Expression) !LinkType !PPosition
- data Statement
- = ResourceDeclaration !ResDecl
- | ResourceDefaultDeclaration !ResDefaultDecl
- | ResourceOverrideDeclaration !ResOverrideDecl
- | ResourceCollectionDeclaration !ResCollDecl
- | ClassDeclaration !ClassDecl
- | DefineDeclaration !DefineDecl
- | NodeDeclaration !NodeDecl
- | ConditionalDeclaration !ConditionalDecl
- | VarAssignmentDeclaration !VarAssignDecl
- | MainFunctionDeclaration !MainFuncDecl
- | HigherOrderLambdaDeclaration !HigherOrderLambdaDecl
- | DependencyDeclaration !DepDecl
- | TopContainer !(Vector Statement) !Statement
- data ResDecl = ResDecl !Text !Expression !(Vector AttributeDecl) !Virtuality !PPosition
- data ResOverrideDecl = ResOverrideDecl !Text !Expression !(Vector AttributeDecl) !PPosition
- data DefineDecl = DefineDecl !Text !(Vector (Pair (Pair Text (Maybe UDataType)) (Maybe Expression))) !(Vector Statement) !PPosition
- data NodeDecl = NodeDecl !NodeDesc !(Vector Statement) !(Maybe NodeDesc) !PPosition
- data VarAssignDecl = VarAssignDecl {}
- data MainFuncDecl = MainFuncDecl !Text !(Vector Expression) !PPosition
- data HigherOrderLambdaDecl = HigherOrderLambdaDecl !HOLambdaCall !PPosition
- data ResCollDecl = ResCollDecl !CollectorType !Text !SearchExpression !(Vector AttributeDecl) !PPosition
- _Statements :: Lens' Statement [Statement]
- _ResDecl :: Prism' Statement ResDecl
- _ResDefaultDecl :: Prism' Statement ResDefaultDecl
- _ResOverrDecl :: Prism' Statement ResOverrideDecl
- _ResCollDecl :: Prism' Statement ResCollDecl
- _ConditionalDecl :: Prism' Statement ConditionalDecl
- _ClassDecl :: Prism' Statement ClassDecl
- _DefineDecl :: Prism' Statement DefineDecl
- _NodeDecl :: Prism' Statement NodeDecl
- _VarAssignDecl :: Prism' Statement VarAssignDecl
- _MainFuncDecl :: Prism' Statement MainFuncDecl
- _HigherOrderLambdaDecl :: Prism' Statement HigherOrderLambdaDecl
- _DepDecl :: Prism' Statement DepDecl
- _Equal :: Prism' Expression (Expression, Expression)
- _Different :: Prism' Expression (Expression, Expression)
- _Not :: Prism' Expression Expression
- _And :: Prism' Expression (Expression, Expression)
- _Or :: Prism' Expression (Expression, Expression)
- _LessThan :: Prism' Expression (Expression, Expression)
- _MoreThan :: Prism' Expression (Expression, Expression)
- _LessEqualThan :: Prism' Expression (Expression, Expression)
- _MoreEqualThan :: Prism' Expression (Expression, Expression)
- _RegexMatch :: Prism' Expression (Expression, Expression)
- _NotRegexMatch :: Prism' Expression (Expression, Expression)
- _Contains :: Prism' Expression (Expression, Expression)
- _Addition :: Prism' Expression (Expression, Expression)
- _Substraction :: Prism' Expression (Expression, Expression)
- _Division :: Prism' Expression (Expression, Expression)
- _Multiplication :: Prism' Expression (Expression, Expression)
- _Modulo :: Prism' Expression (Expression, Expression)
- _RightShift :: Prism' Expression (Expression, Expression)
- _LeftShift :: Prism' Expression (Expression, Expression)
- _Lookup :: Prism' Expression (Expression, Expression)
- _Negate :: Prism' Expression Expression
- _ConditionalValue :: Prism' Expression (Expression, Vector (Pair SelectorCase Expression))
- _FunctionApplication :: Prism' Expression (Expression, Expression)
- _Terminal :: Prism' Expression UnresolvedValue
Runner
runPuppetParser :: String -> Text -> Either PuppetParseError (Vector Statement) #
Run a puppet parser against some Text input.
Parsers
type PuppetParseError = ParseError Char Void #
prettyParseError :: Text -> ParseError Char Void -> PrettyError #
Build a PrettyError from a ParseError given the text source.
The source is used to display the line on which the error occurs.
exposed to ease testing
expression :: Parser Expression #
Parse an Expression.
Pretty Print
ppStatements :: Vector Statement -> Doc #
Pretty print a series of statements.
Expressions
data Expression #
The Expressions
Constructors
| Equal !Expression !Expression | |
| Different !Expression !Expression | |
| Not !Expression | |
| And !Expression !Expression | |
| Or !Expression !Expression | |
| LessThan !Expression !Expression | |
| MoreThan !Expression !Expression | |
| LessEqualThan !Expression !Expression | |
| MoreEqualThan !Expression !Expression | |
| RegexMatch !Expression !Expression | |
| NotRegexMatch !Expression !Expression | |
| Contains !Expression !Expression | |
| Addition !Expression !Expression | |
| Substraction !Expression !Expression | |
| Division !Expression !Expression | |
| Multiplication !Expression !Expression | |
| Modulo !Expression !Expression | |
| RightShift !Expression !Expression | |
| LeftShift !Expression !Expression | |
| Lookup !Expression !Expression | |
| Negate !Expression | |
| ConditionalValue !Expression !(Vector (Pair SelectorCase Expression)) | All conditionals are stored in this format. |
| FunctionApplication !Expression !Expression | This is for higher order functions. |
| Terminal !UnresolvedValue | Terminal object contains no expression |
Instances
data SelectorCase #
Constructors
| SelectorValue !UnresolvedValue | |
| SelectorType !UDataType | |
| SelectorDefault |
Instances
data UnresolvedValue #
An unresolved value, typically the parser's output.
Constructors
| UBoolean !Bool | Special tokens generated when parsing the |
| UString !Text | Raw string. |
| UInterpolable !(Vector Expression) | A string that might contain variable references. The type should be refined at one point. |
| UUndef | Special token that is generated when parsing the |
| UResourceReference !Text !Expression | A Resource[reference] |
| UArray !(Vector Expression) | |
| UHash !(Vector (Pair Expression Expression)) | |
| URegexp !CompRegex | The regular expression compilation is performed during parsing. |
| UVariableReference !Text | |
| UFunctionCall !Text !(Vector Expression) | |
| UHOLambdaCall !HOLambdaCall | |
| UNumber !Scientific | |
| UDataType UDataType |
Instances
data LambdaFunc #
High Order lambdas.
Constructors
| LambEach | |
| LambMap | |
| LambReduce | |
| LambFilter | |
| LambSlice | |
| LambLookup |
Instances
data HOLambdaCall #
Constructors
| HOLambdaCall | |
Fields
| |
Instances
data ChainableRes #
Constructors
| ChainResColl !ResCollDecl | |
| ChainResDecl !ResDecl | |
| ChainResRefr !Text [Expression] !PPosition |
Instances
class HasHOLambdaCall c where #
Minimal complete definition
Methods
hOLambdaCall :: Lens' c HOLambdaCall #
hoLambdaExpr :: Lens' c (Maybe Expression) #
hoLambdaFunc :: Lens' c LambdaFunc #
hoLambdaLastExpr :: Lens' c (Maybe Expression) #
hoLambdaParams :: Lens' c LambdaParameters #
hoLambdaStatements :: Lens' c (Vector Statement) #
Instances
data LambdaParameter #
Instances
data LambdaParameters #
Lambda block parameters:
Currently only two types of block parameters are supported: single values and pairs.
Constructors
| BPSingle !LambdaParameter | |k| |
| BPPair !LambdaParameter !LambdaParameter | |k,v| |
Instances
data Virtuality #
Constructors
| Normal | Normal resource, that will be included in the catalog. |
| Virtual | Type for virtual resources. |
| Exported | Type for exported resources. |
| ExportedRealized | These are resources that are exported AND realized in the catalog. |
Instances
Constructors
| NodeName !Text | |
| NodeMatch !CompRegex | |
| NodeDefault |
Relationship/ordering between resources.
Constructors
| RRequire | Applies a resource after the target resource. |
| RBefore | Applies a resource before the target resource. |
| RNotify | Applies a resource before the target resource. The target resource refreshes if the notifying resource changes. |
| RSubscribe | Applies a resource after the target resource. The subscribing resource refreshes if the target resource changes. |
Datatypes
Constructors
Search Expressions
data SearchExpression #
Search expression inside collector `searchexpr |`
Constructors
| EqualitySearch !Text !Expression | |
| NonEqualitySearch !Text !Expression | |
| AndSearch !SearchExpression !SearchExpression | |
| OrSearch !SearchExpression !SearchExpression | |
| AlwaysTrue |
Instances
Declaration
data AttributeDecl #
Constructors
| AttributeDecl !Text !ArrowOp !Expression | |
| AttributeWildcard !Expression |
Instances
data ConditionalDecl #
All types of conditional statements : case, if, ...
Stored as an ordered list of pair (condition, statements) .
Interpreted as "if first cond is true, choose first statements, else take the next pair, check the condition ..."
Constructors
| ConditionalDecl !(Vector (Pair Expression (Vector Statement))) !PPosition |
Instances
Constructors
| DepDecl !(Pair Text Expression) !(Pair Text Expression) !LinkType !PPosition |
All possible statements.
Constructors
| ResourceDeclaration !ResDecl | |
| ResourceDefaultDeclaration !ResDefaultDecl | |
| ResourceOverrideDeclaration !ResOverrideDecl | |
| ResourceCollectionDeclaration !ResCollDecl | |
| ClassDeclaration !ClassDecl | |
| DefineDeclaration !DefineDecl | |
| NodeDeclaration !NodeDecl | |
| ConditionalDeclaration !ConditionalDecl | |
| VarAssignmentDeclaration !VarAssignDecl | |
| MainFunctionDeclaration !MainFuncDecl | |
| HigherOrderLambdaDeclaration !HigherOrderLambdaDecl | |
| DependencyDeclaration !DepDecl | |
| TopContainer !(Vector Statement) !Statement | Special statement used to include the expressions that are top level. Certainly buggy, but probably just like the original implementation. |
Resource declaration:
file { mode => 755}Constructors
| ResDecl !Text !Expression !(Vector AttributeDecl) !Virtuality !PPosition |
data ResOverrideDecl #
Constructors
| ResOverrideDecl !Text !Expression !(Vector AttributeDecl) !PPosition |
Instances
data DefineDecl #
Constructors
| DefineDecl !Text !(Vector (Pair (Pair Text (Maybe UDataType)) (Maybe Expression))) !(Vector Statement) !PPosition |
Instances
A node is a collection of statements + maybe an inherit node.
data HigherOrderLambdaDecl #
Higher order function call.
Constructors
| HigherOrderLambdaDecl !HOLambdaCall !PPosition |
Instances
data ResCollDecl #
Resource Collector including exported collector (`<<| |>>`)
User <| title == jenkins |> { groups +> "docker"}See puppet reference
Constructors
| ResCollDecl !CollectorType !Text !SearchExpression !(Vector AttributeDecl) !PPosition |
Instances
Prism for Statements
_Statements :: Lens' Statement [Statement] #
Prism for Expressions
_Equal :: Prism' Expression (Expression, Expression) #
_And :: Prism' Expression (Expression, Expression) #
_Or :: Prism' Expression (Expression, Expression) #
_Modulo :: Prism' Expression (Expression, Expression) #
_Lookup :: Prism' Expression (Expression, Expression) #