@@ -9,7 +9,7 @@ class XBsl < RegexLexer
99 tag 'xbsl'
1010 filenames '*.xbsl' , '*.sbsl'
1111
12- KEYWORDS = /(?<=[^ \w а-яё]|^) (?:
12+ KEYWORDS = /\b (?:
1313 вконце | finally | возврат | return
1414 | выбор | case | выбросить | throw
1515 | для | for | если | if
@@ -29,87 +29,150 @@ class XBsl < RegexLexer
2929 | статический | static | структура | structure
3030 | умолчание | default | это | is
3131 | этот | this
32- )(?=[^\w а-яё]|$)/ix
32+ )\b /ix
33+
34+ QUERY_KEYWORDS = /\b (?:
35+ ВЫБРАТЬ | SELECT | ВСТАВИТЬ | INSERT | ИЗМЕНИТЬ | UPDATE | РАЗРЕШЕННЫЕ | ALLOWED
36+ | ПЕРВЫЕ | TOP | РАЗЛИЧНЫЕ | DISTINCT | ОБРЕЗАТЬ | TRUNCATE | УДАЛИТЬ | DELETE
37+ | УНИЧТОЖИТЬ | DROP | ПОМЕСТИТЬ | INTO | ИНДЕКСИРОВАТЬ | INDEX | УСТАНОВИТЬ | SET
38+ | СОЗДАТЬ\\ s+ВРЕМЕННУЮ\\ s+ТАБЛИЦУ | CREATE\\ s+TEMPORARY\\ s+TABLE
39+ | СОЗДАТЬ\\ s+ИНДЕКС | CREATE\\ s+INDEX
40+ | ИЗ | FROM | ГДЕ | WHERE | СОЕДИНЕНИЕ | JOIN | ЛЕВОЕ | LEFT
41+ | ПРАВОЕ | RIGHT | ПОЛНОЕ | FULL | ВНУТРЕННЕЕ | INNER | ОБЪЕДИНИТЬ | UNION
42+ | ВСЕ | ALL | УПОРЯДОЧИТЬ | ORDER | СГРУППИРОВАТЬ | GROUP | ИМЕЮЩИЕ | HAVING
43+ | ИЕРАРХИИ | HIERARCHY | ПО | ON | BY | ВОЗР | ASC | УБЫВ | DESC
44+ | ДЛЯ | FOR | КАК | AS | ЕСТЬ | IS | В | IN
45+ | ВЫРАЗИТЬ | CAST | ВЫБОР | CASE | КОГДА | WHEN | ТОГДА | THEN
46+ | ИНАЧЕ | ELSE | КОНЕЦ | END | НЕ | NOT | ИЛИ | OR
47+ | И | AND | ССЫЛКА | REFS | СПЕЦСИМВОЛ | ESCAPE |NULL
48+ | ПОДОБНО | LIKE | МЕЖДУ | BETWEEN
49+ )\b /ix
3350
3451 state :root do
35- # date
36- rule %r/(Дата|Date|Время|Time|ДатаВремя|DateTime|ЧасовойПояс)(\{ )(.*)(\} )/ do |m |
37- token Name ::Class , m [ 1 ]
38- token Punctuation , m [ 2 ]
39- token Literal ::Date , m [ 3 ]
40- token Punctuation , m [ 4 ]
52+ rule /(импорт|import)(\s +[\w а-яё\. ]+)/i do |m |
53+ token Keyword ::Namespace , m [ 1 ]
54+ token Name ::Namespace , m [ 2 ]
4155 end
4256
43- # binary
44- rule %r/(Байты|Bytes|Ууид|Uuid)(\{ )(.*)(\} )/ do |m |
57+ mixin :query
58+
59+ mixin :statements
60+
61+ mixin :value_types
62+
63+ mixin :comments
64+
65+ rule /@[\w а-яё]+\b /i , Name ::Tag
66+ rule KEYWORDS , Keyword
67+ mixin :literals
68+ rule %r/(\" )/ , Punctuation , :string_end
69+ mixin :other_text
70+ rule /[\( \) \[ \] ]/ , Punctuation
71+ end
72+
73+ state :literals do
74+ rule %r/(?<=[^\w а-яё\. ]|^)((\d +\. ?\d *)|(0x[0-9a-f]+)|(0b[0-1]+))(?=[^\w а-яё\. ]|$)/ , Literal ::Number
75+ rule %r/(Истина|True|Ложь|False|Неопределено|Undefined)/ , Keyword ::Constant
76+ rule %r/(\b [\w а-яё]+\b )(\s *\{ )(.*?)(\} )/i do |m |
4577 token Name ::Class , m [ 1 ]
4678 token Punctuation , m [ 2 ]
47- token Literal :: Number :: Bin , m [ 3 ]
79+ token Keyword :: Constant , m [ 3 ]
4880 token Punctuation , m [ 4 ]
49- end
81+ end
82+ end
5083
51- # string
52- rule %r/\" / , Literal ::String , :stringinter
84+ state :string_end do
85+ rule %r/(\\ .)/ , Literal ::String ::Symbol
86+ rule %r/([%\$ ])(?=\" )/ , Literal ::String
87+ rule %r/([^\" %\$ ]+?)/i , Literal ::String
88+ rule %r/([%\$ ][0-9\s ])/ , Literal ::String
89+ rule %r/([%\$ ](?:[\w а-яё]+|\{ [^\} ]+\} ))/i , Generic ::Inserted
90+ rule %r/(\" )/ , Punctuation , :pop!
91+ end
5392
54- # number
55- rule %r/\b (-*\d +[\. ]?\d *)\b / , Literal ::Number
56- rule %r/\b (-*0x[0-9a-f]+)\b / , Literal ::Number
57- rule %r/\b (-*0b[01]+)\b / , Literal ::Number
93+ state :other_text do
94+ rule /\s +/ , Text ::Whitespace
95+ rule /[\w а-яё]+/i , Name ::Variable
96+ rule %r/(->)/ , Name ::Function ::Magic
97+ rule %r/[:,;\| ]/ , Punctuation
98+ rule %r/[-+\/ *%=<>.?&!]/ , Operator
99+ rule %r/(?<=[^\w а-яё\. ]|^)(не|not|и|and|или|or)(?=[^\w а-яё\. ]|$)/ , Operator
100+ end
58101
59- # new
60- rule %r/(новый|new)(\s +)([\w а-яё\. ]+)/i do |m |
61- token Keyword ::Declaration , m [ 1 ]
62- token Text , m [ 2 ]
102+ state :comments do
103+ rule %r(//.*$) , Comment ::Single
104+ rule %r(\/ \* [.\s \n \w \W ]*?\* \/ ) , Comment ::Multiline
105+ end
106+
107+ state :query do
108+ rule %r/\b (Запрос|Query)(\s *\{ )/i do |m |
109+ token Name ::Class , m [ 1 ]
110+ token Punctuation , m [ 2 ]
111+ push :query_end
112+ end
113+
114+ rule %r/\b (новый|new)(\s *)\b (Запрос|Query)(\s *\( \s *\" )/i do |m |
115+ token Keyword , m [ 1 ]
116+ token Text ::Whitespace , m [ 2 ]
63117 token Name ::Class , m [ 3 ]
118+ token Punctuation , m [ 4 ]
119+ push :query_end_bracket
64120 end
121+ end
65122
66- # type, recurs
67- rule %r/([\< :])/ , Punctuation , :typestate
68- rule %r/\b (as|как)\b / , Keyword , :typestate
123+ state :query_end do
124+ mixin :query_body
125+ rule %r/(\s *\} )/ , Punctuation , :pop!
126+ end
69127
70- # method
71- rule %r/(метод|method)(\s +)([\w а-яё]+)/i do |m |
72- token Keyword , m [ 1 ]
73- token Text , m [ 2 ]
74- token Name ::Function , m [ 3 ]
128+ state :query_end_bracket do
129+ mixin :query_body
130+ rule %r/(\s *\" \s *\) )/ , Punctuation , :pop!
131+ end
132+
133+ state :query_body do
134+ mixin :comments
135+ mixin :literals
136+ rule %r/[%\$ ][\w а-яё]+\b /i , Generic ::Inserted
137+ rule %r/([%\$ ](?:[\w а-яё]+|\{ [^\} ]+\} ))/i , Generic ::Inserted
138+ mixin :query_func
139+ rule QUERY_KEYWORDS , Keyword
140+ mixin :other_text
141+ end
142+
143+ state :query_func do
144+ rule %r/\b ([\w а-я]+\s *)(\( )/i do |m |
145+ token Name ::Function , m [ 1 ]
146+ token Punctuation , m [ 2 ]
147+ push :query_func_end
75148 end
149+ end
76150
77- # class
78- rule %r/^(\s *(?:структура|structure)\s +)([\w а-яё]+)/i do |m |
151+ state :query_func_end do
152+ mixin :query_body
153+ rule %r/(\) )/ , Punctuation , :pop!
154+ end
155+
156+ state :statements do
157+ rule %r/^(\s *(?:структура|structure|перечисление|enum)\s +)([\w а-яё]+)/i do |m |
79158 token Keyword , m [ 1 ]
80159 token Name ::Entity , m [ 2 ]
81160 end
82-
83- # import
84- rule %r/(импорт|import)(\s +[\w а-яё\. ]+)/i do |m |
85- token Keyword ::Namespace , m [ 1 ]
86- token Name ::Namespace , m [ 2 ]
87- end
88-
89- # scope
161+
90162 rule %r/\b (область|scope)\b / , Comment ::Preproc
91163
92- # exception
93164 rule %r/(попытка|поймать|исключение|try|catch|exception|вконце|finally)\s / , Name ::Exception
94165
95- # const
166+ rule %r/(новый|new)(\s +[\w а-яё\. ]+)/i do |m |
167+ token Keyword ::Declaration , m [ 1 ]
168+ token Name ::Class , m [ 2 ]
169+ end
170+
96171 rule %r/(const|конст)(\s +[\w а-яё]+)/i do |m |
97172 token Keyword ::Constant , m [ 1 ]
98173 token Name ::Constant , m [ 2 ]
99174 end
100175
101- # comment
102- rule %r(//.*$) , Comment ::Single
103- rule %r(\/ \* [.\s \n \w \W ]*?\* \/ ) , Comment ::Multiline
104-
105- # query
106- rule %r/(Запрос|Query)(\s *)(\{ )/ do |m |
107- token Keyword ::Type , m [ 1 ]
108- token Literal ::String ::Other , m [ 2 ]
109- token Literal ::String ::Delimiter , m [ 3 ]
110- push :queryinter
111- end
112-
113176 rule %r/\b (знч|val)(\s +[\w а-яё]+)/ do |m |
114177 token Keyword ::Constant , m [ 1 ]
115178 token Name ::Variable , m [ 2 ]
@@ -119,49 +182,14 @@ class XBsl < RegexLexer
119182 token Keyword ::Variable , m [ 1 ]
120183 token Name ::Variable , m [ 2 ]
121184 end
122-
123- rule %r/\n / , Text
124- rule %r/[^\S \n ]+/ , Text
125-
126- rule %r/[\[ \] :(),;{}\| ]/ , Punctuation
127- rule %r/[-+\/ *%=<>.?&!]/ , Operator
128- rule KEYWORDS , Keyword
129- rule %r/[\w а-яё]+/i , Name ::Variable
130- rule %r/@[\w а-яё]+/i , Name ::Tag
131-
132185 end
133186
134- state :typestate do
135- rule %r/=/ , Operator , :pop!
136- rule %r/\s *[0-9.xb]+/ , Literal ::Number , :pop!
137-
138- rule %r/([\w а-яё \t |\? \. ]+)/i , Name ::Class
139-
140- rule %r/\< / , Punctuation , :typestate
141- rule %r/[\> ,\) \( \n ]/ , Punctuation , :pop!
142- :pop!
143- end
144-
145- state :stringinter do
146- rule %r/[%\$ ]*"/ , Literal ::String , :pop!
147- rule %r/(\\ .)/ , Literal ::String ::Symbol
148-
149- rule %r/([^\$ %"\\ ]+)/ , Literal ::String
150- rule %r/([%\$ ](?>[^a-zа-яё_\{ "]))/i , Literal ::String
151-
152- rule %r/(\\ .)/ , Literal ::String ::Symbol
153- rule %r/([%\$ ](?:[\w а-яё]+|\{ [^\} ]+\} ))/i , Literal ::String ::Interpol
154- end
155-
156- state :queryinter do
157- rule %r/[%\$ ]*\} / , Literal ::String ::Delimiter , :pop!
158- rule %r/(\\ .)/ , Literal ::String ::Symbol
159-
160- rule %r/([^\$ %\{ \\ ]+)/ , Generic ::Emph
161- rule %r/([%\$ ](?>[^a-zа-яё_\{ "]))/i , Generic ::Emph
162-
163- rule %r/(\\ .)/ , Literal ::String ::Symbol
164- rule %r/([%\$ ](?:[\w а-яё]+|\{ [^\} ]+\} ))/i , Literal ::String ::Interpol
187+ state :value_types do
188+ rule %r/(:\s *)([\w а-яё\? \. \ \t |<>]+)([,\) =]|$)/i do |m |
189+ token Punctuation , m [ 1 ]
190+ token Keyword ::Type , m [ 2 ]
191+ token Punctuation , m [ 3 ]
192+ end
165193 end
166194 end
167195 end
0 commit comments