|
""" |
|
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": [ |
|
( |
|
|
|
|
|
r"(<\?)(\s*)(ul4)(\s*)(\?>)", |
|
bygroups(Comment.Preproc, Text.Whitespace, Keyword, |
|
Text.Whitespace, Comment.Preproc), |
|
), |
|
( |
|
|
|
|
|
r"(<\?)(\s*)(ul4)(\s*)([a-zA-Z_][a-zA-Z_0-9]*)?", |
|
bygroups(Comment.Preproc, Text.Whitespace, Keyword, |
|
Text.Whitespace, Name.Function), |
|
"ul4", |
|
), |
|
( |
|
|
|
|
|
r"<\?\s*note\s*\?>", |
|
Comment, |
|
"note", |
|
), |
|
( |
|
|
|
|
|
r"<\?\s*note\s.*?\?>", |
|
Comment, |
|
), |
|
( |
|
|
|
|
|
r"<\?\s*doc\s*\?>", |
|
String.Doc, |
|
"doc", |
|
), |
|
( |
|
|
|
|
|
r"<\?\s*doc\s.*?\?>", |
|
String.Doc, |
|
), |
|
( |
|
|
|
|
|
r"<\?\s*ignore\s*\?>", |
|
Comment, |
|
"ignore", |
|
), |
|
( |
|
|
|
|
|
r"(<\?)(\s*)(def)(\s*)([a-zA-Z_][a-zA-Z_0-9]*)?", |
|
bygroups(Comment.Preproc, Text.Whitespace, Keyword, |
|
Text.Whitespace, Name.Function), |
|
"ul4", |
|
), |
|
( |
|
|
|
r"(<\?)(\s*)(printx|print|for|if|elif|else|while|code|renderblocks?|render)\b", |
|
bygroups(Comment.Preproc, Text.Whitespace, Keyword), |
|
"ul4", |
|
), |
|
( |
|
|
|
|
|
|
|
r"(<\?)(\s*)(end)\b", |
|
bygroups(Comment.Preproc, Text.Whitespace, Keyword), |
|
"end", |
|
), |
|
( |
|
|
|
r"(<\?)(\s*)(whitespace)\b", |
|
bygroups(Comment.Preproc, Text.Whitespace, Keyword), |
|
"whitespace", |
|
), |
|
|
|
(r"[^<]+", Other), |
|
(r"<", Other), |
|
], |
|
|
|
"ignore": [ |
|
|
|
(r"<\?\s*ignore\s*\?>", Comment, "#push"), |
|
|
|
(r"<\?\s*end\s+ignore\s*\?>", Comment, "#pop"), |
|
|
|
(r"[^<]+", Comment), |
|
(r".", Comment), |
|
], |
|
|
|
"note": [ |
|
|
|
(r"<\?\s*note\s*\?>", Comment, "#push"), |
|
|
|
(r"<\?\s*end\s+note\s*\?>", Comment, "#pop"), |
|
|
|
(r"[^<]+", Comment), |
|
(r".", Comment), |
|
], |
|
|
|
"doc": [ |
|
|
|
(r"<\?\s*doc\s*\?>", String.Doc, "#push"), |
|
|
|
(r"<\?\s*end\s+doc\s*\?>", String.Doc, "#pop"), |
|
|
|
(r"[^<]+", String.Doc), |
|
(r".", String.Doc), |
|
], |
|
|
|
"ul4": [ |
|
|
|
(r"\?>", Comment.Preproc, "#pop"), |
|
|
|
("'''", String, "string13"), |
|
('"""', String, "string23"), |
|
|
|
("'", String, "string1"), |
|
('"', String, "string2"), |
|
|
|
(r"\d+\.\d*([eE][+-]?\d+)?", Number.Float), |
|
(r"\.\d+([eE][+-]?\d+)?", Number.Float), |
|
(r"\d+[eE][+-]?\d+", Number.Float), |
|
|
|
(r"0[bB][01]+", Number.Bin), |
|
|
|
(r"0[oO][0-7]+", Number.Oct), |
|
|
|
(r"0[xX][0-9a-fA-F]+", Number.Hex), |
|
|
|
(r"@\(\d\d\d\d-\d\d-\d\d(T(\d\d:\d\d(:\d\d(\.\d{6})?)?)?)?\)", Literal.Date), |
|
|
|
(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), |
|
|
|
(r"\d+", Number.Integer), |
|
|
|
(r"//|==|!=|>=|<=|<<|>>|\+=|-=|\*=|/=|//=|<<=|>>=|&=|\|=|^=|=|[\[\]{},:*/().~%&|<>^+-]", Operator), |
|
|
|
(words(("for", "in", "if", "else", "not", "is", "and", "or"), suffix=r"\b"), Keyword), |
|
|
|
(words(("None", "False", "True"), suffix=r"\b"), Keyword.Constant), |
|
|
|
(r"[a-zA-Z_][a-zA-Z0-9_]*", Name), |
|
|
|
(r"\s+", Text.Whitespace), |
|
], |
|
|
|
"end": [ |
|
(r"\?>", Comment.Preproc, "#pop"), |
|
(words(("for", "if", "def", "while", "renderblock", "renderblocks"), suffix=r"\b"), Keyword), |
|
(r"\s+", Text), |
|
], |
|
|
|
|
|
"whitespace": [ |
|
(r"\?>", Comment.Preproc, "#pop"), |
|
(words(("keep", "strip", "smart"), suffix=r"\b"), Comment.Preproc), |
|
(r"\s+", Text.Whitespace), |
|
], |
|
|
|
"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), |
|
], |
|
|
|
"string13": [ |
|
(r"'''", String, "#pop"), |
|
include("stringescapes"), |
|
(r"[^\\']+", String), |
|
(r'.', String), |
|
], |
|
|
|
"string23": [ |
|
(r'"""', String, "#pop"), |
|
include("stringescapes"), |
|
(r'[^\\"]+', String), |
|
(r'.', String), |
|
], |
|
|
|
"string1": [ |
|
(r"'", String, "#pop"), |
|
include("stringescapes"), |
|
(r"[^\\']+", String), |
|
(r'.', String), |
|
], |
|
|
|
"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) |
|
|