<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">"""
    pygments.lexers.ul4
    ~~~~~~~~~~~~~~~~~~~

    Lexer for the UL4 templating language.

    :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import re

from pygments.lexer import RegexLexer, DelegatingLexer, bygroups, words, include
from pygments.token import Comment, Text, Keyword, String, Number, Literal, \
    Name, Other, Operator
from pygments.lexers.web import HtmlLexer, XmlLexer, CssLexer, JavascriptLexer
from pygments.lexers.python import PythonLexer

__all__ = ['UL4Lexer', 'HTMLUL4Lexer', 'XMLUL4Lexer', 'CSSUL4Lexer',
           'JavascriptUL4Lexer', 'PythonUL4Lexer']


class UL4Lexer(RegexLexer):
    """
    Generic lexer for UL4.
    """

    flags = re.MULTILINE | re.DOTALL

    name = 'UL4'
    aliases = ['ul4']
    filenames = ['*.ul4']
    url = 'https://python.livinglogic.de/UL4.html'
    version_added = '2.12'

    tokens = {
        "root": [
            (
                # Template header without name:
                # ``&lt;?ul4?&gt;``
                r"(&lt;\?)(\s*)(ul4)(\s*)(\?&gt;)",
                bygroups(Comment.Preproc, Text.Whitespace, Keyword,
                         Text.Whitespace, Comment.Preproc),
            ),
            (
                # Template header with name (potentially followed by the signature):
                # ``&lt;?ul4 foo(bar=42)?&gt;``
                r"(&lt;\?)(\s*)(ul4)(\s*)([a-zA-Z_][a-zA-Z_0-9]*)?",
                bygroups(Comment.Preproc, Text.Whitespace, Keyword,
                         Text.Whitespace, Name.Function),
                "ul4", # Switch to "expression" mode
            ),
            (
                # Comment:
                # ``&lt;?note?&gt;...&lt;?end note?&gt;``
                r"&lt;\?\s*note\s*\?&gt;",
                Comment,
                "note", # Switch to "note" mode
            ),
            (
                # Comment:
                # ``&lt;?note foobar?&gt;``
                r"&lt;\?\s*note\s.*?\?&gt;",
                Comment,
            ),
            (
                # Template documentation:
                # ``&lt;?doc?&gt;...&lt;?end doc?&gt;``
                r"&lt;\?\s*doc\s*\?&gt;",
                String.Doc,
                "doc",
            ),
            (
                # Template documentation:
                # ``&lt;?doc foobar?&gt;``
                r"&lt;\?\s*doc\s.*?\?&gt;",
                String.Doc,
            ),
            (
                # ``&lt;?ignore?&gt;`` tag for commenting out code:
                # ``&lt;?ignore?&gt;...&lt;?end ignore?&gt;``
                r"&lt;\?\s*ignore\s*\?&gt;",
                Comment,
                "ignore", # Switch to "ignore" mode
            ),
            (
                # ``&lt;?def?&gt;`` tag for defining local templates
                # ``&lt;?def foo(bar=42)?&gt;...&lt;?end def?&gt;``
                r"(&lt;\?)(\s*)(def)(\s*)([a-zA-Z_][a-zA-Z_0-9]*)?",
                bygroups(Comment.Preproc, Text.Whitespace, Keyword,
                         Text.Whitespace, Name.Function),
                "ul4", # Switch to "expression" mode
            ),
            (
                # The rest of the supported tags
                r"(&lt;\?)(\s*)(printx|print|for|if|elif|else|while|code|renderblocks?|render)\b",
                bygroups(Comment.Preproc, Text.Whitespace, Keyword),
                "ul4", # Switch to "expression" mode
            ),
            (
                # ``&lt;?end?&gt;`` tag for ending ``&lt;?def?&gt;``, ``&lt;?for?&gt;``,
                # ``&lt;?if?&gt;``, ``&lt;?while?&gt;``, ``&lt;?renderblock?&gt;`` and
                # ``&lt;?renderblocks?&gt;`` blocks.
                r"(&lt;\?)(\s*)(end)\b",
                bygroups(Comment.Preproc, Text.Whitespace, Keyword),
                "end", # Switch to "end tag" mode
            ),
            (
                # ``&lt;?whitespace?&gt;`` tag for configuring whitespace handlng
                r"(&lt;\?)(\s*)(whitespace)\b",
                bygroups(Comment.Preproc, Text.Whitespace, Keyword),
                "whitespace", # Switch to "whitespace" mode
            ),
            # Plain text
            (r"[^&lt;]+", Other),
            (r"&lt;", Other),
        ],
        # Ignore mode ignores everything upto the matching ``&lt;?end ignore?&gt;`` tag
        "ignore": [
            # Nested ``&lt;?ignore?&gt;`` tag
            (r"&lt;\?\s*ignore\s*\?&gt;", Comment, "#push"),
            # ``&lt;?end ignore?&gt;`` tag
            (r"&lt;\?\s*end\s+ignore\s*\?&gt;", Comment, "#pop"),
            # Everything else
            (r"[^&lt;]+", Comment),
            (r".", Comment),
        ],
        # Note mode ignores everything upto the matching ``&lt;?end note?&gt;`` tag
        "note": [
            # Nested ``&lt;?note?&gt;`` tag
            (r"&lt;\?\s*note\s*\?&gt;", Comment, "#push"),
            # ``&lt;?end note?&gt;`` tag
            (r"&lt;\?\s*end\s+note\s*\?&gt;", Comment, "#pop"),
            # Everything else
            (r"[^&lt;]+", Comment),
            (r".", Comment),
        ],
        # Doc mode ignores everything upto the matching ``&lt;?end doc?&gt;`` tag
        "doc": [
            # Nested ``&lt;?doc?&gt;`` tag
            (r"&lt;\?\s*doc\s*\?&gt;", String.Doc, "#push"),
            # ``&lt;?end doc?&gt;`` tag
            (r"&lt;\?\s*end\s+doc\s*\?&gt;", String.Doc, "#pop"),
            # Everything else
            (r"[^&lt;]+", String.Doc),
            (r".", String.Doc),
        ],
        # UL4 expressions
        "ul4": [
            # End the tag
            (r"\?&gt;", Comment.Preproc, "#pop"),
            # Start triple quoted string constant
            ("'''", String, "string13"),
            ('"""', String, "string23"),
            # Start single quoted string constant
            ("'", String, "string1"),
            ('"', String, "string2"),
            # Floating point number
            (r"\d+\.\d*([eE][+-]?\d+)?", Number.Float),
            (r"\.\d+([eE][+-]?\d+)?", Number.Float),
            (r"\d+[eE][+-]?\d+", Number.Float),
            # Binary integer: ``0b101010``
            (r"0[bB][01]+", Number.Bin),
            # Octal integer: ``0o52``
            (r"0[oO][0-7]+", Number.Oct),
            # Hexadecimal integer: ``0x2a``
            (r"0[xX][0-9a-fA-F]+", Number.Hex),
            # Date or datetime: ``@(2000-02-29)``/``@(2000-02-29T12:34:56.987654)``
            (r"@\(\d\d\d\d-\d\d-\d\d(T(\d\d:\d\d(:\d\d(\.\d{6})?)?)?)?\)", Literal.Date),
            # Color: ``#fff``, ``#fff8f0`` etc.
            (r"#[0-9a-fA-F]{8}", Literal.Color),
            (r"#[0-9a-fA-F]{6}", Literal.Color),
            (r"#[0-9a-fA-F]{3,4}", Literal.Color),
            # Decimal integer: ``42``
            (r"\d+", Number.Integer),
            # Operators
            (r"//|==|!=|&gt;=|&lt;=|&lt;&lt;|&gt;&gt;|\+=|-=|\*=|/=|//=|&lt;&lt;=|&gt;&gt;=|&amp;=|\|=|^=|=|[\[\]{},:*/().~%&amp;|&lt;&gt;^+-]", Operator),
            # Keywords
            (words(("for", "in", "if", "else", "not", "is", "and", "or"), suffix=r"\b"), Keyword),
            # Builtin constants
            (words(("None", "False", "True"), suffix=r"\b"), Keyword.Constant),
            # Variable names
            (r"[a-zA-Z_][a-zA-Z0-9_]*", Name),
            # Whitespace
            (r"\s+", Text.Whitespace),
        ],
        # ``&lt;?end ...?&gt;`` tag for closing the last open block
        "end": [
            (r"\?&gt;", Comment.Preproc, "#pop"),
            (words(("for", "if", "def", "while", "renderblock", "renderblocks"), suffix=r"\b"), Keyword),
            (r"\s+", Text),
        ],
        # Content of the ``&lt;?whitespace ...?&gt;`` tag:
        # ``keep``, ``strip`` or ``smart``
        "whitespace": [
            (r"\?&gt;", Comment.Preproc, "#pop"),
            (words(("keep", "strip", "smart"), suffix=r"\b"), Comment.Preproc),
            (r"\s+", Text.Whitespace),
        ],
        # Inside a string constant
        "stringescapes": [
            (r"""\\[\\'"abtnfr]""", String.Escape),
            (r"\\x[0-9a-fA-F]{2}", String.Escape),
            (r"\\u[0-9a-fA-F]{4}", String.Escape),
            (r"\\U[0-9a-fA-F]{8}", String.Escape),
        ],
        # Inside a triple quoted string started with ``'''``
        "string13": [
            (r"'''", String, "#pop"),
            include("stringescapes"),
            (r"[^\\']+", String),
            (r'.', String),
        ],
        # Inside a triple quoted string started with ``"""``
        "string23": [
            (r'"""', String, "#pop"),
            include("stringescapes"),
            (r'[^\\"]+', String),
            (r'.', String),
        ],
        # Inside a single quoted string started with ``'``
        "string1": [
            (r"'", String, "#pop"),
            include("stringescapes"),
            (r"[^\\']+", String),
            (r'.', String),
        ],
        # Inside a single quoted string started with ``"``
        "string2": [
            (r'"', String, "#pop"),
            include("stringescapes"),
            (r'[^\\"]+', String),
            (r'.', String),
        ],
    }

class HTMLUL4Lexer(DelegatingLexer):
    """
    Lexer for UL4 embedded in HTML.
    """

    name = 'HTML+UL4'
    aliases = ['html+ul4']
    filenames = ['*.htmlul4']
    url = 'https://python.livinglogic.de/UL4.html'
    version_added = ''

    def __init__(self, **options):
        super().__init__(HtmlLexer, UL4Lexer, **options)


class XMLUL4Lexer(DelegatingLexer):
    """
    Lexer for UL4 embedded in XML.
    """

    name = 'XML+UL4'
    aliases = ['xml+ul4']
    filenames = ['*.xmlul4']
    url = 'https://python.livinglogic.de/UL4.html'
    version_added = ''

    def __init__(self, **options):
        super().__init__(XmlLexer, UL4Lexer, **options)


class CSSUL4Lexer(DelegatingLexer):
    """
    Lexer for UL4 embedded in CSS.
    """

    name = 'CSS+UL4'
    aliases = ['css+ul4']
    filenames = ['*.cssul4']
    url = 'https://python.livinglogic.de/UL4.html'
    version_added = ''

    def __init__(self, **options):
        super().__init__(CssLexer, UL4Lexer, **options)


class JavascriptUL4Lexer(DelegatingLexer):
    """
    Lexer for UL4 embedded in Javascript.
    """

    name = 'Javascript+UL4'
    aliases = ['js+ul4']
    filenames = ['*.jsul4']
    url = 'https://python.livinglogic.de/UL4.html'
    version_added = ''

    def __init__(self, **options):
        super().__init__(JavascriptLexer, UL4Lexer, **options)


class PythonUL4Lexer(DelegatingLexer):
    """
    Lexer for UL4 embedded in Python.
    """

    name = 'Python+UL4'
    aliases = ['py+ul4']
    filenames = ['*.pyul4']
    url = 'https://python.livinglogic.de/UL4.html'
    version_added = ''

    def __init__(self, **options):
        super().__init__(PythonLexer, UL4Lexer, **options)
</pre></body></html>