summaryrefslogtreecommitdiff
path: root/pygments/lexers/qbasic.py
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2014-04-24 11:38:52 -0400
committerTim Hatch <tim@timhatch.com>2014-04-24 11:38:52 -0400
commit4330942e358d466ec6516e4114865ec6ca641c48 (patch)
tree522d4de78d70f6acf59f1118c1512fd5649b1aa6 /pygments/lexers/qbasic.py
parentd1e781ec268ad6d1b3af570412245af4e8608770 (diff)
downloadpygments-4330942e358d466ec6516e4114865ec6ca641c48.tar.gz
Let qbasic lexer match functions like 'RIGHT$', with test
Diffstat (limited to 'pygments/lexers/qbasic.py')
-rw-r--r--pygments/lexers/qbasic.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/pygments/lexers/qbasic.py b/pygments/lexers/qbasic.py
index b84d36a9..80b80f9f 100644
--- a/pygments/lexers/qbasic.py
+++ b/pygments/lexers/qbasic.py
@@ -85,6 +85,8 @@ class QBasicLexer(RegexLexer):
tokens = {
'root': [
+ (r'\n+', Text),
+ (r'\s+', Text.Whitespace),
(r'^(\s*)(\d*)(\s*)(REM .*)$',
bygroups(Text.Whitespace, Name.Label, Text.Whitespace,
Comment.Single)),
@@ -93,7 +95,8 @@ class QBasicLexer(RegexLexer):
(r'(?=[\s]*)(\w+)(?=[\s]*=)', Name.Variable.Global),
(r'(?=[^"]*)\'.*$', Comment.Single),
(r'"[^\n\"]*"', String.Double),
- (r'END (FUNCTION|IF|SELECT|SUB)', Keyword.Reserved),
+ (r'(END)(\s+)(FUNCTION|IF|SELECT|SUB)',
+ bygroups(Keyword.Reserved, Text.Whitespace, Keyword.Reserved)),
(r'(DECLARE)(\s+)([A-Z]+)(\s+)(\S+)',
bygroups(Keyword.Declaration, Text.Whitespace, Name.Variable,
Text.Whitespace, Name)),
@@ -109,6 +112,12 @@ class QBasicLexer(RegexLexer):
bygroups(Keyword.Reserved, Text.Whitespace, Name.Label)),
(r'(SUB)(\s+)(\w+\:?)',
bygroups(Keyword.Reserved, Text.Whitespace, Name.Label)),
+ include('declarations'),
+ include('functions'),
+ include('metacommands'),
+ include('operators'),
+ include('statements'),
+ include('keywords'),
(r'[a-zA-Z_]\w*[\$@#&!]', Name.Variable.Global),
(r'[a-zA-Z_]\w*\:', Name.Label),
(r'\-?\d*\.\d+[@|#]?', Number.Float),
@@ -116,31 +125,24 @@ class QBasicLexer(RegexLexer):
(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),
],
+ # can't use regular \b because of X$()
'declarations': [
- (r'\b(%s)\b' % '|'.join(map(re.escape, declarations)),
+ (r'\b(%s)(?=\(|\b)' % '|'.join(map(re.escape, declarations)),
Keyword.Declaration),
],
'functions': [
- (r'\b(%s)\b' % '|'.join(map(re.escape, functions)),
+ (r'\b(%s)(?=\(|\b)' % '|'.join(map(re.escape, functions)),
Keyword.Reserved),
],
'metacommands': [
- (r'\b(%s)\b' % '|'.join(map(re.escape, metacommands)),
+ (r'\b(%s)(?=\(|\b)' % '|'.join(map(re.escape, metacommands)),
Keyword.Constant),
],
'operators': [
- (r'\b(%s)\b' % '|'.join(map(re.escape, operators)), Operator.Word),
+ (r'\b(%s)(?=\(|\b)' % '|'.join(map(re.escape, operators)), Operator.Word),
],
'statements': [
(r'\b(%s)\b' % '|'.join(map(re.escape, statements)),