Package spade :: Module pyratemp :: Class Parser
[hide private]
[frames] | no frames]

Class Parser

source code


Parse a template into a parse-tree.

:TODO: describe the parse-tree

Instance Methods [hide private]
 
__init__(self, loadfunc=None, testexpr=None, escape=0)
Init the parser.
source code
 
parse(self, template)
Parse a template.
source code
 
_errpos(self, fpos)
Convert fpos to (filename,row,column) for error-messages.
source code
 
_testexpr(self, expr, fpos=0)
Test a template-expression to detect errors.
source code
 
_parse(self, template, fpos=0)
Recursive part of parse().
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  _comment_start = '#!'
  _comment_end = '!#'
  _sub_start = '$!'
  _sub_end = '!$'
  _subesc_start = '@!'
  _subesc_end = '!@'
  _block_start = '<!--('
  _block_end = ')-->'
  _strComment = '\\#\\!(?P<content>.*?)(?P<end>\\!\\#|\\n|$)'
  _reComment = re.compile(r'(?m)#!(?P<content>.*?)(?P<end>!#|\n|...
  _strSubstitution = '\n (\n ...
  _reSubstitution = re.compile(r'(?mx)(\$!\s*(?P<sub>.*?)\s*(?P<...
  _strBlock = '\n ^(?P<mEnd>[ \\t]*)\\<\\!\\-...
  _reBlock = re.compile(r'(?mx)^(?P<mEnd>[ \t]*)<!--\(end\)-->(?...
  _strForParam = '^(?P<names>\\w+(?:\\s*,\\s*\\w+)*)\\s+in\\s+(?...
  _reForParam = re.compile(r'^(?P<names>\w+(?:\s*,\s*\w+)*)\s+in...
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, loadfunc=None, testexpr=None, escape=0)
(Constructor)

source code 

Init the parser.

:Parameters:

  • loadfunc: function to load included templates (i.e. FileLoader(...).load)
  • testexpr: function to test if a template-expressions is valid (i.e. TempateEval().compile)
  • escape: default-escaping (may be modified by the template <- TODO)
Overrides: object.__init__

parse(self, template)

source code 

Parse a template.

:Parameters:

  • template: template-unicode-string

:Returns: the resulting parse-tree :Raises:

  • TemplateSyntaxError: for template-syntax-errors
  • TemplateIncludeError: if template-inclusion failed
  • TemplateException

Class Variable Details [hide private]

_reComment

Value:
re.compile(r'(?m)#!(?P<content>.*?)(?P<end>!#|\n|$)')

_strSubstitution

Value:
'''
                    (
                    \\$\\!\\s*(?P<sub>.*?)\\s*(?P<end>\\!\\$|$)       \
#substitution
                    |
                    \\@\\!\\s*(?P<escsub>.*?)\\s*(?P<escend>\\!\\@|$) \
#escaped substitution
                    )
...

_reSubstitution

Value:
re.compile(r'(?mx)(\$!\s*(?P<sub>.*?)\s*(?P<end>!\$|$)|@!\s*(?P<escsub\
>.*?)\s*(?P<escend>!@|$))')

_strBlock

Value:
'''
                    ^(?P<mEnd>[ \\t]*)\\<\\!\\-\\-\\(end\\)\\-\\-\\>(?\
P<meIgnored>.*)\\r?\\n? # multi-line end  (^   <!--(end)-->IGNORED_TEX\
T\\n)
                    |
                    (?P<sEnd>)\\<\\!\\-\\-\\(end\\)\\-\\-\\>          \
                     # single-line end (<!--(end)-->)
                    |
...

_reBlock

Value:
re.compile(r'(?mx)^(?P<mEnd>[ \t]*)<!--\(end\)-->(?P<meIgnored>.*)\r?\\
n?|(?P<sEnd>)<!--\(end\)-->|(?P<sSpace>\s*)<!--\((?P<sKeyw>\w+)[ \t]*(\
?P<sParam>.*?)\)-->(?P<sContent>.*?)(?=(?:<!--\(.*?\)-->.*?)??<!--\(en\
d\)-->)|^(?P<indent>[ \t]*)<!--\((?P<mKeyw>\w+)\s*(?P<mParam>.*?)\)-->\
(?P<mIgnored>.*)\r?\n(?P<mContent>(?:.*\n)*?)(?=\8<!--\((?:.|\s)*?\)--\
>)')

_strForParam

Value:
'^(?P<names>\\w+(?:\\s*,\\s*\\w+)*)\\s+in\\s+(?P<iter>.+)$'

_reForParam

Value:
re.compile(r'^(?P<names>\w+(?:\s*,\s*\w+)*)\s+in\s+(?P<iter>.+)$')