File size: 6,188 Bytes
9c6594c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
"""
pygments.lexers.blueprint
~~~~~~~~~~~~~~~~~~~~~~~~~
Lexer for the Blueprint UI markup language.
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
from pygments.lexer import RegexLexer, include, bygroups, words
from pygments.token import (
Comment,
Operator,
Keyword,
Name,
String,
Number,
Punctuation,
Whitespace,
)
__all__ = ["BlueprintLexer"]
class BlueprintLexer(RegexLexer):
"""
For Blueprint UI markup.
"""
name = "Blueprint"
aliases = ["blueprint"]
filenames = ["*.blp"]
mimetypes = ["text/x-blueprint"]
url = "https://gitlab.gnome.org/jwestman/blueprint-compiler"
version_added = '2.16'
flags = re.IGNORECASE
tokens = {
"root": [
include("block-content"),
],
"type": [
(r"\$\s*[a-z_][a-z0-9_\-]*", Name.Class),
(r"(?:([a-z_][a-z0-9_\-]*)(\s*)(\.)(\s*))?([a-z_][a-z0-9_\-]*)",
bygroups(Name.Namespace, Whitespace, Punctuation, Whitespace, Name.Class)),
],
"whitespace": [
(r"\s+", Whitespace),
(r"//.*?\n", Comment.Single),
(r"/\*", Comment.Multiline, "comment-multiline"),
],
"comment-multiline": [
(r"\*/", Comment.Multiline, "#pop"),
(r"[^*]+", Comment.Multiline),
(r"\*", Comment.Multiline),
],
"value": [
(r"(typeof)(\s*)(<)", bygroups(Keyword, Whitespace, Punctuation), "typeof"),
(words(("true", "false", "null")), Keyword.Constant),
(r"[a-z_][a-z0-9_\-]*", Name.Variable),
(r"\|", Operator),
(r'".*?"', String.Double),
(r"\'.*?\'", String.Single),
(r"0x[\d_]*", Number.Hex),
(r"[0-9_]+", Number.Integer),
(r"\d[\d\.a-z_]*", Number),
],
"typeof": [
include("whitespace"),
include("type"),
(r">", Punctuation, "#pop"),
],
"content": [
include("whitespace"),
# Keywords
(words(("after", "bidirectional", "bind-property", "bind", "default",
"destructive", "disabled", "inverted", "no-sync-create",
"suggested", "swapped", "sync-create", "template")),
Keyword),
# Translated strings
(r"(C?_)(\s*)(\()",
bygroups(Name.Function.Builtin, Whitespace, Punctuation),
"paren-content"),
# Cast expressions
(r"(as)(\s*)(<)", bygroups(Keyword, Whitespace, Punctuation), "typeof"),
# Closures
(r"(\$?[a-z_][a-z0-9_\-]*)(\s*)(\()",
bygroups(Name.Function, Whitespace, Punctuation),
"paren-content"),
# Objects
(r"(?:(\$\s*[a-z_][a-z0-9_\-]+)|(?:([a-z_][a-z0-9_\-]*)(\s*)(\.)(\s*))?([a-z_][a-z0-9_\-]*))(?:(\s+)([a-z_][a-z0-9_\-]*))?(\s*)(\{)",
bygroups(Name.Class, Name.Namespace, Whitespace, Punctuation, Whitespace,
Name.Class, Whitespace, Name.Variable, Whitespace, Punctuation),
"brace-block"),
# Misc
include("value"),
(r",|\.", Punctuation),
],
"block-content": [
# Import statements
(r"(using)(\s+)([a-z_][a-z0-9_\-]*)(\s+)(\d[\d\.]*)(;)",
bygroups(Keyword, Whitespace, Name.Namespace, Whitespace,
Name.Namespace, Punctuation)),
# Menus
(r"(menu|section|submenu)(?:(\s+)([a-z_][a-z0-9_\-]*))?(\s*)(\{)",
bygroups(Keyword, Whitespace, Name.Variable, Whitespace, Punctuation),
"brace-block"),
(r"(item)(\s*)(\{)",
bygroups(Keyword, Whitespace, Punctuation),
"brace-block"),
(r"(item)(\s*)(\()",
bygroups(Keyword, Whitespace, Punctuation),
"paren-block"),
# Templates
(r"template", Keyword.Declaration, "template"),
# Nested blocks. When extensions are added, this is where they go.
(r"(responses|items|mime-types|patterns|suffixes|marks|widgets|strings|styles)(\s*)(\[)",
bygroups(Keyword, Whitespace, Punctuation),
"bracket-block"),
(r"(accessibility|setters|layout|item)(\s*)(\{)",
bygroups(Keyword, Whitespace, Punctuation),
"brace-block"),
(r"(condition|mark|item)(\s*)(\()",
bygroups(Keyword, Whitespace, Punctuation),
"paren-content"),
(r"\[", Punctuation, "child-type"),
# Properties and signals
(r"([a-z_][a-z0-9_\-]*(?:::[a-z0-9_]+)?)(\s*)(:|=>)",
bygroups(Name.Property, Whitespace, Punctuation),
"statement"),
include("content"),
],
"paren-block": [
include("block-content"),
(r"\)", Punctuation, "#pop"),
],
"paren-content": [
include("content"),
(r"\)", Punctuation, "#pop"),
],
"bracket-block": [
include("block-content"),
(r"\]", Punctuation, "#pop"),
],
"brace-block": [
include("block-content"),
(r"\}", Punctuation, "#pop"),
],
"statement": [
include("content"),
(r";", Punctuation, "#pop"),
],
"child-type": [
include("whitespace"),
(r"(action)(\s+)(response)(\s*)(=)(\s*)",
bygroups(Keyword, Whitespace, Name.Attribute, Whitespace,
Punctuation, Whitespace)),
(words(("default", "internal-child", "response")), Keyword),
(r"[a-z_][a-z0-9_\-]*", Name.Decorator),
include("value"),
(r"=", Punctuation),
(r"\]", Punctuation, "#pop"),
],
"template": [
include("whitespace"),
include("type"),
(r":", Punctuation),
(r"\{", Punctuation, ("#pop", "brace-block")),
],
}
|