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