diff options
author | Pat Hawks <pat@pathawks.com> | 2013-03-07 14:36:54 -0400 |
---|---|---|
committer | Pat Hawks <pat@pathawks.com> | 2013-03-07 14:36:54 -0400 |
commit | 9ec12a9258c1e434291162e6ff06597761eea1e5 (patch) | |
tree | f46fe99f9cd4b99d5c4b95bfaf8536b1d5a2f766 /pygments/lexers/qbasic.py | |
parent | 9e8024c742cbdbc8a2bb975f4ee2add6b76bf20c (diff) | |
download | pygments-9ec12a9258c1e434291162e6ff06597761eea1e5.tar.gz |
Adding simple QBasic support.
Still LOTS of work to be done
Diffstat (limited to 'pygments/lexers/qbasic.py')
-rw-r--r-- | pygments/lexers/qbasic.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/pygments/lexers/qbasic.py b/pygments/lexers/qbasic.py new file mode 100644 index 00000000..0de87e62 --- /dev/null +++ b/pygments/lexers/qbasic.py @@ -0,0 +1,92 @@ +# -*- 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'] + mimetype = [] + + declarations = """\ + DATA DECLARE + """.split() + + functions = """\ +ABS ASC ATN CDBL 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 + """.split() + + metacommands = """\ + $DYNAMIC $INCLUDE $STATIC + """.split() + + operators = """\ + AND EQV IMP NOT OR XOR + """.split() + + statements = """\ + BEEP BLOAD BSAVE CALL CALL ABSOLUTE CALL INTERRUPT CALLS CHAIN CHDIR CIRCLE CLEAR CLOSE CLS COLOR COM COMMON CONST DATE$ DEF FN DEF SEG DEFDBL DEFINT DEFLNG DEFSNG DEFSTR DIM DO DRAW END ENVIRON ERASE ERROR EXIT FIELD FILES FOR FUNCTION GET GOSUB GOTO IF INPUT INPUT# IOCTL KEY KILL LET LINE INPUT LINE INPUT# LOCATE LOCK LPRINT LSET MID$ MKDIR NAME ON OPEN OPTION BASE OUT PAINT PALETTE PCOPY PEN PLAY POKE PRESET PRINT PRINT# PRINT USING PSET PUT RANDOMIZE READ REDIM 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 WIDTH WINDOW WRITE + """.split() + + 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 + """.split() + + tokens = { + 'root': [ + (r'\'.*\n', Comment.Single), + (r'REM .*\n', Comment.Single), + (r'[\s\t\n]+', Text.Whitespace), + (r'[\[\]{}(),;]', Punctuation), + (r'[a-zA-Z_][a-zA-Z0-9_]*[\$|@|#|&]', Name.Variable.Global), + (r'[a-zA-Z_][a-zA-Z0-9_]*\:', Name.Label), + (r'\-?[0-9]*\.[0-9]+\#?', Number.Float), + (r'\-?[0-9]+\#?', Number.Integer), + (r'!=|==|:=|\.=|<<|>>|[-~+/\\*%=<>&^|?:!.]', Operator), + (r'"[^\n\"]*"', String.Double), + (r'CHR$(.+)', String.Char), + include('declarations'), + include('functions'), + include('metacommands'), + include('operators'), + include('statements'), + include('keywords'), + ], + 'declarations': [ + (r'(?i)(\s*)(%s)\b' % '|'.join(declarations), Keyword.Declaration), + ], + 'functions': [ + (r'(?i)(\s*)(%s)\b' % '|'.join(functions), Keyword.Reserved), + ], + 'metacommands': [ + (r'(?i)(\s*)(%s)\b' % '|'.join(metacommands), Keyword.Constant), + ], + 'operators': [ + (r'(?i)(\s*)(%s)\b' % '|'.join(operators), Operator.Word), + ], + 'statements': [ + (r'(?i)(\s*)(%s)\b' % '|'.join(statements), Keyword.Reserved), + ], + 'keywords': [ + (r'(?i)(\s*)(%s)\b' % '|'.join(keywords), Keyword), + ], + } |