How to use the jinja.datastructure.StateTest.expect_token function in Jinja

To help you get started, we’ve selected a few Jinja examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pallets / jinja / jinja / parser.py View on Github external
"""
from jinja import nodes
from jinja.datastructure import StateTest
from jinja.exceptions import TemplateSyntaxError
from jinja.utils import set


__all__ = ['Parser']


# general callback functions for the parser
end_of_block = StateTest.expect_token('block_end',
                                      msg='expected end of block tag')
end_of_variable = StateTest.expect_token('variable_end',
                                         msg='expected end of variable')
end_of_comment = StateTest.expect_token('comment_end',
                                        msg='expected end of comment')

# internal tag callbacks
switch_for = StateTest.expect_token('else', 'endfor')
end_of_for = StateTest.expect_token('endfor')
switch_if = StateTest.expect_token('else', 'elif', 'endif')
end_of_if = StateTest.expect_token('endif')
end_of_filter = StateTest.expect_token('endfilter')
end_of_macro = StateTest.expect_token('endmacro')
end_of_call = StateTest.expect_token('endcall')
end_of_block_tag = StateTest.expect_token('endblock')
end_of_trans = StateTest.expect_token('endtrans')

# this ends a tuple
tuple_edge_tokens = set(['rparen', 'block_end', 'variable_end', 'in',
                         'recursive'])
github pallets / jinja / jinja / parser.py View on Github external
__all__ = ['Parser']


# general callback functions for the parser
end_of_block = StateTest.expect_token('block_end',
                                      msg='expected end of block tag')
end_of_variable = StateTest.expect_token('variable_end',
                                         msg='expected end of variable')
end_of_comment = StateTest.expect_token('comment_end',
                                        msg='expected end of comment')

# internal tag callbacks
switch_for = StateTest.expect_token('else', 'endfor')
end_of_for = StateTest.expect_token('endfor')
switch_if = StateTest.expect_token('else', 'elif', 'endif')
end_of_if = StateTest.expect_token('endif')
end_of_filter = StateTest.expect_token('endfilter')
end_of_macro = StateTest.expect_token('endmacro')
end_of_call = StateTest.expect_token('endcall')
end_of_block_tag = StateTest.expect_token('endblock')
end_of_trans = StateTest.expect_token('endtrans')

# this ends a tuple
tuple_edge_tokens = set(['rparen', 'block_end', 'variable_end', 'in',
                         'recursive'])


class Parser(object):
    """
    The template parser class.
github pallets / jinja / jinja / parser.py View on Github external
:copyright: 2007 by Armin Ronacher.
    :license: BSD, see LICENSE for more details.
"""
from jinja import nodes
from jinja.datastructure import StateTest
from jinja.exceptions import TemplateSyntaxError
from jinja.utils import set


__all__ = ['Parser']


# general callback functions for the parser
end_of_block = StateTest.expect_token('block_end',
                                      msg='expected end of block tag')
end_of_variable = StateTest.expect_token('variable_end',
                                         msg='expected end of variable')
end_of_comment = StateTest.expect_token('comment_end',
                                        msg='expected end of comment')

# internal tag callbacks
switch_for = StateTest.expect_token('else', 'endfor')
end_of_for = StateTest.expect_token('endfor')
switch_if = StateTest.expect_token('else', 'elif', 'endif')
end_of_if = StateTest.expect_token('endif')
end_of_filter = StateTest.expect_token('endfilter')
end_of_macro = StateTest.expect_token('endmacro')
end_of_call = StateTest.expect_token('endcall')
end_of_block_tag = StateTest.expect_token('endblock')
end_of_trans = StateTest.expect_token('endtrans')

# this ends a tuple
github pallets / jinja / jinja / parser.py View on Github external
__all__ = ['Parser']


# general callback functions for the parser
end_of_block = StateTest.expect_token('block_end',
                                      msg='expected end of block tag')
end_of_variable = StateTest.expect_token('variable_end',
                                         msg='expected end of variable')
end_of_comment = StateTest.expect_token('comment_end',
                                        msg='expected end of comment')

# internal tag callbacks
switch_for = StateTest.expect_token('else', 'endfor')
end_of_for = StateTest.expect_token('endfor')
switch_if = StateTest.expect_token('else', 'elif', 'endif')
end_of_if = StateTest.expect_token('endif')
end_of_filter = StateTest.expect_token('endfilter')
end_of_macro = StateTest.expect_token('endmacro')
end_of_call = StateTest.expect_token('endcall')
end_of_block_tag = StateTest.expect_token('endblock')
end_of_trans = StateTest.expect_token('endtrans')

# this ends a tuple
tuple_edge_tokens = set(['rparen', 'block_end', 'variable_end', 'in',
                         'recursive'])


class Parser(object):
    """
    The template parser class.
github pallets / jinja / jinja / parser.py View on Github external
# general callback functions for the parser
end_of_block = StateTest.expect_token('block_end',
                                      msg='expected end of block tag')
end_of_variable = StateTest.expect_token('variable_end',
                                         msg='expected end of variable')
end_of_comment = StateTest.expect_token('comment_end',
                                        msg='expected end of comment')

# internal tag callbacks
switch_for = StateTest.expect_token('else', 'endfor')
end_of_for = StateTest.expect_token('endfor')
switch_if = StateTest.expect_token('else', 'elif', 'endif')
end_of_if = StateTest.expect_token('endif')
end_of_filter = StateTest.expect_token('endfilter')
end_of_macro = StateTest.expect_token('endmacro')
end_of_call = StateTest.expect_token('endcall')
end_of_block_tag = StateTest.expect_token('endblock')
end_of_trans = StateTest.expect_token('endtrans')

# this ends a tuple
tuple_edge_tokens = set(['rparen', 'block_end', 'variable_end', 'in',
                         'recursive'])


class Parser(object):
    """
    The template parser class.

    Transforms sourcecode into an abstract syntax tree.
    """

    def __init__(self, environment, source, filename=None):
github pallets / jinja / jinja / parser.py View on Github external
msg='expected end of block tag')
end_of_variable = StateTest.expect_token('variable_end',
                                         msg='expected end of variable')
end_of_comment = StateTest.expect_token('comment_end',
                                        msg='expected end of comment')

# internal tag callbacks
switch_for = StateTest.expect_token('else', 'endfor')
end_of_for = StateTest.expect_token('endfor')
switch_if = StateTest.expect_token('else', 'elif', 'endif')
end_of_if = StateTest.expect_token('endif')
end_of_filter = StateTest.expect_token('endfilter')
end_of_macro = StateTest.expect_token('endmacro')
end_of_call = StateTest.expect_token('endcall')
end_of_block_tag = StateTest.expect_token('endblock')
end_of_trans = StateTest.expect_token('endtrans')

# this ends a tuple
tuple_edge_tokens = set(['rparen', 'block_end', 'variable_end', 'in',
                         'recursive'])


class Parser(object):
    """
    The template parser class.

    Transforms sourcecode into an abstract syntax tree.
    """

    def __init__(self, environment, source, filename=None):
        self.environment = environment
        if isinstance(source, str):
github pallets / jinja / jinja / parser.py View on Github external
__all__ = ['Parser']


# general callback functions for the parser
end_of_block = StateTest.expect_token('block_end',
                                      msg='expected end of block tag')
end_of_variable = StateTest.expect_token('variable_end',
                                         msg='expected end of variable')
end_of_comment = StateTest.expect_token('comment_end',
                                        msg='expected end of comment')

# internal tag callbacks
switch_for = StateTest.expect_token('else', 'endfor')
end_of_for = StateTest.expect_token('endfor')
switch_if = StateTest.expect_token('else', 'elif', 'endif')
end_of_if = StateTest.expect_token('endif')
end_of_filter = StateTest.expect_token('endfilter')
end_of_macro = StateTest.expect_token('endmacro')
end_of_call = StateTest.expect_token('endcall')
end_of_block_tag = StateTest.expect_token('endblock')
end_of_trans = StateTest.expect_token('endtrans')

# this ends a tuple
tuple_edge_tokens = set(['rparen', 'block_end', 'variable_end', 'in',
                         'recursive'])


class Parser(object):
    """
    The template parser class.

    Transforms sourcecode into an abstract syntax tree.
github pallets / jinja / jinja / parser.py View on Github external
# general callback functions for the parser
end_of_block = StateTest.expect_token('block_end',
                                      msg='expected end of block tag')
end_of_variable = StateTest.expect_token('variable_end',
                                         msg='expected end of variable')
end_of_comment = StateTest.expect_token('comment_end',
                                        msg='expected end of comment')

# internal tag callbacks
switch_for = StateTest.expect_token('else', 'endfor')
end_of_for = StateTest.expect_token('endfor')
switch_if = StateTest.expect_token('else', 'elif', 'endif')
end_of_if = StateTest.expect_token('endif')
end_of_filter = StateTest.expect_token('endfilter')
end_of_macro = StateTest.expect_token('endmacro')
end_of_call = StateTest.expect_token('endcall')
end_of_block_tag = StateTest.expect_token('endblock')
end_of_trans = StateTest.expect_token('endtrans')

# this ends a tuple
tuple_edge_tokens = set(['rparen', 'block_end', 'variable_end', 'in',
                         'recursive'])


class Parser(object):
    """
    The template parser class.

    Transforms sourcecode into an abstract syntax tree.
    """
github pallets / jinja / jinja / parser.py View on Github external
from jinja.utils import set


__all__ = ['Parser']


# general callback functions for the parser
end_of_block = StateTest.expect_token('block_end',
                                      msg='expected end of block tag')
end_of_variable = StateTest.expect_token('variable_end',
                                         msg='expected end of variable')
end_of_comment = StateTest.expect_token('comment_end',
                                        msg='expected end of comment')

# internal tag callbacks
switch_for = StateTest.expect_token('else', 'endfor')
end_of_for = StateTest.expect_token('endfor')
switch_if = StateTest.expect_token('else', 'elif', 'endif')
end_of_if = StateTest.expect_token('endif')
end_of_filter = StateTest.expect_token('endfilter')
end_of_macro = StateTest.expect_token('endmacro')
end_of_call = StateTest.expect_token('endcall')
end_of_block_tag = StateTest.expect_token('endblock')
end_of_trans = StateTest.expect_token('endtrans')

# this ends a tuple
tuple_edge_tokens = set(['rparen', 'block_end', 'variable_end', 'in',
                         'recursive'])


class Parser(object):
    """