pypuppetdbquery.parser module

exception pypuppetdbquery.parser.ParseException(message, position)[source]

Bases: Exception

Raised for errors encountered during parsing.

The position of the lexer when the error was encountered (the index into the input string) is stored in the position attribute.

class pypuppetdbquery.parser.Parser(lex_options=None, yacc_options=None)[source]

Bases: object

Parser for the PuppetDBQuery language.

This class uses ply.yacc.yacc() to implement the parser. In concert with pypuppetdbquery.lexer.Lexer, it produces an Abstract Syntax Tree (AST) as declared in pypuppetdbquery.ast.

Parameters:
  • lex_options (dict) – Passed as keyword arguments to pypuppetdbquery.lexer.Lexer
  • yacc_options (dict) – Passed as keyword arguments to ply.yacc.yacc()

Note

Many of the docstrings in this class are used by ply.yacc to build the parser. These strings are not particularly useful for generating documentation from, so the built documentation for this class may not be very useful.

p_block_expr(p)[source]

block_expr : LBRACE expr RBRACE

p_boolean(p)[source]

boolean : BOOLEAN

p_comparison_expr(p)[source]

comparison_expr : identifier_path comparison_op literal

p_comparison_op(p)[source]
comparison_op : MATCH
NOTMATCH
EQUALS
NOTEQUALS
GREATERTHAN
GREATERTHANEQ
LESSTHAN
LESSTHANEQ
p_empty(p)[source]

empty :

p_error(p)[source]
p_expr(p)[source]
expr : resource_expr
comparison_expr
subquery
p_expr_and(p)[source]

expr : expr AND expr

p_expr_identifier_path(p)[source]

expr : identifier_path

p_expr_not(p)[source]

expr : NOT expr

p_expr_or(p)[source]

expr : expr OR expr

p_expr_parenthesized(p)[source]

expr : LPAREN expr RPAREN

p_float(p)[source]

float : FLOAT

p_identifier(p)[source]
identifier : string
integer
p_identifier_path(p)[source]

identifier_path : identifier

p_identifier_path_nested(p)[source]

identifier_path : identifier_path DOT identifier

p_identifier_regexp(p)[source]

identifier : MATCH string

p_identifier_wild(p)[source]

identifier : ASTERISK

p_integer(p)[source]

integer : NUMBER

p_literal(p)[source]
literal : boolean
string
integer
float
p_literal_date(p)[source]

literal : AT string

p_query(p)[source]
query : expr
empty
p_resource_expr(p)[source]

resource_expr : string LBRACK identifier RBRACK

p_resource_expr_exported(p)[source]

resource_expr : EXPORTED string LBRACK identifier RBRACK

p_resource_expr_exported_param(p)[source]

resource_expr : EXPORTED string LBRACK identifier RBRACK block_expr

p_resource_expr_param(p)[source]

resource_expr : string LBRACK identifier RBRACK block_expr

p_string(p)[source]

string : STRING

p_subquery_block(p)[source]

subquery : HASH string block_expr

p_subquery_comparison(p)[source]

subquery : HASH string DOT comparison_expr

parse(text, debug=0)[source]

Parse the input string and return an AST.

Parameters:
  • text (str) – The query to parse
  • debug (bool) – Output detailed information during the parsing process
Returns:

An Abstract Syntax Tree

Return type:

pypuppetdbquery.ast.Query

precedence = (('left', 'OR'), ('left', 'AND'), ('left', 'EQUALS', 'MATCH', 'LESSTHAN', 'GREATERTHAN'), ('right', 'NOT'))

Precedence rules in lowest to highest order

start = 'query'

Non-terminal to use as the starting grammar symbol