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