2222
2323
2424class ParseException (Exception ):
25+ """
26+ Raised for errors encountered during parsing.
27+
28+ The position of the lexer when the error was encountered (the index into
29+ the input string) is stored in the `position` attribute.
30+ """
2531 def __init__ (self , message , position ):
2632 super (ParseException , self ).__init__ (message )
2733 self .position = position
2834
2935
3036class Parser (object ):
3137 """
32- Parser for the PuppetDB query language.
38+ Parser for the PuppetDBQuery language.
39+
40+ This class uses :func:`ply.yacc.yacc` to implement the parser. In concert
41+ with :class:`pypuppetdbquery.lexer.Lexer`, it produces an Abstract Syntax
42+ Tree (AST) as declared in :mod:`pypuppetdbquery.ast`.
43+
44+ :param dict lex_options: Passed as keyword arguments to
45+ :class:`pypuppetdbquery.lexer.Lexer`
46+ :param dict yacc_options: Passed as keyword arguments to
47+ :func:`ply.yacc.yacc`
48+
49+ .. note:: Many of the docstrings in this class are used by :mod:`ply.yacc`
50+ to build the parser. These strings are not particularly useful for
51+ generating documentation from, so the built documentation for this class
52+ may not be very useful.
3353 """
3454 def __init__ (self , lex_options = None , yacc_options = None ):
3555 super (Parser , self ).__init__ ()
@@ -48,8 +68,18 @@ def __init__(self, lex_options=None, yacc_options=None):
4868 self .parser = yacc .yacc (module = self , ** yacc_options )
4969
5070 def parse (self , text , debug = 0 ):
71+ """
72+ Parse the input string and return an AST.
73+
74+ :param str text: The query to parse
75+ :param bool debug: Output detailed information during the parsing
76+ process
77+ :return: An Abstract Syntax Tree
78+ :rtype: pypuppetdbquery.ast.Query
79+ """
5180 return self .parser .parse (input = text , lexer = self .lexer , debug = debug )
5281
82+ #: Non-terminal to use as the starting grammar symbol
5383 start = 'query'
5484
5585 def p_query (self , p ):
@@ -189,6 +219,7 @@ def p_empty(self, p):
189219 'empty :'
190220 pass
191221
222+ #: Precedence rules in lowest to highest order
192223 precedence = (
193224 ('left' , 'OR' ),
194225 ('left' , 'AND' ),
0 commit comments