Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/basic.py: 93%
84 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1"""
2 pygments.lexers.basic
3 ~~~~~~~~~~~~~~~~~~~~~
5 Lexers for BASIC like languages (other than VB.net).
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, bygroups, default, words, include
14from pygments.token import Comment, Error, Keyword, Name, Number, \
15 Punctuation, Operator, String, Text, Whitespace
16from pygments.lexers import _vbscript_builtins
19__all__ = ['BlitzBasicLexer', 'BlitzMaxLexer', 'MonkeyLexer', 'CbmBasicV2Lexer',
20 'QBasicLexer', 'VBScriptLexer', 'BBCBasicLexer']
23class BlitzMaxLexer(RegexLexer):
24 """
25 For BlitzMax source code.
27 .. versionadded:: 1.4
28 """
30 name = 'BlitzMax'
31 url = 'http://blitzbasic.com'
32 aliases = ['blitzmax', 'bmax']
33 filenames = ['*.bmx']
34 mimetypes = ['text/x-bmx']
36 bmax_vopwords = r'\b(Shl|Shr|Sar|Mod)\b'
37 bmax_sktypes = r'@{1,2}|[!#$%]'
38 bmax_lktypes = r'\b(Int|Byte|Short|Float|Double|Long)\b'
39 bmax_name = r'[a-z_]\w*'
40 bmax_var = (r'(%s)(?:(?:([ \t]*)(%s)|([ \t]*:[ \t]*\b(?:Shl|Shr|Sar|Mod)\b)'
41 r'|([ \t]*)(:)([ \t]*)(?:%s|(%s)))(?:([ \t]*)(Ptr))?)') % \
42 (bmax_name, bmax_sktypes, bmax_lktypes, bmax_name)
43 bmax_func = bmax_var + r'?((?:[ \t]|\.\.\n)*)([(])'
45 flags = re.MULTILINE | re.IGNORECASE
46 tokens = {
47 'root': [
48 # Text
49 (r'\s+', Whitespace),
50 (r'(\.\.)(\n)', bygroups(Text, Whitespace)), # Line continuation
51 # Comments
52 (r"'.*?\n", Comment.Single),
53 (r'([ \t]*)\bRem\n(\n|.)*?\s*\bEnd([ \t]*)Rem', Comment.Multiline),
54 # Data types
55 ('"', String.Double, 'string'),
56 # Numbers
57 (r'[0-9]+\.[0-9]*(?!\.)', Number.Float),
58 (r'\.[0-9]*(?!\.)', Number.Float),
59 (r'[0-9]+', Number.Integer),
60 (r'\$[0-9a-f]+', Number.Hex),
61 (r'\%[10]+', Number.Bin),
62 # Other
63 (r'(?:(?:(:)?([ \t]*)(:?%s|([+\-*/&|~]))|Or|And|Not|[=<>^]))' %
64 (bmax_vopwords), Operator),
65 (r'[(),.:\[\]]', Punctuation),
66 (r'(?:#[\w \t]*)', Name.Label),
67 (r'(?:\?[\w \t]*)', Comment.Preproc),
68 # Identifiers
69 (r'\b(New)\b([ \t]?)([(]?)(%s)' % (bmax_name),
70 bygroups(Keyword.Reserved, Whitespace, Punctuation, Name.Class)),
71 (r'\b(Import|Framework|Module)([ \t]+)(%s\.%s)' %
72 (bmax_name, bmax_name),
73 bygroups(Keyword.Reserved, Whitespace, Keyword.Namespace)),
74 (bmax_func, bygroups(Name.Function, Whitespace, Keyword.Type,
75 Operator, Whitespace, Punctuation, Whitespace,
76 Keyword.Type, Name.Class, Whitespace,
77 Keyword.Type, Whitespace, Punctuation)),
78 (bmax_var, bygroups(Name.Variable, Whitespace, Keyword.Type, Operator,
79 Whitespace, Punctuation, Whitespace, Keyword.Type,
80 Name.Class, Whitespace, Keyword.Type)),
81 (r'\b(Type|Extends)([ \t]+)(%s)' % (bmax_name),
82 bygroups(Keyword.Reserved, Whitespace, Name.Class)),
83 # Keywords
84 (r'\b(Ptr)\b', Keyword.Type),
85 (r'\b(Pi|True|False|Null|Self|Super)\b', Keyword.Constant),
86 (r'\b(Local|Global|Const|Field)\b', Keyword.Declaration),
87 (words((
88 'TNullMethodException', 'TNullFunctionException',
89 'TNullObjectException', 'TArrayBoundsException',
90 'TRuntimeException'), prefix=r'\b', suffix=r'\b'), Name.Exception),
91 (words((
92 'Strict', 'SuperStrict', 'Module', 'ModuleInfo',
93 'End', 'Return', 'Continue', 'Exit', 'Public', 'Private',
94 'Var', 'VarPtr', 'Chr', 'Len', 'Asc', 'SizeOf', 'Sgn', 'Abs', 'Min', 'Max',
95 'New', 'Release', 'Delete', 'Incbin', 'IncbinPtr', 'IncbinLen',
96 'Framework', 'Include', 'Import', 'Extern', 'EndExtern',
97 'Function', 'EndFunction', 'Type', 'EndType', 'Extends', 'Method', 'EndMethod',
98 'Abstract', 'Final', 'If', 'Then', 'Else', 'ElseIf', 'EndIf',
99 'For', 'To', 'Next', 'Step', 'EachIn', 'While', 'Wend', 'EndWhile',
100 'Repeat', 'Until', 'Forever', 'Select', 'Case', 'Default', 'EndSelect',
101 'Try', 'Catch', 'EndTry', 'Throw', 'Assert', 'Goto', 'DefData', 'ReadData',
102 'RestoreData'), prefix=r'\b', suffix=r'\b'),
103 Keyword.Reserved),
104 # Final resolve (for variable names and such)
105 (r'(%s)' % (bmax_name), Name.Variable),
106 ],
107 'string': [
108 (r'""', String.Double),
109 (r'"C?', String.Double, '#pop'),
110 (r'[^"]+', String.Double),
111 ],
112 }
115class BlitzBasicLexer(RegexLexer):
116 """
117 For BlitzBasic source code.
119 .. versionadded:: 2.0
120 """
122 name = 'BlitzBasic'
123 url = 'http://blitzbasic.com'
124 aliases = ['blitzbasic', 'b3d', 'bplus']
125 filenames = ['*.bb', '*.decls']
126 mimetypes = ['text/x-bb']
128 bb_sktypes = r'@{1,2}|[#$%]'
129 bb_name = r'[a-z]\w*'
130 bb_var = (r'(%s)(?:([ \t]*)(%s)|([ \t]*)([.])([ \t]*)(?:(%s)))?') % \
131 (bb_name, bb_sktypes, bb_name)
133 flags = re.MULTILINE | re.IGNORECASE
134 tokens = {
135 'root': [
136 # Text
137 (r'\s+', Whitespace),
138 # Comments
139 (r";.*?\n", Comment.Single),
140 # Data types
141 ('"', String.Double, 'string'),
142 # Numbers
143 (r'[0-9]+\.[0-9]*(?!\.)', Number.Float),
144 (r'\.[0-9]+(?!\.)', Number.Float),
145 (r'[0-9]+', Number.Integer),
146 (r'\$[0-9a-f]+', Number.Hex),
147 (r'\%[10]+', Number.Bin),
148 # Other
149 (words(('Shl', 'Shr', 'Sar', 'Mod', 'Or', 'And', 'Not',
150 'Abs', 'Sgn', 'Handle', 'Int', 'Float', 'Str',
151 'First', 'Last', 'Before', 'After'),
152 prefix=r'\b', suffix=r'\b'),
153 Operator),
154 (r'([+\-*/~=<>^])', Operator),
155 (r'[(),:\[\]\\]', Punctuation),
156 (r'\.([ \t]*)(%s)' % bb_name, Name.Label),
157 # Identifiers
158 (r'\b(New)\b([ \t]+)(%s)' % (bb_name),
159 bygroups(Keyword.Reserved, Whitespace, Name.Class)),
160 (r'\b(Gosub|Goto)\b([ \t]+)(%s)' % (bb_name),
161 bygroups(Keyword.Reserved, Whitespace, Name.Label)),
162 (r'\b(Object)\b([ \t]*)([.])([ \t]*)(%s)\b' % (bb_name),
163 bygroups(Operator, Whitespace, Punctuation, Whitespace, Name.Class)),
164 (r'\b%s\b([ \t]*)(\()' % bb_var,
165 bygroups(Name.Function, Whitespace, Keyword.Type, Whitespace, Punctuation,
166 Whitespace, Name.Class, Whitespace, Punctuation)),
167 (r'\b(Function)\b([ \t]+)%s' % bb_var,
168 bygroups(Keyword.Reserved, Whitespace, Name.Function, Whitespace, Keyword.Type,
169 Whitespace, Punctuation, Whitespace, Name.Class)),
170 (r'\b(Type)([ \t]+)(%s)' % (bb_name),
171 bygroups(Keyword.Reserved, Whitespace, Name.Class)),
172 # Keywords
173 (r'\b(Pi|True|False|Null)\b', Keyword.Constant),
174 (r'\b(Local|Global|Const|Field|Dim)\b', Keyword.Declaration),
175 (words((
176 'End', 'Return', 'Exit', 'Chr', 'Len', 'Asc', 'New', 'Delete', 'Insert',
177 'Include', 'Function', 'Type', 'If', 'Then', 'Else', 'ElseIf', 'EndIf',
178 'For', 'To', 'Next', 'Step', 'Each', 'While', 'Wend',
179 'Repeat', 'Until', 'Forever', 'Select', 'Case', 'Default',
180 'Goto', 'Gosub', 'Data', 'Read', 'Restore'), prefix=r'\b', suffix=r'\b'),
181 Keyword.Reserved),
182 # Final resolve (for variable names and such)
183 # (r'(%s)' % (bb_name), Name.Variable),
184 (bb_var, bygroups(Name.Variable, Whitespace, Keyword.Type,
185 Whitespace, Punctuation, Whitespace, Name.Class)),
186 ],
187 'string': [
188 (r'""', String.Double),
189 (r'"C?', String.Double, '#pop'),
190 (r'[^"\n]+', String.Double),
191 ],
192 }
195class MonkeyLexer(RegexLexer):
196 """
197 For
198 `Monkey <https://en.wikipedia.org/wiki/Monkey_(programming_language)>`_
199 source code.
201 .. versionadded:: 1.6
202 """
204 name = 'Monkey'
205 aliases = ['monkey']
206 filenames = ['*.monkey']
207 mimetypes = ['text/x-monkey']
209 name_variable = r'[a-z_]\w*'
210 name_function = r'[A-Z]\w*'
211 name_constant = r'[A-Z_][A-Z0-9_]*'
212 name_class = r'[A-Z]\w*'
213 name_module = r'[a-z0-9_]*'
215 keyword_type = r'(?:Int|Float|String|Bool|Object|Array|Void)'
216 # ? == Bool // % == Int // # == Float // $ == String
217 keyword_type_special = r'[?%#$]'
219 flags = re.MULTILINE
221 tokens = {
222 'root': [
223 # Text
224 (r'\s+', Whitespace),
225 # Comments
226 (r"'.*", Comment),
227 (r'(?i)^#rem\b', Comment.Multiline, 'comment'),
228 # preprocessor directives
229 (r'(?i)^(?:#If|#ElseIf|#Else|#EndIf|#End|#Print|#Error)\b', Comment.Preproc),
230 # preprocessor variable (any line starting with '#' that is not a directive)
231 (r'^#', Comment.Preproc, 'variables'),
232 # String
233 ('"', String.Double, 'string'),
234 # Numbers
235 (r'[0-9]+\.[0-9]*(?!\.)', Number.Float),
236 (r'\.[0-9]+(?!\.)', Number.Float),
237 (r'[0-9]+', Number.Integer),
238 (r'\$[0-9a-fA-Z]+', Number.Hex),
239 (r'\%[10]+', Number.Bin),
240 # Native data types
241 (r'\b%s\b' % keyword_type, Keyword.Type),
242 # Exception handling
243 (r'(?i)\b(?:Try|Catch|Throw)\b', Keyword.Reserved),
244 (r'Throwable', Name.Exception),
245 # Builtins
246 (r'(?i)\b(?:Null|True|False)\b', Name.Builtin),
247 (r'(?i)\b(?:Self|Super)\b', Name.Builtin.Pseudo),
248 (r'\b(?:HOST|LANG|TARGET|CONFIG)\b', Name.Constant),
249 # Keywords
250 (r'(?i)^(Import)(\s+)(.*)(\n)',
251 bygroups(Keyword.Namespace, Whitespace, Name.Namespace, Whitespace)),
252 (r'(?i)^Strict\b.*\n', Keyword.Reserved),
253 (r'(?i)(Const|Local|Global|Field)(\s+)',
254 bygroups(Keyword.Declaration, Whitespace), 'variables'),
255 (r'(?i)(New|Class|Interface|Extends|Implements)(\s+)',
256 bygroups(Keyword.Reserved, Whitespace), 'classname'),
257 (r'(?i)(Function|Method)(\s+)',
258 bygroups(Keyword.Reserved, Whitespace), 'funcname'),
259 (r'(?i)(?:End|Return|Public|Private|Extern|Property|'
260 r'Final|Abstract)\b', Keyword.Reserved),
261 # Flow Control stuff
262 (r'(?i)(?:If|Then|Else|ElseIf|EndIf|'
263 r'Select|Case|Default|'
264 r'While|Wend|'
265 r'Repeat|Until|Forever|'
266 r'For|To|Until|Step|EachIn|Next|'
267 r'Exit|Continue)(?=\s)', Keyword.Reserved),
268 # not used yet
269 (r'(?i)\b(?:Module|Inline)\b', Keyword.Reserved),
270 # Array
271 (r'[\[\]]', Punctuation),
272 # Other
273 (r'<=|>=|<>|\*=|/=|\+=|-=|&=|~=|\|=|[-&*/^+=<>|~]', Operator),
274 (r'(?i)(?:Not|Mod|Shl|Shr|And|Or)', Operator.Word),
275 (r'[(){}!#,.:]', Punctuation),
276 # catch the rest
277 (r'%s\b' % name_constant, Name.Constant),
278 (r'%s\b' % name_function, Name.Function),
279 (r'%s\b' % name_variable, Name.Variable),
280 ],
281 'funcname': [
282 (r'(?i)%s\b' % name_function, Name.Function),
283 (r':', Punctuation, 'classname'),
284 (r'\s+', Whitespace),
285 (r'\(', Punctuation, 'variables'),
286 (r'\)', Punctuation, '#pop')
287 ],
288 'classname': [
289 (r'%s\.' % name_module, Name.Namespace),
290 (r'%s\b' % keyword_type, Keyword.Type),
291 (r'%s\b' % name_class, Name.Class),
292 # array (of given size)
293 (r'(\[)(\s*)(\d*)(\s*)(\])',
294 bygroups(Punctuation, Whitespace, Number.Integer, Whitespace, Punctuation)),
295 # generics
296 (r'\s+(?!<)', Whitespace, '#pop'),
297 (r'<', Punctuation, '#push'),
298 (r'>', Punctuation, '#pop'),
299 (r'\n', Whitespace, '#pop'),
300 default('#pop')
301 ],
302 'variables': [
303 (r'%s\b' % name_constant, Name.Constant),
304 (r'%s\b' % name_variable, Name.Variable),
305 (r'%s' % keyword_type_special, Keyword.Type),
306 (r'\s+', Whitespace),
307 (r':', Punctuation, 'classname'),
308 (r',', Punctuation, '#push'),
309 default('#pop')
310 ],
311 'string': [
312 (r'[^"~]+', String.Double),
313 (r'~q|~n|~r|~t|~z|~~', String.Escape),
314 (r'"', String.Double, '#pop'),
315 ],
316 'comment': [
317 (r'(?i)^#rem.*?', Comment.Multiline, "#push"),
318 (r'(?i)^#end.*?', Comment.Multiline, "#pop"),
319 (r'\n', Comment.Multiline),
320 (r'.+', Comment.Multiline),
321 ],
322 }
325class CbmBasicV2Lexer(RegexLexer):
326 """
327 For CBM BASIC V2 sources.
329 .. versionadded:: 1.6
330 """
331 name = 'CBM BASIC V2'
332 aliases = ['cbmbas']
333 filenames = ['*.bas']
335 flags = re.IGNORECASE
337 tokens = {
338 'root': [
339 (r'rem.*\n', Comment.Single),
340 (r'\s+', Whitespace),
341 (r'new|run|end|for|to|next|step|go(to|sub)?|on|return|stop|cont'
342 r'|if|then|input#?|read|wait|load|save|verify|poke|sys|print#?'
343 r'|list|clr|cmd|open|close|get#?', Keyword.Reserved),
344 (r'data|restore|dim|let|def|fn', Keyword.Declaration),
345 (r'tab|spc|sgn|int|abs|usr|fre|pos|sqr|rnd|log|exp|cos|sin|tan|atn'
346 r'|peek|len|val|asc|(str|chr|left|right|mid)\$', Name.Builtin),
347 (r'[-+*/^<>=]', Operator),
348 (r'not|and|or', Operator.Word),
349 (r'"[^"\n]*.', String),
350 (r'\d+|[-+]?\d*\.\d*(e[-+]?\d+)?', Number.Float),
351 (r'[(),:;]', Punctuation),
352 (r'\w+[$%]?', Name),
353 ]
354 }
356 def analyse_text(text):
357 # if it starts with a line number, it shouldn't be a "modern" Basic
358 # like VB.net
359 if re.match(r'^\d+', text):
360 return 0.2
363class QBasicLexer(RegexLexer):
364 """
365 For
366 `QBasic <http://en.wikipedia.org/wiki/QBasic>`_
367 source code.
369 .. versionadded:: 2.0
370 """
372 name = 'QBasic'
373 aliases = ['qbasic', 'basic']
374 filenames = ['*.BAS', '*.bas']
375 mimetypes = ['text/basic']
377 declarations = ('DATA', 'LET')
379 functions = (
380 'ABS', 'ASC', 'ATN', 'CDBL', 'CHR$', 'CINT', 'CLNG',
381 'COMMAND$', 'COS', 'CSNG', 'CSRLIN', 'CVD', 'CVDMBF', 'CVI',
382 'CVL', 'CVS', 'CVSMBF', 'DATE$', 'ENVIRON$', 'EOF', 'ERDEV',
383 'ERDEV$', 'ERL', 'ERR', 'EXP', 'FILEATTR', 'FIX', 'FRE',
384 'FREEFILE', 'HEX$', 'INKEY$', 'INP', 'INPUT$', 'INSTR', 'INT',
385 'IOCTL$', 'LBOUND', 'LCASE$', 'LEFT$', 'LEN', 'LOC', 'LOF',
386 'LOG', 'LPOS', 'LTRIM$', 'MID$', 'MKD$', 'MKDMBF$', 'MKI$',
387 'MKL$', 'MKS$', 'MKSMBF$', 'OCT$', 'PEEK', 'PEN', 'PLAY',
388 'PMAP', 'POINT', 'POS', 'RIGHT$', 'RND', 'RTRIM$', 'SADD',
389 'SCREEN', 'SEEK', 'SETMEM', 'SGN', 'SIN', 'SPACE$', 'SPC',
390 'SQR', 'STICK', 'STR$', 'STRIG', 'STRING$', 'TAB', 'TAN',
391 'TIME$', 'TIMER', 'UBOUND', 'UCASE$', 'VAL', 'VARPTR',
392 'VARPTR$', 'VARSEG'
393 )
395 metacommands = ('$DYNAMIC', '$INCLUDE', '$STATIC')
397 operators = ('AND', 'EQV', 'IMP', 'NOT', 'OR', 'XOR')
399 statements = (
400 'BEEP', 'BLOAD', 'BSAVE', 'CALL', 'CALL ABSOLUTE',
401 'CALL INTERRUPT', 'CALLS', 'CHAIN', 'CHDIR', 'CIRCLE', 'CLEAR',
402 'CLOSE', 'CLS', 'COLOR', 'COM', 'COMMON', 'CONST', 'DATA',
403 'DATE$', 'DECLARE', 'DEF FN', 'DEF SEG', 'DEFDBL', 'DEFINT',
404 'DEFLNG', 'DEFSNG', 'DEFSTR', 'DEF', 'DIM', 'DO', 'LOOP',
405 'DRAW', 'END', 'ENVIRON', 'ERASE', 'ERROR', 'EXIT', 'FIELD',
406 'FILES', 'FOR', 'NEXT', 'FUNCTION', 'GET', 'GOSUB', 'GOTO',
407 'IF', 'THEN', 'INPUT', 'INPUT #', 'IOCTL', 'KEY', 'KEY',
408 'KILL', 'LET', 'LINE', 'LINE INPUT', 'LINE INPUT #', 'LOCATE',
409 'LOCK', 'UNLOCK', 'LPRINT', 'LSET', 'MID$', 'MKDIR', 'NAME',
410 'ON COM', 'ON ERROR', 'ON KEY', 'ON PEN', 'ON PLAY',
411 'ON STRIG', 'ON TIMER', 'ON UEVENT', 'ON', 'OPEN', 'OPEN COM',
412 'OPTION BASE', 'OUT', 'PAINT', 'PALETTE', 'PCOPY', 'PEN',
413 'PLAY', 'POKE', 'PRESET', 'PRINT', 'PRINT #', 'PRINT USING',
414 'PSET', 'PUT', 'PUT', 'RANDOMIZE', 'READ', 'REDIM', 'REM',
415 'RESET', 'RESTORE', 'RESUME', 'RETURN', 'RMDIR', 'RSET', 'RUN',
416 'SCREEN', 'SEEK', 'SELECT CASE', 'SHARED', 'SHELL', 'SLEEP',
417 'SOUND', 'STATIC', 'STOP', 'STRIG', 'SUB', 'SWAP', 'SYSTEM',
418 'TIME$', 'TIMER', 'TROFF', 'TRON', 'TYPE', 'UEVENT', 'UNLOCK',
419 'VIEW', 'WAIT', 'WHILE', 'WEND', 'WIDTH', 'WINDOW', 'WRITE'
420 )
422 keywords = (
423 'ACCESS', 'ALIAS', 'ANY', 'APPEND', 'AS', 'BASE', 'BINARY',
424 'BYVAL', 'CASE', 'CDECL', 'DOUBLE', 'ELSE', 'ELSEIF', 'ENDIF',
425 'INTEGER', 'IS', 'LIST', 'LOCAL', 'LONG', 'LOOP', 'MOD',
426 'NEXT', 'OFF', 'ON', 'OUTPUT', 'RANDOM', 'SIGNAL', 'SINGLE',
427 'STEP', 'STRING', 'THEN', 'TO', 'UNTIL', 'USING', 'WEND'
428 )
430 tokens = {
431 'root': [
432 (r'\n+', Text),
433 (r'\s+', Text.Whitespace),
434 (r'^(\s*)(\d*)(\s*)(REM .*)$',
435 bygroups(Text.Whitespace, Name.Label, Text.Whitespace,
436 Comment.Single)),
437 (r'^(\s*)(\d+)(\s*)',
438 bygroups(Text.Whitespace, Name.Label, Text.Whitespace)),
439 (r'(?=[\s]*)(\w+)(?=[\s]*=)', Name.Variable.Global),
440 (r'(?=[^"]*)\'.*$', Comment.Single),
441 (r'"[^\n"]*"', String.Double),
442 (r'(END)(\s+)(FUNCTION|IF|SELECT|SUB)',
443 bygroups(Keyword.Reserved, Text.Whitespace, Keyword.Reserved)),
444 (r'(DECLARE)(\s+)([A-Z]+)(\s+)(\S+)',
445 bygroups(Keyword.Declaration, Text.Whitespace, Name.Variable,
446 Text.Whitespace, Name)),
447 (r'(DIM)(\s+)(SHARED)(\s+)([^\s(]+)',
448 bygroups(Keyword.Declaration, Text.Whitespace, Name.Variable,
449 Text.Whitespace, Name.Variable.Global)),
450 (r'(DIM)(\s+)([^\s(]+)',
451 bygroups(Keyword.Declaration, Text.Whitespace, Name.Variable.Global)),
452 (r'^(\s*)([a-zA-Z_]+)(\s*)(\=)',
453 bygroups(Text.Whitespace, Name.Variable.Global, Text.Whitespace,
454 Operator)),
455 (r'(GOTO|GOSUB)(\s+)(\w+\:?)',
456 bygroups(Keyword.Reserved, Text.Whitespace, Name.Label)),
457 (r'(SUB)(\s+)(\w+\:?)',
458 bygroups(Keyword.Reserved, Text.Whitespace, Name.Label)),
459 include('declarations'),
460 include('functions'),
461 include('metacommands'),
462 include('operators'),
463 include('statements'),
464 include('keywords'),
465 (r'[a-zA-Z_]\w*[$@#&!]', Name.Variable.Global),
466 (r'[a-zA-Z_]\w*\:', Name.Label),
467 (r'\-?\d*\.\d+[@|#]?', Number.Float),
468 (r'\-?\d+[@|#]', Number.Float),
469 (r'\-?\d+#?', Number.Integer.Long),
470 (r'\-?\d+#?', Number.Integer),
471 (r'!=|==|:=|\.=|<<|>>|[-~+/\\*%=<>&^|?:!.]', Operator),
472 (r'[\[\]{}(),;]', Punctuation),
473 (r'[\w]+', Name.Variable.Global),
474 ],
475 # can't use regular \b because of X$()
476 # XXX: use words() here
477 'declarations': [
478 (r'\b(%s)(?=\(|\b)' % '|'.join(map(re.escape, declarations)),
479 Keyword.Declaration),
480 ],
481 'functions': [
482 (r'\b(%s)(?=\(|\b)' % '|'.join(map(re.escape, functions)),
483 Keyword.Reserved),
484 ],
485 'metacommands': [
486 (r'\b(%s)(?=\(|\b)' % '|'.join(map(re.escape, metacommands)),
487 Keyword.Constant),
488 ],
489 'operators': [
490 (r'\b(%s)(?=\(|\b)' % '|'.join(map(re.escape, operators)), Operator.Word),
491 ],
492 'statements': [
493 (r'\b(%s)\b' % '|'.join(map(re.escape, statements)),
494 Keyword.Reserved),
495 ],
496 'keywords': [
497 (r'\b(%s)\b' % '|'.join(keywords), Keyword),
498 ],
499 }
501 def analyse_text(text):
502 if '$DYNAMIC' in text or '$STATIC' in text:
503 return 0.9
506class VBScriptLexer(RegexLexer):
507 """
508 VBScript is scripting language that is modeled on Visual Basic.
510 .. versionadded:: 2.4
511 """
512 name = 'VBScript'
513 aliases = ['vbscript']
514 filenames = ['*.vbs', '*.VBS']
515 flags = re.IGNORECASE
517 tokens = {
518 'root': [
519 (r"'[^\n]*", Comment.Single),
520 (r'\s+', Whitespace),
521 ('"', String.Double, 'string'),
522 ('&h[0-9a-f]+', Number.Hex),
523 # Float variant 1, for example: 1., 1.e2, 1.2e3
524 (r'[0-9]+\.[0-9]*(e[+-]?[0-9]+)?', Number.Float),
525 (r'\.[0-9]+(e[+-]?[0-9]+)?', Number.Float), # Float variant 2, for example: .1, .1e2
526 (r'[0-9]+e[+-]?[0-9]+', Number.Float), # Float variant 3, for example: 123e45
527 (r'[0-9]+', Number.Integer),
528 ('#.+#', String), # date or time value
529 (r'(dim)(\s+)([a-z_][a-z0-9_]*)',
530 bygroups(Keyword.Declaration, Whitespace, Name.Variable), 'dim_more'),
531 (r'(function|sub)(\s+)([a-z_][a-z0-9_]*)',
532 bygroups(Keyword.Declaration, Whitespace, Name.Function)),
533 (r'(class)(\s+)([a-z_][a-z0-9_]*)',
534 bygroups(Keyword.Declaration, Whitespace, Name.Class)),
535 (r'(const)(\s+)([a-z_][a-z0-9_]*)',
536 bygroups(Keyword.Declaration, Whitespace, Name.Constant)),
537 (r'(end)(\s+)(class|function|if|property|sub|with)',
538 bygroups(Keyword, Whitespace, Keyword)),
539 (r'(on)(\s+)(error)(\s+)(goto)(\s+)(0)',
540 bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword, Whitespace, Number.Integer)),
541 (r'(on)(\s+)(error)(\s+)(resume)(\s+)(next)',
542 bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword, Whitespace, Keyword)),
543 (r'(option)(\s+)(explicit)', bygroups(Keyword, Whitespace, Keyword)),
544 (r'(property)(\s+)(get|let|set)(\s+)([a-z_][a-z0-9_]*)',
545 bygroups(Keyword.Declaration, Whitespace, Keyword.Declaration, Whitespace, Name.Property)),
546 (r'rem\s.*[^\n]*', Comment.Single),
547 (words(_vbscript_builtins.KEYWORDS, suffix=r'\b'), Keyword),
548 (words(_vbscript_builtins.OPERATORS), Operator),
549 (words(_vbscript_builtins.OPERATOR_WORDS, suffix=r'\b'), Operator.Word),
550 (words(_vbscript_builtins.BUILTIN_CONSTANTS, suffix=r'\b'), Name.Constant),
551 (words(_vbscript_builtins.BUILTIN_FUNCTIONS, suffix=r'\b'), Name.Builtin),
552 (words(_vbscript_builtins.BUILTIN_VARIABLES, suffix=r'\b'), Name.Builtin),
553 (r'[a-z_][a-z0-9_]*', Name),
554 (r'\b_\n', Operator),
555 (words(r'(),.:'), Punctuation),
556 (r'.+(\n)?', Error)
557 ],
558 'dim_more': [
559 (r'(\s*)(,)(\s*)([a-z_][a-z0-9]*)',
560 bygroups(Whitespace, Punctuation, Whitespace, Name.Variable)),
561 default('#pop'),
562 ],
563 'string': [
564 (r'[^"\n]+', String.Double),
565 (r'\"\"', String.Double),
566 (r'"', String.Double, '#pop'),
567 (r'\n', Error, '#pop'), # Unterminated string
568 ],
569 }
572class BBCBasicLexer(RegexLexer):
573 """
574 BBC Basic was supplied on the BBC Micro, and later Acorn RISC OS.
575 It is also used by BBC Basic For Windows.
577 .. versionadded:: 2.4
578 """
579 base_keywords = ['OTHERWISE', 'AND', 'DIV', 'EOR', 'MOD', 'OR', 'ERROR',
580 'LINE', 'OFF', 'STEP', 'SPC', 'TAB', 'ELSE', 'THEN',
581 'OPENIN', 'PTR', 'PAGE', 'TIME', 'LOMEM', 'HIMEM', 'ABS',
582 'ACS', 'ADVAL', 'ASC', 'ASN', 'ATN', 'BGET', 'COS', 'COUNT',
583 'DEG', 'ERL', 'ERR', 'EVAL', 'EXP', 'EXT', 'FALSE', 'FN',
584 'GET', 'INKEY', 'INSTR', 'INT', 'LEN', 'LN', 'LOG', 'NOT',
585 'OPENUP', 'OPENOUT', 'PI', 'POINT', 'POS', 'RAD', 'RND',
586 'SGN', 'SIN', 'SQR', 'TAN', 'TO', 'TRUE', 'USR', 'VAL',
587 'VPOS', 'CHR$', 'GET$', 'INKEY$', 'LEFT$', 'MID$',
588 'RIGHT$', 'STR$', 'STRING$', 'EOF', 'PTR', 'PAGE', 'TIME',
589 'LOMEM', 'HIMEM', 'SOUND', 'BPUT', 'CALL', 'CHAIN', 'CLEAR',
590 'CLOSE', 'CLG', 'CLS', 'DATA', 'DEF', 'DIM', 'DRAW', 'END',
591 'ENDPROC', 'ENVELOPE', 'FOR', 'GOSUB', 'GOTO', 'GCOL', 'IF',
592 'INPUT', 'LET', 'LOCAL', 'MODE', 'MOVE', 'NEXT', 'ON',
593 'VDU', 'PLOT', 'PRINT', 'PROC', 'READ', 'REM', 'REPEAT',
594 'REPORT', 'RESTORE', 'RETURN', 'RUN', 'STOP', 'COLOUR',
595 'TRACE', 'UNTIL', 'WIDTH', 'OSCLI']
597 basic5_keywords = ['WHEN', 'OF', 'ENDCASE', 'ENDIF', 'ENDWHILE', 'CASE',
598 'CIRCLE', 'FILL', 'ORIGIN', 'POINT', 'RECTANGLE', 'SWAP',
599 'WHILE', 'WAIT', 'MOUSE', 'QUIT', 'SYS', 'INSTALL',
600 'LIBRARY', 'TINT', 'ELLIPSE', 'BEATS', 'TEMPO', 'VOICES',
601 'VOICE', 'STEREO', 'OVERLAY', 'APPEND', 'AUTO', 'CRUNCH',
602 'DELETE', 'EDIT', 'HELP', 'LIST', 'LOAD', 'LVAR', 'NEW',
603 'OLD', 'RENUMBER', 'SAVE', 'TEXTLOAD', 'TEXTSAVE',
604 'TWIN', 'TWINO', 'INSTALL', 'SUM', 'BEAT']
607 name = 'BBC Basic'
608 aliases = ['bbcbasic']
609 filenames = ['*.bbc']
611 tokens = {
612 'root': [
613 (r"[0-9]+", Name.Label),
614 (r"(\*)([^\n]*)",
615 bygroups(Keyword.Pseudo, Comment.Special)),
616 default('code'),
617 ],
619 'code': [
620 (r"(REM)([^\n]*)",
621 bygroups(Keyword.Declaration, Comment.Single)),
622 (r'\n', Whitespace, 'root'),
623 (r'\s+', Whitespace),
624 (r':', Comment.Preproc),
626 # Some special cases to make functions come out nicer
627 (r'(DEF)(\s*)(FN|PROC)([A-Za-z_@][\w@]*)',
628 bygroups(Keyword.Declaration, Whitespace,
629 Keyword.Declaration, Name.Function)),
630 (r'(FN|PROC)([A-Za-z_@][\w@]*)',
631 bygroups(Keyword, Name.Function)),
633 (r'(GOTO|GOSUB|THEN|RESTORE)(\s*)(\d+)',
634 bygroups(Keyword, Whitespace, Name.Label)),
636 (r'(TRUE|FALSE)', Keyword.Constant),
637 (r'(PAGE|LOMEM|HIMEM|TIME|WIDTH|ERL|ERR|REPORT\$|POS|VPOS|VOICES)',
638 Keyword.Pseudo),
640 (words(base_keywords), Keyword),
641 (words(basic5_keywords), Keyword),
643 ('"', String.Double, 'string'),
645 ('%[01]{1,32}', Number.Bin),
646 ('&[0-9a-f]{1,8}', Number.Hex),
648 (r'[+-]?[0-9]+\.[0-9]*(E[+-]?[0-9]+)?', Number.Float),
649 (r'[+-]?\.[0-9]+(E[+-]?[0-9]+)?', Number.Float),
650 (r'[+-]?[0-9]+E[+-]?[0-9]+', Number.Float),
651 (r'[+-]?\d+', Number.Integer),
653 (r'([A-Za-z_@][\w@]*[%$]?)', Name.Variable),
654 (r'([+\-]=|[$!|?+\-*/%^=><();]|>=|<=|<>|<<|>>|>>>|,)', Operator),
655 ],
656 'string': [
657 (r'[^"\n]+', String.Double),
658 (r'"', String.Double, '#pop'),
659 (r'\n', Error, 'root'), # Unterminated string
660 ],
661 }
663 def analyse_text(text):
664 if text.startswith('10REM >') or text.startswith('REM >'):
665 return 0.9