summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPat Hawks <pat@pathawks.com>2013-08-01 20:51:29 -0400
committerPat Hawks <pat@pathawks.com>2013-08-01 20:51:29 -0400
commita0a813093bfbd262e4131a8327cb57d15e244f0e (patch)
tree6dfb7a2695df1ad83c655a6e5cd34b970ba799e3
parent1ea0fa53d253eae501f0a48611dd01493240b34d (diff)
parentea8cb94d0455379ddba8a4fea0a028daa1c99df0 (diff)
downloadpygments-a0a813093bfbd262e4131a8327cb57d15e244f0e.tar.gz
Merged birkenfeld/pygments-main into default
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/qbasic.py141
2 files changed, 142 insertions, 0 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 969bdba5..6382b49f 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -234,6 +234,7 @@ LEXERS = {
'PythonConsoleLexer': ('pygments.lexers.agile', 'Python console session', ('pycon',), (), ('text/x-python-doctest',)),
'PythonLexer': ('pygments.lexers.agile', 'Python', ('python', 'py', 'sage'), ('*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac', '*.sage'), ('text/x-python', 'application/x-python')),
'PythonTracebackLexer': ('pygments.lexers.agile', 'Python Traceback', ('pytb',), ('*.pytb',), ('text/x-python-traceback',)),
+ 'QBasicLexer': ('pygments.lexers.qbasic', 'QBasic', ('qbasic', 'basic'), ('*.BAS', '*.bas'), ()),
'QmlLexer': ('pygments.lexers.web', 'QML', ('qml', 'Qt Meta Language', 'Qt modeling Language'), ('*.qml',), ('application/x-qml',)),
'RConsoleLexer': ('pygments.lexers.math', 'RConsole', ('rconsole', 'rout'), ('*.Rout',), ()),
'RPMSpecLexer': ('pygments.lexers.other', 'RPMSpec', ('spec',), ('*.spec',), ('text/x-rpm-spec',)),
diff --git a/pygments/lexers/qbasic.py b/pygments/lexers/qbasic.py
new file mode 100644
index 00000000..c08725e8
--- /dev/null
+++ b/pygments/lexers/qbasic.py
@@ -0,0 +1,141 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.lexers.qbasic
+ ~~~~~~~~~~~~~~~~~~~~~~
+
+ Simple lexer for Microsoft QBasic source code.
+
+ :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+from pygments.lexer import RegexLexer, include, bygroups, using, \
+ this, combined, ExtendedRegexLexer
+from pygments.token import *
+
+__all__ = ['QBasicLexer']
+
+class QBasicLexer(RegexLexer):
+ """
+ For
+ `QBasic <http://en.wikipedia.org/wiki/QBasic>`_
+ source code.
+ """
+
+ name = 'QBasic'
+ aliases = ['qbasic', 'basic']
+ filenames = ['*.BAS', '*.bas']
+ mimetypes = []
+
+ declarations = ['DATA', 'LET']
+
+ functions = [
+ 'ABS', 'ASC', 'ATN', 'CDBL', 'CHR$', 'CINT', 'CLNG',
+ 'COMMAND$', 'COS', 'CSNG', 'CSRLIN', 'CVD', 'CVDMBF', 'CVI',
+ 'CVL', 'CVS', 'CVSMBF', 'DATE$', 'ENVIRON$', 'EOF', 'ERDEV',
+ 'ERDEV$', 'ERL', 'ERR', 'EXP', 'FILEATTR', 'FIX', 'FRE',
+ 'FREEFILE', 'HEX$', 'INKEY$', 'INP', 'INPUT$', 'INSTR', 'INT',
+ 'IOCTL$', 'LBOUND', 'LCASE$', 'LEFT$', 'LEN', 'LOC', 'LOF',
+ 'LOG', 'LPOS', 'LTRIM$', 'MID$', 'MKD$', 'MKDMBF$', 'MKI$',
+ 'MKL$', 'MKS$', 'MKSMBF$', 'OCT$', 'PEEK', 'PEN', 'PLAY',
+ 'PMAP', 'POINT', 'POS', 'RIGHT$', 'RND', 'RTRIM$', 'SADD',
+ 'SCREEN', 'SEEK', 'SETMEM', 'SGN', 'SIN', 'SPACE$', 'SPC',
+ 'SQR', 'STICK', 'STR$', 'STRIG', 'STRING$', 'TAB', 'TAN',
+ 'TIME$', 'TIMER', 'UBOUND', 'UCASE$', 'VAL', 'VARPTR',
+ 'VARPTR$', 'VARSEG'
+ ]
+
+ metacommands = ['$DYNAMIC', '$INCLUDE', '$STATIC']
+
+ operators = ['AND', 'EQV', 'IMP', 'NOT', 'OR', 'XOR']
+
+ statements = [
+ 'BEEP', 'BLOAD', 'BSAVE', 'CALL', 'CALL_ABSOLUTE',
+ 'CALL_INTERRUPT', 'CALLS', 'CHAIN', 'CHDIR', 'CIRCLE', 'CLEAR',
+ 'CLOSE', 'CLS', 'COLOR', 'COM', 'COMMON', 'CONST', 'DATA',
+ 'DATE$', 'DECLARE', 'DEF_FN', 'DEF_SEG', 'DEFDBL', 'DEFINT',
+ 'DEFLNG', 'DEFSNG', 'DEFSTR', 'DEF', 'DIM', 'DO', 'LOOP',
+ 'DRAW', 'END', 'ENVIRON', 'ERASE', 'ERROR', 'EXIT', 'FIELD',
+ 'FILES', 'FOR', 'NEXT', 'FUNCTION', 'GET', 'GOSUB', 'GOTO',
+ 'IF', 'THEN', 'INPUT', 'INPUT_#', 'IOCTL', 'KEY', 'KEY',
+ 'KILL', 'LET', 'LINE', 'LINE_INPUT', 'LINE_INPUT_#', 'LOCATE',
+ 'LOCK', 'UNLOCK', 'LPRINT', 'LSET', 'MID$', 'MKDIR', 'NAME',
+ 'ON_COM', 'ON_ERROR', 'ON_KEY', 'ON_PEN', 'ON_PLAY',
+ 'ON_STRIG', 'ON_TIMER', 'ON_UEVENT', 'ON', 'OPEN', 'OPEN_COM',
+ 'OPTION_BASE', 'OUT', 'PAINT', 'PALETTE', 'PCOPY', 'PEN',
+ 'PLAY', 'POKE', 'PRESET', 'PRINT', 'PRINT_#', 'PRINT_USING',
+ 'PSET', 'PUT', 'PUT', 'RANDOMIZE', 'READ', 'REDIM', 'REM',
+ 'RESET', 'RESTORE', 'RESUME', 'RETURN', 'RMDIR', 'RSET', 'RUN',
+ 'SCREEN', 'SEEK', 'SELECT_CASE', 'SHARED', 'SHELL', 'SLEEP',
+ 'SOUND', 'STATIC', 'STOP', 'STRIG', 'SUB', 'SWAP', 'SYSTEM',
+ 'TIME$', 'TIMER', 'TROFF', 'TRON', 'TYPE', 'UEVENT', 'UNLOCK',
+ 'VIEW', 'WAIT', 'WHILE', 'WEND', 'WIDTH', 'WINDOW', 'WRITE'
+ ]
+
+ keywords = [
+ 'ACCESS', 'ALIAS', 'ANY', 'APPEND', 'AS', 'BASE', 'BINARY',
+ 'BYVAL', 'CASE', 'CDECL', 'DOUBLE', 'ELSE', 'ELSEIF', 'ENDIF',
+ 'INTEGER', 'IS', 'LIST', 'LOCAL', 'LONG', 'LOOP', 'MOD',
+ 'NEXT', 'OFF', 'ON', 'OUTPUT', 'RANDOM', 'SIGNAL', 'SINGLE',
+ 'STEP', 'STRING', 'THEN', 'TO', 'UNTIL', 'USING', 'WEND'
+ ]
+
+ tokens = {
+ 'root': [
+ (r'^(\s*)(\d*)(\s*)(REM .*)$',
+ bygroups(Text.Whitespace, Name.Label, Text.Whitespace, Comment.Single)),
+ (r'^(\s*)(\d+)(\s*)',
+ bygroups(Text.Whitespace, Name.Label, Text.Whitespace)),
+ (r'(?=[\s]*)(\w+)(?=[\s]*=)', Name.Variable.Global),
+ (r'(?=[^"]*)\'.*$', Comment.Single),
+ (r'"[^\n\"]*"', String.Double),
+ (r'END (FUNCTION|IF|SELECT|SUB)', Keyword.Reserved),
+ (r'(DECLARE)(\s+)([A-Z]+)(\s+)([^\s]+)',
+ bygroups(Keyword.Declaration, Text.Whitespace, Name.Variable, Text.Whitespace, Name)),
+ (r'(DIM)(\s+)(SHARED)(\s+)([^\n\s\t\(]+)',
+ bygroups(Keyword.Declaration, Text.Whitespace, Name.Variable, Text.Whitespace, Name.Variable.Global)),
+ (r'(DIM)(\s+)([^\n\s\t\(]+)',
+ bygroups(Keyword.Declaration, Text.Whitespace, Name.Variable.Global)),
+ (r'^(\s*)([a-zA-Z_]+)(\s*)(\=)',
+ bygroups(Text.Whitespace, Name.Variable.Global, Text.Whitespace, Operator)),
+ (r'(GOTO|GOSUB)(\s+)(\w+\:?)',
+ bygroups(Keyword.Reserved, Text.Whitespace, Name.Label)),
+ (r'(SUB)(\s+)(\w+\:?)',
+ bygroups(Keyword.Reserved, Text.Whitespace, Name.Label)),
+ (r'[a-zA-Z_]\w*[\$|@|#|&|!]', Name.Variable.Global),
+ (r'[a-zA-Z_]\w*\:', Name.Label),
+ (r'\-?\d*\.\d+[@|#]?', Number.Float),
+ (r'\-?\d+[@|#]', Number.Float),
+ (r'\-?\d+#?', Number.Integer.Long),
+ (r'\-?\d+#?', Number.Integer),
+ (r'!=|==|:=|\.=|<<|>>|[-~+/\\*%=<>&^|?:!.]', Operator),
+ include('declarations'),
+ include('functions'),
+ include('metacommands'),
+ include('operators'),
+ include('statements'),
+ include('keywords'),
+ (r'[\[\]{}(),;]', Punctuation),
+ (r'[\n]+', Text),
+ (r'[\s]+', Text.Whitespace),
+ (r'[\w]+', Name.Variable.Global),
+ ],
+ 'declarations': [
+ (r'\b(%s)\b' % '|'.join(declarations), Keyword.Declaration),
+ ],
+ 'functions': [
+ (r'\b(%s)\b' % '|'.join(functions), Keyword.Reserved),
+ ],
+ 'metacommands': [
+ (r'\b(%s)\b' % '|'.join(metacommands), Keyword.Constant),
+ ],
+ 'operators': [
+ (r'\b(%s)\b' % '|'.join(operators), Operator.Word),
+ ],
+ 'statements': [
+ (r'\b(%s)\b' % '|'.join(statements).replace('_',' '), Keyword.Reserved),
+ ],
+ 'keywords': [
+ (r'\b(%s)\b' % '|'.join(keywords), Keyword),
+ ],
+ }