496 } |
499 } |
497 |
500 |
498 def analyse_text(text): |
501 def analyse_text(text): |
499 if '$DYNAMIC' in text or '$STATIC' in text: |
502 if '$DYNAMIC' in text or '$STATIC' in text: |
500 return 0.9 |
503 return 0.9 |
|
504 |
|
505 |
|
506 class VBScriptLexer(RegexLexer): |
|
507 """ |
|
508 VBScript is scripting language that is modeled on Visual Basic. |
|
509 |
|
510 .. versionadded:: 2.4 |
|
511 """ |
|
512 name = 'VBScript' |
|
513 aliases = ['vbscript'] |
|
514 filenames = ['*.vbs', '*.VBS'] |
|
515 flags = re.IGNORECASE |
|
516 |
|
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'\d+', 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_]*)', bygroups(Keyword.Declaration, Whitespace, Name.Class)), |
|
534 (r'(const)(\s+)([a-z_][a-z0-9_]*)', bygroups(Keyword.Declaration, Whitespace, Name.Constant)), |
|
535 (r'(end)(\s+)(class|function|if|property|sub|with)', bygroups(Keyword, Whitespace, Keyword)), |
|
536 (r'(on)(\s+)(error)(\s+)(goto)(\s+)(0)', |
|
537 bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword, Whitespace, Number.Integer)), |
|
538 (r'(on)(\s+)(error)(\s+)(resume)(\s+)(next)', |
|
539 bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword, Whitespace, Keyword)), |
|
540 (r'(option)(\s+)(explicit)', bygroups(Keyword, Whitespace, Keyword)), |
|
541 (r'(property)(\s+)(get|let|set)(\s+)([a-z_][a-z0-9_]*)', |
|
542 bygroups(Keyword.Declaration, Whitespace, Keyword.Declaration, Whitespace, Name.Property)), |
|
543 (r'rem\s.*[^\n]*', Comment.Single), |
|
544 (words(_vbscript_builtins.KEYWORDS, suffix=r'\b'), Keyword), |
|
545 (words(_vbscript_builtins.OPERATORS), Operator), |
|
546 (words(_vbscript_builtins.OPERATOR_WORDS, suffix=r'\b'), Operator.Word), |
|
547 (words(_vbscript_builtins.BUILTIN_CONSTANTS, suffix=r'\b'), Name.Constant), |
|
548 (words(_vbscript_builtins.BUILTIN_FUNCTIONS, suffix=r'\b'), Name.Builtin), |
|
549 (words(_vbscript_builtins.BUILTIN_VARIABLES, suffix=r'\b'), Name.Builtin), |
|
550 (r'[a-z_][a-z0-9_]*', Name), |
|
551 (r'\b_\n', Operator), |
|
552 (words(r'(),.:'), Punctuation), |
|
553 (r'.+(\n)?', Error) |
|
554 ], |
|
555 'dim_more': [ |
|
556 (r'(\s*)(,)(\s*)([a-z_][a-z0-9]*)', bygroups(Whitespace, Punctuation, Whitespace, Name.Variable)), |
|
557 default('#pop'), |
|
558 ], |
|
559 'string': [ |
|
560 (r'[^"\n]+', String.Double), |
|
561 (r'\"\"', String.Double), |
|
562 (r'"', String.Double, '#pop'), |
|
563 (r'\n', Error, '#pop'), # Unterminated string |
|
564 ], |
|
565 } |
|
566 |
|
567 |
|
568 class BBCBasicLexer(RegexLexer): |
|
569 """ |
|
570 BBC Basic was supplied on the BBC Micro, and later Acorn RISC OS. |
|
571 It is also used by BBC Basic For Windows. |
|
572 |
|
573 .. versionadded:: 2.4 |
|
574 """ |
|
575 base_keywords = ['OTHERWISE', 'AND', 'DIV', 'EOR', 'MOD', 'OR', 'ERROR', |
|
576 'LINE', 'OFF', 'STEP', 'SPC', 'TAB', 'ELSE', 'THEN', |
|
577 'OPENIN', 'PTR', 'PAGE', 'TIME', 'LOMEM', 'HIMEM', 'ABS', |
|
578 'ACS', 'ADVAL', 'ASC', 'ASN', 'ATN', 'BGET', 'COS', 'COUNT', |
|
579 'DEG', 'ERL', 'ERR', 'EVAL', 'EXP', 'EXT', 'FALSE', 'FN', |
|
580 'GET', 'INKEY', 'INSTR', 'INT', 'LEN', 'LN', 'LOG', 'NOT', |
|
581 'OPENUP', 'OPENOUT', 'PI', 'POINT', 'POS', 'RAD', 'RND', |
|
582 'SGN', 'SIN', 'SQR', 'TAN', 'TO', 'TRUE', 'USR', 'VAL', |
|
583 'VPOS', 'CHR$', 'GET$', 'INKEY$', 'LEFT$', 'MID$', |
|
584 'RIGHT$', 'STR$', 'STRING$', 'EOF', 'PTR', 'PAGE', 'TIME', |
|
585 'LOMEM', 'HIMEM', 'SOUND', 'BPUT', 'CALL', 'CHAIN', 'CLEAR', |
|
586 'CLOSE', 'CLG', 'CLS', 'DATA', 'DEF', 'DIM', 'DRAW', 'END', |
|
587 'ENDPROC', 'ENVELOPE', 'FOR', 'GOSUB', 'GOTO', 'GCOL', 'IF', |
|
588 'INPUT', 'LET', 'LOCAL', 'MODE', 'MOVE', 'NEXT', 'ON', |
|
589 'VDU', 'PLOT', 'PRINT', 'PROC', 'READ', 'REM', 'REPEAT', |
|
590 'REPORT', 'RESTORE', 'RETURN', 'RUN', 'STOP', 'COLOUR', |
|
591 'TRACE', 'UNTIL', 'WIDTH', 'OSCLI'] |
|
592 |
|
593 basic5_keywords = ['WHEN', 'OF', 'ENDCASE', 'ENDIF', 'ENDWHILE', 'CASE', |
|
594 'CIRCLE', 'FILL', 'ORIGIN', 'POINT', 'RECTANGLE', 'SWAP', |
|
595 'WHILE', 'WAIT', 'MOUSE', 'QUIT', 'SYS', 'INSTALL', |
|
596 'LIBRARY', 'TINT', 'ELLIPSE', 'BEATS', 'TEMPO', 'VOICES', |
|
597 'VOICE', 'STEREO', 'OVERLAY', 'APPEND', 'AUTO', 'CRUNCH', |
|
598 'DELETE', 'EDIT', 'HELP', 'LIST', 'LOAD', 'LVAR', 'NEW', |
|
599 'OLD', 'RENUMBER', 'SAVE', 'TEXTLOAD', 'TEXTSAVE', |
|
600 'TWIN', 'TWINO', 'INSTALL', 'SUM', 'BEAT'] |
|
601 |
|
602 |
|
603 name = 'BBC Basic' |
|
604 aliases = ['bbcbasic'] |
|
605 filenames = ['*.bbc'] |
|
606 |
|
607 tokens = { |
|
608 'root': [ |
|
609 (r"[0-9]+", Name.Label), |
|
610 (r"(\*)([^\n]*)", |
|
611 bygroups(Keyword.Pseudo, Comment.Special)), |
|
612 (r"", Whitespace, 'code'), |
|
613 ], |
|
614 |
|
615 'code': [ |
|
616 (r"(REM)([^\n]*)", |
|
617 bygroups(Keyword.Declaration, Comment.Single)), |
|
618 (r'\n', Whitespace, 'root'), |
|
619 (r'\s+', Whitespace), |
|
620 (r':', Comment.Preproc), |
|
621 |
|
622 # Some special cases to make functions come out nicer |
|
623 (r'(DEF)(\s*)(FN|PROC)([A-Za-z_@][\w@]*)', |
|
624 bygroups(Keyword.Declaration, Whitespace, Keyword.Declaration, Name.Function)), |
|
625 (r'(FN|PROC)([A-Za-z_@][\w@]*)', |
|
626 bygroups(Keyword, Name.Function)), |
|
627 |
|
628 (r'(GOTO|GOSUB|THEN|RESTORE)(\s*)(\d+)', |
|
629 bygroups(Keyword, Whitespace, Name.Label)), |
|
630 |
|
631 (r'(TRUE|FALSE)', Keyword.Constant), |
|
632 (r'(PAGE|LOMEM|HIMEM|TIME|WIDTH|ERL|ERR|REPORT\$|POS|VPOS|VOICES)', Keyword.Pseudo), |
|
633 |
|
634 (words(base_keywords), Keyword), |
|
635 (words(basic5_keywords), Keyword), |
|
636 |
|
637 ('"', String.Double, 'string'), |
|
638 |
|
639 ('%[01]{1,32}', Number.Bin), |
|
640 ('&[0-9a-f]{1,8}', Number.Hex), |
|
641 |
|
642 (r'[+-]?[0-9]+\.[0-9]*(E[+-]?[0-9]+)?', Number.Float), |
|
643 (r'[+-]?\.[0-9]+(E[+-]?[0-9]+)?', Number.Float), |
|
644 (r'[+-]?[0-9]+E[+-]?[0-9]+', Number.Float), |
|
645 (r'[+-]?\d+', Number.Integer), |
|
646 |
|
647 (r'([A-Za-z_@][\w@]*[%$]?)', Name.Variable), |
|
648 (r'([+\-]=|[$!|?+\-*/%^=><();]|>=|<=|<>|<<|>>|>>>|,)', Operator), |
|
649 ], |
|
650 'string': [ |
|
651 (r'[^"\n]+', String.Double), |
|
652 (r'"', String.Double, '#pop'), |
|
653 (r'\n', Error, 'root'), # Unterminated string |
|
654 ], |
|
655 } |
|
656 |
|
657 def analyse_text(text): |
|
658 if text.startswith('10REM >') or text.startswith('REM >'): |
|
659 return 0.9 |