pygments.rb 0.5.2 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/README.md +2 -0
  2. data/lexers +0 -0
  3. data/lib/pygments/version.rb +1 -1
  4. data/test/test_pygments.rb +1 -1
  5. data/vendor/custom_lexers/github.py +15 -9
  6. data/vendor/pygments-main/AUTHORS +12 -2
  7. data/vendor/pygments-main/CHANGES +52 -2
  8. data/vendor/pygments-main/REVISION +1 -1
  9. data/vendor/pygments-main/docs/src/lexerdevelopment.txt +52 -0
  10. data/vendor/pygments-main/external/lasso-builtins-generator-9.lasso +67 -44
  11. data/vendor/pygments-main/pygmentize +1 -1
  12. data/vendor/pygments-main/pygments/filters/__init__.py +2 -2
  13. data/vendor/pygments-main/pygments/formatter.py +3 -0
  14. data/vendor/pygments-main/pygments/lexers/__init__.py +11 -0
  15. data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +2880 -3124
  16. data/vendor/pygments-main/pygments/lexers/_mapping.py +30 -20
  17. data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +1 -1
  18. data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +206 -20
  19. data/vendor/pygments-main/pygments/lexers/agile.py +378 -5
  20. data/vendor/pygments-main/pygments/lexers/asm.py +2 -2
  21. data/vendor/pygments-main/pygments/lexers/compiled.py +235 -8
  22. data/vendor/pygments-main/pygments/lexers/dotnet.py +88 -47
  23. data/vendor/pygments-main/pygments/lexers/functional.py +195 -62
  24. data/vendor/pygments-main/pygments/lexers/github.py +15 -9
  25. data/vendor/pygments-main/pygments/lexers/jvm.py +14 -11
  26. data/vendor/pygments-main/pygments/lexers/math.py +284 -18
  27. data/vendor/pygments-main/pygments/lexers/other.py +132 -21
  28. data/vendor/pygments-main/pygments/lexers/shell.py +29 -15
  29. data/vendor/pygments-main/pygments/lexers/sql.py +1 -1
  30. data/vendor/pygments-main/pygments/lexers/templates.py +8 -8
  31. data/vendor/pygments-main/pygments/lexers/text.py +59 -9
  32. data/vendor/pygments-main/pygments/lexers/web.py +832 -210
  33. data/vendor/pygments-main/pygments/modeline.py +40 -0
  34. data/vendor/pygments-main/tests/examplefiles/Deflate.fs +578 -0
  35. data/vendor/pygments-main/tests/examplefiles/Get-CommandDefinitionHtml.ps1 +66 -0
  36. data/vendor/pygments-main/tests/examplefiles/IPDispatchC.nc +104 -0
  37. data/vendor/pygments-main/tests/examplefiles/IPDispatchP.nc +671 -0
  38. data/vendor/pygments-main/tests/examplefiles/RoleQ.pm6 +23 -0
  39. data/vendor/pygments-main/tests/examplefiles/example.ceylon +29 -10
  40. data/vendor/pygments-main/tests/examplefiles/example.clay +33 -0
  41. data/vendor/pygments-main/tests/examplefiles/example.hx +142 -0
  42. data/vendor/pygments-main/tests/examplefiles/example.lagda +19 -0
  43. data/vendor/pygments-main/tests/examplefiles/example.rexx +50 -0
  44. data/vendor/pygments-main/tests/examplefiles/example.stan +86 -75
  45. data/vendor/pygments-main/tests/examplefiles/garcia-wachs.kk +40 -30
  46. data/vendor/pygments-main/tests/examplefiles/grammar-test.p6 +22 -0
  47. data/vendor/pygments-main/tests/examplefiles/objc_example.m +7 -0
  48. data/vendor/pygments-main/tests/examplefiles/py3tb_test.py3tb +4 -0
  49. data/vendor/pygments-main/tests/examplefiles/swig_java.swg +1329 -0
  50. data/vendor/pygments-main/tests/examplefiles/swig_std_vector.i +225 -0
  51. data/vendor/pygments-main/tests/examplefiles/test.agda +102 -0
  52. data/vendor/pygments-main/tests/examplefiles/test.bb +95 -0
  53. data/vendor/pygments-main/tests/examplefiles/test.ebnf +31 -0
  54. data/vendor/pygments-main/tests/examplefiles/test.p6 +252 -0
  55. data/vendor/pygments-main/tests/examplefiles/type.lisp +16 -0
  56. data/vendor/pygments-main/tests/test_basic_api.py +3 -3
  57. data/vendor/pygments-main/tests/test_lexers_other.py +68 -0
  58. metadata +21 -2
@@ -67,7 +67,7 @@ class JavascriptLexer(RegexLexer):
67
67
  (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
68
68
  (r'[})\].]', Punctuation),
69
69
  (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
70
- r'throw|try|catch|finally|new|delete|typeof|instanceof|void|'
70
+ r'throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|'
71
71
  r'this)\b', Keyword, 'slashstartsregex'),
72
72
  (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
73
73
  (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
@@ -722,8 +722,10 @@ class HtmlLexer(RegexLexer):
722
722
  ('<![^>]*>', Comment.Preproc),
723
723
  (r'<\s*script\s*', Name.Tag, ('script-content', 'tag')),
724
724
  (r'<\s*style\s*', Name.Tag, ('style-content', 'tag')),
725
- (r'<\s*[a-zA-Z0-9:]+', Name.Tag, 'tag'),
726
- (r'<\s*/\s*[a-zA-Z0-9:]+\s*>', Name.Tag),
725
+ # note: this allows tag names not used in HTML like <x:with-dash>,
726
+ # this is to support yet-unknown template engines and the like
727
+ (r'<\s*[\w:.-]+', Name.Tag, 'tag'),
728
+ (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag),
727
729
  ],
728
730
  'comment': [
729
731
  ('[^-]+', Comment),
@@ -1006,7 +1008,8 @@ class XmlLexer(RegexLexer):
1006
1008
 
1007
1009
  name = 'XML'
1008
1010
  aliases = ['xml']
1009
- filenames = ['*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl']
1011
+ filenames = ['*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd',
1012
+ '*.wsdl', '*.wsf']
1010
1013
  mimetypes = ['text/xml', 'application/xml', 'image/svg+xml',
1011
1014
  'application/rss+xml', 'application/atom+xml']
1012
1015
 
@@ -1125,227 +1128,840 @@ class MxmlLexer(RegexLexer):
1125
1128
  }
1126
1129
 
1127
1130
 
1128
- class HaxeLexer(RegexLexer):
1131
+ class HaxeLexer(ExtendedRegexLexer):
1129
1132
  """
1130
- For haXe source code (http://haxe.org/).
1133
+ For Haxe source code (http://haxe.org/).
1131
1134
 
1132
1135
  *New in Pygments 1.3.*
1133
1136
  """
1134
1137
 
1135
- name = 'haXe'
1136
- aliases = ['hx', 'haXe']
1137
- filenames = ['*.hx']
1138
- mimetypes = ['text/haxe']
1138
+ name = 'Haxe'
1139
+ aliases = ['hx', 'Haxe', 'haxe', 'haXe', 'hxsl']
1140
+ filenames = ['*.hx', '*.hxsl']
1141
+ mimetypes = ['text/haxe', 'text/x-haxe', 'text/x-hx']
1142
+
1143
+ # keywords extracted from lexer.mll in the haxe compiler source
1144
+ keyword = (r'(?:function|class|static|var|if|else|while|do|for|'
1145
+ r'break|return|continue|extends|implements|import|'
1146
+ r'switch|case|default|public|private|try|untyped|'
1147
+ r'catch|new|this|throw|extern|enum|in|interface|'
1148
+ r'cast|override|dynamic|typedef|package|'
1149
+ r'inline|using|null|true|false|abstract)\b')
1150
+
1151
+ # idtype in lexer.mll
1152
+ typeid = r'_*[A-Z][_a-zA-Z0-9]*'
1139
1153
 
1140
- ident = r'(?:[a-zA-Z_][a-zA-Z0-9_]*)'
1141
- typeid = r'(?:(?:[a-z0-9_\.])*[A-Z_][A-Za-z0-9_]*)'
1142
- key_prop = r'(?:default|null|never)'
1143
- key_decl_mod = r'(?:public|private|override|static|inline|extern|dynamic)'
1154
+ # combined ident and dollar and idtype
1155
+ ident = r'(?:_*[a-z][_a-zA-Z0-9]*|_+[0-9][_a-zA-Z0-9]*|' + typeid + \
1156
+ '|_+|\$[_a-zA-Z0-9]+)'
1157
+
1158
+ binop = (r'(?:%=|&=|\|=|\^=|\+=|\-=|\*=|/=|<<=|>\s*>\s*=|>\s*>\s*>\s*=|==|'
1159
+ r'!=|<=|>\s*=|&&|\|\||<<|>>>|>\s*>|\.\.\.|<|>|%|&|\||\^|\+|\*|'
1160
+ r'/|\-|=>|=)')
1161
+
1162
+ # ident except keywords
1163
+ ident_no_keyword = r'(?!' + keyword + ')' + ident
1144
1164
 
1145
1165
  flags = re.DOTALL | re.MULTILINE
1146
1166
 
1167
+ preproc_stack = []
1168
+
1169
+ def preproc_callback(self, match, ctx):
1170
+ proc = match.group(2)
1171
+
1172
+ if proc == 'if':
1173
+ # store the current stack
1174
+ self.preproc_stack.append(ctx.stack[:])
1175
+ elif proc in ['else', 'elseif']:
1176
+ # restore the stack back to right before #if
1177
+ if self.preproc_stack: ctx.stack = self.preproc_stack[-1][:]
1178
+ elif proc == 'end':
1179
+ # remove the saved stack of previous #if
1180
+ if self.preproc_stack: self.preproc_stack.pop()
1181
+
1182
+ # #if and #elseif should follow by an expr
1183
+ if proc in ['if', 'elseif']:
1184
+ ctx.stack.append('preproc-expr')
1185
+
1186
+ # #error can be optionally follow by the error msg
1187
+ if proc in ['error']:
1188
+ ctx.stack.append('preproc-error')
1189
+
1190
+ yield match.start(), Comment.Preproc, '#' + proc
1191
+ ctx.pos = match.end()
1192
+
1193
+
1147
1194
  tokens = {
1148
1195
  'root': [
1149
- include('whitespace'),
1150
- include('comments'),
1151
- (key_decl_mod, Keyword.Declaration),
1152
- include('enumdef'),
1153
- include('typedef'),
1154
- include('classdef'),
1155
- include('imports'),
1196
+ include('spaces'),
1197
+ include('meta'),
1198
+ (r'(?:package)\b', Keyword.Namespace, ('semicolon', 'package')),
1199
+ (r'(?:import)\b', Keyword.Namespace, ('semicolon', 'import')),
1200
+ (r'(?:using)\b', Keyword.Namespace, ('semicolon', 'using')),
1201
+ (r'(?:extern|private)\b', Keyword.Declaration),
1202
+ (r'(?:abstract)\b', Keyword.Declaration, 'abstract'),
1203
+ (r'(?:class|interface)\b', Keyword.Declaration, 'class'),
1204
+ (r'(?:enum)\b', Keyword.Declaration, 'enum'),
1205
+ (r'(?:typedef)\b', Keyword.Declaration, 'typedef'),
1206
+
1207
+ # top-level expression
1208
+ # although it is not supported in haxe, but it is common to write
1209
+ # expression in web pages the positive lookahead here is to prevent
1210
+ # an infinite loop at the EOF
1211
+ (r'(?=.)', Text, 'expr-statement'),
1212
+ ],
1213
+
1214
+ # space/tab/comment/preproc
1215
+ 'spaces': [
1216
+ (r'\s+', Text),
1217
+ (r'//[^\n\r]*', Comment.Single),
1218
+ (r'/\*.*?\*/', Comment.Multiline),
1219
+ (r'(#)(if|elseif|else|end|error)\b', preproc_callback),
1156
1220
  ],
1157
1221
 
1158
- # General constructs
1159
- 'comments': [
1160
- (r'//.*?\n', Comment.Single),
1161
- (r'/\*.*?\*/', Comment.Multiline),
1162
- (r'#[^\n]*', Comment.Preproc),
1222
+ 'string-single-interpol': [
1223
+ (r'\$\{', String.Interpol, ('string-interpol-close', 'expr')),
1224
+ (r'\$\$', String.Escape),
1225
+ (r'\$(?=' + ident + ')', String.Interpol, 'ident'),
1226
+ include('string-single'),
1163
1227
  ],
1164
- 'whitespace': [
1165
- include('comments'),
1166
- (r'\s+', Text),
1228
+
1229
+ 'string-single': [
1230
+ (r"'", String.Single, '#pop'),
1231
+ (r'\\.', String.Escape),
1232
+ (r'.', String.Single),
1167
1233
  ],
1168
- 'codekeywords': [
1169
- (r'\b(if|else|while|do|for|in|break|continue|'
1170
- r'return|switch|case|try|catch|throw|null|trace|'
1171
- r'new|this|super|untyped|cast|callback|here)\b',
1172
- Keyword.Reserved),
1234
+
1235
+ 'string-double': [
1236
+ (r'"', String.Double, '#pop'),
1237
+ (r'\\.', String.Escape),
1238
+ (r'.', String.Double),
1173
1239
  ],
1174
- 'literals': [
1175
- (r'0[xX][0-9a-fA-F]+', Number.Hex),
1176
- (r'[0-9]+', Number.Integer),
1177
- (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
1178
- (r"'(\\\\|\\'|[^'])*'", String.Single),
1179
- (r'"(\\\\|\\"|[^"])*"', String.Double),
1180
- (r'~/([^\n])*?/[gisx]*', String.Regex),
1181
- (r'\b(true|false|null)\b', Keyword.Constant),
1182
- ],
1183
- 'codeblock': [
1184
- include('whitespace'),
1185
- include('new'),
1186
- include('case'),
1187
- include('anonfundef'),
1188
- include('literals'),
1189
- include('vardef'),
1190
- include('codekeywords'),
1191
- (r'[();,\[\]]', Punctuation),
1192
- (r'(?:=|\+=|-=|\*=|/=|%=|&=|\|=|\^=|<<=|>>=|>>>=|\|\||&&|'
1193
- r'\.\.\.|==|!=|>|<|>=|<=|\||&|\^|<<|>>>|>>|\+|\-|\*|/|%|'
1194
- r'!|\+\+|\-\-|~|\.|\?|\:)',
1195
- Operator),
1196
- (ident, Name),
1197
-
1198
- (r'}', Punctuation,'#pop'),
1199
- (r'{', Punctuation,'#push'),
1200
- ],
1201
-
1202
- # Instance/Block level constructs
1203
- 'propertydef': [
1204
- (r'(\()(' + key_prop + ')(,)(' + key_prop + ')(\))',
1205
- bygroups(Punctuation, Keyword.Reserved, Punctuation,
1206
- Keyword.Reserved, Punctuation)),
1240
+
1241
+ 'string-interpol-close': [
1242
+ (r'\$'+ident, String.Interpol),
1243
+ (r'\}', String.Interpol, '#pop'),
1207
1244
  ],
1208
- 'new': [
1209
- (r'\bnew\b', Keyword, 'typedecl'),
1245
+
1246
+ 'package': [
1247
+ include('spaces'),
1248
+ (ident, Name.Namespace),
1249
+ (r'\.', Punctuation, 'import-ident'),
1250
+ (r'', Text, '#pop'),
1210
1251
  ],
1211
- 'case': [
1212
- (r'\b(case)(\s+)(' + ident + ')(\s*)(\()',
1213
- bygroups(Keyword.Reserved, Text, Name, Text, Punctuation),
1214
- 'funargdecl'),
1252
+
1253
+ 'import': [
1254
+ include('spaces'),
1255
+ (ident, Name.Namespace),
1256
+ (r'\*', Keyword), # wildcard import
1257
+ (r'\.', Punctuation, 'import-ident'),
1258
+ (r'in', Keyword.Namespace, 'ident'),
1259
+ (r'', Text, '#pop'),
1215
1260
  ],
1216
- 'vardef': [
1217
- (r'\b(var)(\s+)(' + ident + ')',
1218
- bygroups(Keyword.Declaration, Text, Name.Variable), 'vardecl'),
1261
+
1262
+ 'import-ident': [
1263
+ include('spaces'),
1264
+ (r'\*', Keyword, '#pop'), # wildcard import
1265
+ (ident, Name.Namespace, '#pop'),
1219
1266
  ],
1220
- 'vardecl': [
1221
- include('whitespace'),
1222
- include('typelabel'),
1223
- (r'=', Operator,'#pop'),
1224
- (r';', Punctuation,'#pop'),
1267
+
1268
+ 'using': [
1269
+ include('spaces'),
1270
+ (ident, Name.Namespace),
1271
+ (r'\.', Punctuation, 'import-ident'),
1272
+ (r'', Text, '#pop'),
1225
1273
  ],
1226
- 'instancevardef': [
1227
- (key_decl_mod,Keyword.Declaration),
1228
- (r'\b(var)(\s+)(' + ident + ')',
1229
- bygroups(Keyword.Declaration, Text, Name.Variable.Instance),
1230
- 'instancevardecl'),
1274
+
1275
+ 'preproc-error': [
1276
+ (r'\s+', Comment.Preproc),
1277
+ (r"'", String.Single, ('#pop', 'string-single')),
1278
+ (r'"', String.Double, ('#pop', 'string-double')),
1279
+ (r'', Text, '#pop'),
1231
1280
  ],
1232
- 'instancevardecl': [
1233
- include('vardecl'),
1234
- include('propertydef'),
1281
+
1282
+ 'preproc-expr': [
1283
+ (r'\s+', Comment.Preproc),
1284
+ (r'\!', Comment.Preproc),
1285
+ (r'\(', Comment.Preproc, ('#pop', 'preproc-parenthesis')),
1286
+
1287
+ (ident, Comment.Preproc, '#pop'),
1288
+ (r"'", String.Single, ('#pop', 'string-single')),
1289
+ (r'"', String.Double, ('#pop', 'string-double')),
1235
1290
  ],
1236
1291
 
1237
- 'anonfundef': [
1238
- (r'\bfunction\b', Keyword.Declaration, 'fundecl'),
1292
+ 'preproc-parenthesis': [
1293
+ (r'\s+', Comment.Preproc),
1294
+ (r'\)', Comment.Preproc, '#pop'),
1295
+ ('', Text, 'preproc-expr-in-parenthesis'),
1239
1296
  ],
1240
- 'instancefundef': [
1241
- (key_decl_mod, Keyword.Declaration),
1242
- (r'\b(function)(\s+)(' + ident + ')',
1243
- bygroups(Keyword.Declaration, Text, Name.Function), 'fundecl'),
1297
+
1298
+ 'preproc-expr-chain': [
1299
+ (r'\s+', Comment.Preproc),
1300
+ (binop, Comment.Preproc, ('#pop', 'preproc-expr-in-parenthesis')),
1301
+ (r'', Text, '#pop'),
1244
1302
  ],
1245
- 'fundecl': [
1246
- include('whitespace'),
1247
- include('typelabel'),
1248
- include('generictypedecl'),
1249
- (r'\(',Punctuation,'funargdecl'),
1250
- (r'(?=[a-zA-Z0-9_])',Text,'#pop'),
1251
- (r'{',Punctuation,('#pop','codeblock')),
1252
- (r';',Punctuation,'#pop'),
1253
- ],
1254
- 'funargdecl': [
1255
- include('whitespace'),
1256
- (ident, Name.Variable),
1257
- include('typelabel'),
1258
- include('literals'),
1259
- (r'=', Operator),
1303
+
1304
+ # same as 'preproc-expr' but able to chain 'preproc-expr-chain'
1305
+ 'preproc-expr-in-parenthesis': [
1306
+ (r'\s+', Comment.Preproc),
1307
+ (r'\!', Comment.Preproc),
1308
+ (r'\(', Comment.Preproc,
1309
+ ('#pop', 'preproc-expr-chain', 'preproc-parenthesis')),
1310
+
1311
+ (ident, Comment.Preproc, ('#pop', 'preproc-expr-chain')),
1312
+ (r"'", String.Single,
1313
+ ('#pop', 'preproc-expr-chain', 'string-single')),
1314
+ (r'"', String.Double,
1315
+ ('#pop', 'preproc-expr-chain', 'string-double')),
1316
+ ],
1317
+
1318
+ 'abstract' : [
1319
+ include('spaces'),
1320
+ (r'', Text, ('#pop', 'abstract-body', 'abstract-relation',
1321
+ 'abstract-opaque', 'type-param-constraint', 'type-name')),
1322
+ ],
1323
+
1324
+ 'abstract-body' : [
1325
+ include('spaces'),
1326
+ (r'\{', Punctuation, ('#pop', 'class-body')),
1327
+ ],
1328
+
1329
+ 'abstract-opaque' : [
1330
+ include('spaces'),
1331
+ (r'\(', Punctuation, ('#pop', 'parenthesis-close', 'type')),
1332
+ (r'', Text, '#pop'),
1333
+ ],
1334
+
1335
+ 'abstract-relation': [
1336
+ include('spaces'),
1337
+ (r'(?:to|from)', Keyword.Declaration, 'type'),
1260
1338
  (r',', Punctuation),
1339
+ (r'', Text, '#pop'),
1340
+ ],
1341
+
1342
+ 'meta': [
1343
+ include('spaces'),
1344
+ (r'@', Name.Decorator, ('meta-body', 'meta-ident', 'meta-colon')),
1345
+ ],
1346
+
1347
+ # optional colon
1348
+ 'meta-colon': [
1349
+ include('spaces'),
1350
+ (r':', Name.Decorator, '#pop'),
1351
+ (r'', Text, '#pop'),
1352
+ ],
1353
+
1354
+ # same as 'ident' but set token as Name.Decorator instead of Name
1355
+ 'meta-ident': [
1356
+ include('spaces'),
1357
+ (ident, Name.Decorator, '#pop'),
1358
+ ],
1359
+
1360
+ 'meta-body': [
1361
+ include('spaces'),
1362
+ (r'\(', Name.Decorator, ('#pop', 'meta-call')),
1363
+ (r'', Text, '#pop'),
1364
+ ],
1365
+
1366
+ 'meta-call': [
1367
+ include('spaces'),
1368
+ (r'\)', Name.Decorator, '#pop'),
1369
+ (r'', Text, ('#pop', 'meta-call-sep', 'expr')),
1370
+ ],
1371
+
1372
+ 'meta-call-sep': [
1373
+ include('spaces'),
1374
+ (r'\)', Name.Decorator, '#pop'),
1375
+ (r',', Punctuation, ('#pop', 'meta-call')),
1376
+ ],
1377
+
1378
+ 'typedef': [
1379
+ include('spaces'),
1380
+ (r'', Text, ('#pop', 'typedef-body', 'type-param-constraint',
1381
+ 'type-name')),
1382
+ ],
1383
+
1384
+ 'typedef-body': [
1385
+ include('spaces'),
1386
+ (r'=', Operator, ('#pop', 'optional-semicolon', 'type')),
1387
+ ],
1388
+
1389
+ 'enum': [
1390
+ include('spaces'),
1391
+ (r'', Text, ('#pop', 'enum-body', 'bracket-open',
1392
+ 'type-param-constraint', 'type-name')),
1393
+ ],
1394
+
1395
+ 'enum-body': [
1396
+ include('spaces'),
1397
+ include('meta'),
1398
+ (r'\}', Punctuation, '#pop'),
1399
+ (ident_no_keyword, Name, ('enum-member', 'type-param-constraint')),
1400
+ ],
1401
+
1402
+ 'enum-member': [
1403
+ include('spaces'),
1404
+ (r'\(', Punctuation,
1405
+ ('#pop', 'semicolon', 'flag', 'function-param')),
1406
+ (r'', Punctuation, ('#pop', 'semicolon', 'flag')),
1407
+ ],
1408
+
1409
+ 'class': [
1410
+ include('spaces'),
1411
+ (r'', Text, ('#pop', 'class-body', 'bracket-open', 'extends',
1412
+ 'type-param-constraint', 'type-name')),
1413
+ ],
1414
+
1415
+ 'extends': [
1416
+ include('spaces'),
1417
+ (r'(?:extends|implements)\b', Keyword.Declaration, 'type'),
1418
+ (r',', Punctuation), # the comma is made optional here, since haxe2
1419
+ # requires the comma but haxe3 does not allow it
1420
+ (r'', Text, '#pop'),
1421
+ ],
1422
+
1423
+ 'bracket-open': [
1424
+ include('spaces'),
1425
+ (r'\{', Punctuation, '#pop'),
1426
+ ],
1427
+
1428
+ 'bracket-close': [
1429
+ include('spaces'),
1430
+ (r'\}', Punctuation, '#pop'),
1431
+ ],
1432
+
1433
+ 'class-body': [
1434
+ include('spaces'),
1435
+ include('meta'),
1436
+ (r'\}', Punctuation, '#pop'),
1437
+ (r'(?:static|public|private|override|dynamic|inline|macro)\b',
1438
+ Keyword.Declaration),
1439
+ (r'', Text, 'class-member'),
1440
+ ],
1441
+
1442
+ 'class-member': [
1443
+ include('spaces'),
1444
+ (r'(var)\b', Keyword.Declaration,
1445
+ ('#pop', 'optional-semicolon', 'prop')),
1446
+ (r'(function)\b', Keyword.Declaration,
1447
+ ('#pop', 'optional-semicolon', 'class-method')),
1448
+ ],
1449
+
1450
+ # local function, anonymous or not
1451
+ 'function-local': [
1452
+ include('spaces'),
1453
+ (r'(' + ident_no_keyword + ')?', Name.Function,
1454
+ ('#pop', 'expr', 'flag', 'function-param',
1455
+ 'parenthesis-open', 'type-param-constraint')),
1456
+ ],
1457
+
1458
+ 'optional-expr': [
1459
+ include('spaces'),
1460
+ include('expr'),
1461
+ (r'', Text, '#pop'),
1462
+ ],
1463
+
1464
+ 'class-method': [
1465
+ include('spaces'),
1466
+ (ident, Name.Function, ('#pop', 'optional-expr', 'flag',
1467
+ 'function-param', 'parenthesis-open',
1468
+ 'type-param-constraint')),
1469
+ ],
1470
+
1471
+ # function arguments
1472
+ 'function-param': [
1473
+ include('spaces'),
1474
+ (r'\)', Punctuation, '#pop'),
1261
1475
  (r'\?', Punctuation),
1476
+ (ident_no_keyword, Name,
1477
+ ('#pop', 'function-param-sep', 'assign', 'flag')),
1478
+ ],
1479
+
1480
+ 'function-param-sep': [
1481
+ include('spaces'),
1262
1482
  (r'\)', Punctuation, '#pop'),
1483
+ (r',', Punctuation, ('#pop', 'function-param')),
1263
1484
  ],
1264
1485
 
1265
- 'typelabel': [
1266
- (r':', Punctuation, 'type'),
1486
+ # class property
1487
+ # eg. var prop(default, null):String;
1488
+ 'prop': [
1489
+ include('spaces'),
1490
+ (ident_no_keyword, Name, ('#pop', 'assign', 'flag', 'prop-get-set')),
1267
1491
  ],
1268
- 'typedecl': [
1269
- include('whitespace'),
1270
- (typeid, Name.Class),
1271
- (r'<', Punctuation, 'generictypedecl'),
1272
- (r'(?=[{}()=,a-z])', Text,'#pop'),
1492
+
1493
+ 'prop-get-set': [
1494
+ include('spaces'),
1495
+ (r'\(', Punctuation, ('#pop', 'parenthesis-close',
1496
+ 'prop-get-set-opt', 'comma', 'prop-get-set-opt')),
1497
+ (r'', Text, '#pop'),
1498
+ ],
1499
+
1500
+ 'prop-get-set-opt': [
1501
+ include('spaces'),
1502
+ (r'(?:default|null|never|dynamic|get|set)\b', Keyword, '#pop'),
1503
+ (ident_no_keyword, Text, '#pop'), #custom getter/setter
1504
+ ],
1505
+
1506
+ 'expr-statement': [
1507
+ include('spaces'),
1508
+ # makes semicolon optional here, just to avoid checking the last
1509
+ # one is bracket or not.
1510
+ (r'', Text, ('#pop', 'optional-semicolon', 'expr')),
1511
+ ],
1512
+
1513
+ 'expr': [
1514
+ include('spaces'),
1515
+ (r'@', Name.Decorator, ('#pop', 'optional-expr', 'meta-body',
1516
+ 'meta-ident', 'meta-colon')),
1517
+ (r'(?:\+\+|\-\-|~(?!/)|!|\-)', Operator),
1518
+ (r'\(', Punctuation, ('#pop', 'expr-chain', 'parenthesis')),
1519
+ (r'(?:inline)\b', Keyword.Declaration),
1520
+ (r'(?:function)\b', Keyword.Declaration, ('#pop', 'expr-chain',
1521
+ 'function-local')),
1522
+ (r'\{', Punctuation, ('#pop', 'expr-chain', 'bracket')),
1523
+ (r'(?:true|false|null)\b', Keyword.Constant, ('#pop', 'expr-chain')),
1524
+ (r'(?:this)\b', Keyword, ('#pop', 'expr-chain')),
1525
+ (r'(?:cast)\b', Keyword, ('#pop', 'expr-chain', 'cast')),
1526
+ (r'(?:try)\b', Keyword, ('#pop', 'catch', 'expr')),
1527
+ (r'(?:var)\b', Keyword.Declaration, ('#pop', 'var')),
1528
+ (r'(?:new)\b', Keyword, ('#pop', 'expr-chain', 'new')),
1529
+ (r'(?:switch)\b', Keyword, ('#pop', 'switch')),
1530
+ (r'(?:if)\b', Keyword, ('#pop', 'if')),
1531
+ (r'(?:do)\b', Keyword, ('#pop', 'do')),
1532
+ (r'(?:while)\b', Keyword, ('#pop', 'while')),
1533
+ (r'(?:for)\b', Keyword, ('#pop', 'for')),
1534
+ (r'(?:untyped|throw)\b', Keyword),
1535
+ (r'(?:return)\b', Keyword, ('#pop', 'optional-expr')),
1536
+ (r'(?:macro)\b', Keyword, ('#pop', 'macro')),
1537
+ (r'(?:continue|break)\b', Keyword, '#pop'),
1538
+ (r'(?:\$\s*[a-z]\b|\$(?!'+ident+'))', Name, ('#pop', 'dollar')),
1539
+ (ident_no_keyword, Name, ('#pop', 'expr-chain')),
1540
+
1541
+ # Float
1542
+ (r'\.[0-9]+', Number.Float, ('#pop', 'expr-chain')),
1543
+ (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'expr-chain')),
1544
+ (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'expr-chain')),
1545
+ (r'[0-9]+\.[0-9]+', Number.Float, ('#pop', 'expr-chain')),
1546
+ (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, ('#pop', 'expr-chain')),
1547
+
1548
+ # Int
1549
+ (r'0x[0-9a-fA-F]+', Number.Hex, ('#pop', 'expr-chain')),
1550
+ (r'[0-9]+', Number.Integer, ('#pop', 'expr-chain')),
1551
+
1552
+ # String
1553
+ (r"'", String.Single, ('#pop', 'expr-chain', 'string-single-interpol')),
1554
+ (r'"', String.Double, ('#pop', 'expr-chain', 'string-double')),
1555
+
1556
+ # EReg
1557
+ (r'~/(\\\\|\\/|[^/\n])*/[gimsu]*', String.Regex, ('#pop', 'expr-chain')),
1558
+
1559
+ # Array
1560
+ (r'\[', Punctuation, ('#pop', 'expr-chain', 'array-decl')),
1561
+ ],
1562
+
1563
+ 'expr-chain': [
1564
+ include('spaces'),
1565
+ (r'(?:\+\+|\-\-)', Operator),
1566
+ (binop, Operator, ('#pop', 'expr')),
1567
+ (r'(?:in)\b', Keyword, ('#pop', 'expr')),
1568
+ (r'\?', Operator, ('#pop', 'expr', 'ternary', 'expr')),
1569
+ (r'(\.)(' + ident_no_keyword + ')', bygroups(Punctuation, Name)),
1570
+ (r'\[', Punctuation, 'array-access'),
1571
+ (r'\(', Punctuation, 'call'),
1572
+ (r'', Text, '#pop'),
1573
+ ],
1574
+
1575
+ # macro reification
1576
+ 'macro': [
1577
+ include('spaces'),
1578
+ (r':', Punctuation, ('#pop', 'type')),
1579
+ (r'', Text, ('#pop', 'expr')),
1580
+ ],
1581
+
1582
+ # cast can be written as "cast expr" or "cast(expr, type)"
1583
+ 'cast': [
1584
+ include('spaces'),
1585
+ (r'\(', Punctuation, ('#pop', 'parenthesis-close',
1586
+ 'cast-type', 'expr')),
1587
+ (r'', Text, ('#pop', 'expr')),
1588
+ ],
1589
+
1590
+ # optionally give a type as the 2nd argument of cast()
1591
+ 'cast-type': [
1592
+ include('spaces'),
1593
+ (r',', Punctuation, ('#pop', 'type')),
1594
+ (r'', Text, '#pop'),
1595
+ ],
1596
+
1597
+ 'catch': [
1598
+ include('spaces'),
1599
+ (r'(?:catch)\b', Keyword, ('expr', 'function-param',
1600
+ 'parenthesis-open')),
1601
+ (r'', Text, '#pop'),
1602
+ ],
1603
+
1604
+ # do-while loop
1605
+ 'do': [
1606
+ include('spaces'),
1607
+ (r'', Punctuation, ('#pop', 'do-while', 'expr')),
1608
+ ],
1609
+
1610
+ # the while after do
1611
+ 'do-while': [
1612
+ include('spaces'),
1613
+ (r'(?:while)\b', Keyword, ('#pop', 'parenthesis',
1614
+ 'parenthesis-open')),
1615
+ ],
1616
+
1617
+ 'while': [
1618
+ include('spaces'),
1619
+ (r'\(', Punctuation, ('#pop', 'expr', 'parenthesis')),
1620
+ ],
1621
+
1622
+ 'for': [
1623
+ include('spaces'),
1624
+ (r'\(', Punctuation, ('#pop', 'expr', 'parenthesis')),
1625
+ ],
1626
+
1627
+ 'if': [
1628
+ include('spaces'),
1629
+ (r'\(', Punctuation, ('#pop', 'else', 'optional-semicolon', 'expr',
1630
+ 'parenthesis')),
1631
+ ],
1632
+
1633
+ 'else': [
1634
+ include('spaces'),
1635
+ (r'(?:else)\b', Keyword, ('#pop', 'expr')),
1636
+ (r'', Text, '#pop'),
1637
+ ],
1638
+
1639
+ 'switch': [
1640
+ include('spaces'),
1641
+ (r'', Text, ('#pop', 'switch-body', 'bracket-open', 'expr')),
1642
+ ],
1643
+
1644
+ 'switch-body': [
1645
+ include('spaces'),
1646
+ (r'(?:case|default)\b', Keyword, ('case-block', 'case')),
1647
+ (r'\}', Punctuation, '#pop'),
1648
+ ],
1649
+
1650
+ 'case': [
1651
+ include('spaces'),
1652
+ (r':', Punctuation, '#pop'),
1653
+ (r'', Text, ('#pop', 'case-sep', 'case-guard', 'expr')),
1654
+ ],
1655
+
1656
+ 'case-sep': [
1657
+ include('spaces'),
1658
+ (r':', Punctuation, '#pop'),
1659
+ (r',', Punctuation, ('#pop', 'case')),
1660
+ ],
1661
+
1662
+ 'case-guard': [
1663
+ include('spaces'),
1664
+ (r'(?:if)\b', Keyword, ('#pop', 'parenthesis', 'parenthesis-open')),
1665
+ (r'', Text, '#pop'),
1666
+ ],
1667
+
1668
+ # optional multiple expr under a case
1669
+ 'case-block': [
1670
+ include('spaces'),
1671
+ (r'(?!(?:case|default)\b|\})', Keyword, 'expr-statement'),
1672
+ (r'', Text, '#pop'),
1673
+ ],
1674
+
1675
+ 'new': [
1676
+ include('spaces'),
1677
+ (r'', Text, ('#pop', 'call', 'parenthesis-open', 'type')),
1678
+ ],
1679
+
1680
+ 'array-decl': [
1681
+ include('spaces'),
1682
+ (r'\]', Punctuation, '#pop'),
1683
+ (r'', Text, ('#pop', 'array-decl-sep', 'expr')),
1684
+ ],
1685
+
1686
+ 'array-decl-sep': [
1687
+ include('spaces'),
1688
+ (r'\]', Punctuation, '#pop'),
1689
+ (r',', Punctuation, ('#pop', 'array-decl')),
1690
+ ],
1691
+
1692
+ 'array-access': [
1693
+ include('spaces'),
1694
+ (r'', Text, ('#pop', 'array-access-close', 'expr')),
1695
+ ],
1696
+
1697
+ 'array-access-close': [
1698
+ include('spaces'),
1699
+ (r'\]', Punctuation, '#pop'),
1700
+ ],
1701
+
1702
+ 'comma': [
1703
+ include('spaces'),
1704
+ (r',', Punctuation, '#pop'),
1273
1705
  ],
1706
+
1707
+ 'colon': [
1708
+ include('spaces'),
1709
+ (r':', Punctuation, '#pop'),
1710
+ ],
1711
+
1712
+ 'semicolon': [
1713
+ include('spaces'),
1714
+ (r';', Punctuation, '#pop'),
1715
+ ],
1716
+
1717
+ 'optional-semicolon': [
1718
+ include('spaces'),
1719
+ (r';', Punctuation, '#pop'),
1720
+ (r'', Text, '#pop'),
1721
+ ],
1722
+
1723
+ # identity that CAN be a Haxe keyword
1724
+ 'ident': [
1725
+ include('spaces'),
1726
+ (ident, Name, '#pop'),
1727
+ ],
1728
+
1729
+ 'dollar': [
1730
+ include('spaces'),
1731
+ (r'\{', Keyword, ('#pop', 'bracket-close', 'expr')),
1732
+ (r'', Text, ('#pop', 'expr-chain')),
1733
+ ],
1734
+
1735
+ 'type-name': [
1736
+ include('spaces'),
1737
+ (typeid, Name, '#pop'),
1738
+ ],
1739
+
1740
+ 'type-full-name': [
1741
+ include('spaces'),
1742
+ (r'\.', Punctuation, 'ident'),
1743
+ (r'', Text, '#pop'),
1744
+ ],
1745
+
1274
1746
  'type': [
1275
- include('whitespace'),
1276
- (typeid, Name.Class),
1277
- (r'<', Punctuation, 'generictypedecl'),
1278
- (r'->', Keyword.Type),
1279
- (r'(?=[{}(),;=])', Text, '#pop'),
1747
+ include('spaces'),
1748
+ (r'\?', Punctuation),
1749
+ (ident, Name, ('#pop', 'type-check', 'type-full-name')),
1750
+ (r'\{', Punctuation, ('#pop', 'type-check', 'type-struct')),
1751
+ (r'\(', Punctuation, ('#pop', 'type-check', 'type-parenthesis')),
1280
1752
  ],
1281
- 'generictypedecl': [
1282
- include('whitespace'),
1283
- (typeid, Name.Class),
1284
- (r'<', Punctuation, '#push'),
1753
+
1754
+ 'type-parenthesis': [
1755
+ include('spaces'),
1756
+ (r'', Text, ('#pop', 'parenthesis-close', 'type')),
1757
+ ],
1758
+
1759
+ 'type-check': [
1760
+ include('spaces'),
1761
+ (r'->', Punctuation, ('#pop', 'type')),
1762
+ (r'<(?!=)', Punctuation, 'type-param'),
1763
+ (r'', Text, '#pop'),
1764
+ ],
1765
+
1766
+ 'type-struct': [
1767
+ include('spaces'),
1768
+ (r'\}', Punctuation, '#pop'),
1769
+ (r'\?', Punctuation),
1770
+ (r'>', Punctuation, ('comma', 'type')),
1771
+ (ident_no_keyword, Name, ('#pop', 'type-struct-sep', 'type', 'colon')),
1772
+ include('class-body'),
1773
+ ],
1774
+
1775
+ 'type-struct-sep': [
1776
+ include('spaces'),
1777
+ (r'\}', Punctuation, '#pop'),
1778
+ (r',', Punctuation, ('#pop', 'type-struct')),
1779
+ ],
1780
+
1781
+ # type-param can be a normal type or a constant literal...
1782
+ 'type-param-type': [
1783
+ # Float
1784
+ (r'\.[0-9]+', Number.Float, '#pop'),
1785
+ (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, '#pop'),
1786
+ (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, '#pop'),
1787
+ (r'[0-9]+\.[0-9]+', Number.Float, '#pop'),
1788
+ (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, '#pop'),
1789
+
1790
+ # Int
1791
+ (r'0x[0-9a-fA-F]+', Number.Hex, '#pop'),
1792
+ (r'[0-9]+', Number.Integer, '#pop'),
1793
+
1794
+ # String
1795
+ (r"'", String.Single, ('#pop', 'string-single')),
1796
+ (r'"', String.Double, ('#pop', 'string-double')),
1797
+
1798
+ # EReg
1799
+ (r'~/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex, '#pop'),
1800
+
1801
+ # Array
1802
+ (r'\[', Operator, ('#pop', 'array-decl')),
1803
+
1804
+ include('type'),
1805
+ ],
1806
+
1807
+ # type-param part of a type
1808
+ # ie. the <A,B> path in Map<A,B>
1809
+ 'type-param': [
1810
+ include('spaces'),
1811
+ (r'', Text, ('#pop', 'type-param-sep', 'type-param-type')),
1812
+ ],
1813
+
1814
+ 'type-param-sep': [
1815
+ include('spaces'),
1285
1816
  (r'>', Punctuation, '#pop'),
1286
- (r',', Punctuation),
1817
+ (r',', Punctuation, ('#pop', 'type-param')),
1287
1818
  ],
1288
1819
 
1289
- # Top level constructs
1290
- 'imports': [
1291
- (r'(package|import|using)(\s+)([^;]+)(;)',
1292
- bygroups(Keyword.Namespace, Text, Name.Namespace,Punctuation)),
1820
+ # optional type-param that may include constraint
1821
+ # ie. <T:Constraint, T2:(ConstraintA,ConstraintB)>
1822
+ 'type-param-constraint': [
1823
+ include('spaces'),
1824
+ (r'<(?!=)', Punctuation, ('#pop', 'type-param-constraint-sep',
1825
+ 'type-param-constraint-flag', 'type-name')),
1826
+ (r'', Text, '#pop'),
1293
1827
  ],
1294
- 'typedef': [
1295
- (r'typedef', Keyword.Declaration, ('typedefprebody', 'typedecl')),
1828
+
1829
+ 'type-param-constraint-sep': [
1830
+ include('spaces'),
1831
+ (r'>', Punctuation, '#pop'),
1832
+ (r',', Punctuation, ('#pop', 'type-param-constraint-sep',
1833
+ 'type-param-constraint-flag', 'type-name')),
1296
1834
  ],
1297
- 'typedefprebody': [
1298
- include('whitespace'),
1299
- (r'(=)(\s*)({)', bygroups(Punctuation, Text, Punctuation),
1300
- ('#pop', 'typedefbody')),
1835
+
1836
+ # the optional constraint inside type-param
1837
+ 'type-param-constraint-flag': [
1838
+ include('spaces'),
1839
+ (r':', Punctuation, ('#pop', 'type-param-constraint-flag-type')),
1840
+ (r'', Text, '#pop'),
1301
1841
  ],
1302
- 'enumdef': [
1303
- (r'enum', Keyword.Declaration, ('enumdefprebody', 'typedecl')),
1842
+
1843
+ 'type-param-constraint-flag-type': [
1844
+ include('spaces'),
1845
+ (r'\(', Punctuation, ('#pop', 'type-param-constraint-flag-type-sep',
1846
+ 'type')),
1847
+ (r'', Text, ('#pop', 'type')),
1304
1848
  ],
1305
- 'enumdefprebody': [
1306
- include('whitespace'),
1307
- (r'{', Punctuation, ('#pop','enumdefbody')),
1849
+
1850
+ 'type-param-constraint-flag-type-sep': [
1851
+ include('spaces'),
1852
+ (r'\)', Punctuation, '#pop'),
1853
+ (r',', Punctuation, 'type'),
1308
1854
  ],
1309
- 'classdef': [
1310
- (r'class', Keyword.Declaration, ('classdefprebody', 'typedecl')),
1855
+
1856
+ # a parenthesis expr that contain exactly one expr
1857
+ 'parenthesis': [
1858
+ include('spaces'),
1859
+ (r'', Text, ('#pop', 'parenthesis-close', 'expr')),
1311
1860
  ],
1312
- 'classdefprebody': [
1313
- include('whitespace'),
1314
- (r'(extends|implements)', Keyword.Declaration,'typedecl'),
1315
- (r'{', Punctuation, ('#pop', 'classdefbody')),
1861
+
1862
+ 'parenthesis-open': [
1863
+ include('spaces'),
1864
+ (r'\(', Punctuation, '#pop'),
1316
1865
  ],
1317
- 'interfacedef': [
1318
- (r'interface', Keyword.Declaration,
1319
- ('interfacedefprebody', 'typedecl')),
1866
+
1867
+ 'parenthesis-close': [
1868
+ include('spaces'),
1869
+ (r'\)', Punctuation, '#pop'),
1320
1870
  ],
1321
- 'interfacedefprebody': [
1322
- include('whitespace'),
1323
- (r'(extends)', Keyword.Declaration, 'typedecl'),
1324
- (r'{', Punctuation, ('#pop', 'classdefbody')),
1325
- ],
1326
-
1327
- 'typedefbody': [
1328
- include('whitespace'),
1329
- include('instancevardef'),
1330
- include('instancefundef'),
1331
- (r'>', Punctuation, 'typedecl'),
1332
- (r',', Punctuation),
1333
- (r'}', Punctuation, '#pop'),
1334
- ],
1335
- 'enumdefbody': [
1336
- include('whitespace'),
1337
- (ident, Name.Variable.Instance),
1338
- (r'\(', Punctuation, 'funargdecl'),
1339
- (r';', Punctuation),
1340
- (r'}', Punctuation, '#pop'),
1341
- ],
1342
- 'classdefbody': [
1343
- include('whitespace'),
1344
- include('instancevardef'),
1345
- include('instancefundef'),
1346
- (r'}', Punctuation, '#pop'),
1347
- include('codeblock'),
1871
+
1872
+ 'var': [
1873
+ include('spaces'),
1874
+ (ident_no_keyword, Text, ('#pop', 'var-sep', 'assign', 'flag')),
1875
+ ],
1876
+
1877
+ # optional more var decl.
1878
+ 'var-sep': [
1879
+ include('spaces'),
1880
+ (r',', Punctuation, ('#pop', 'var')),
1881
+ (r'', Text, '#pop'),
1882
+ ],
1883
+
1884
+ # optional assignment
1885
+ 'assign': [
1886
+ include('spaces'),
1887
+ (r'=', Operator, ('#pop', 'expr')),
1888
+ (r'', Text, '#pop'),
1889
+ ],
1890
+
1891
+ # optional type flag
1892
+ 'flag': [
1893
+ include('spaces'),
1894
+ (r':', Punctuation, ('#pop', 'type')),
1895
+ (r'', Text, '#pop'),
1348
1896
  ],
1897
+
1898
+ # colon as part of a ternary operator (?:)
1899
+ 'ternary': [
1900
+ include('spaces'),
1901
+ (r':', Operator, '#pop'),
1902
+ ],
1903
+
1904
+ # function call
1905
+ 'call': [
1906
+ include('spaces'),
1907
+ (r'\)', Punctuation, '#pop'),
1908
+ (r'', Text, ('#pop', 'call-sep', 'expr')),
1909
+ ],
1910
+
1911
+ # after a call param
1912
+ 'call-sep': [
1913
+ include('spaces'),
1914
+ (r'\)', Punctuation, '#pop'),
1915
+ (r',', Punctuation, ('#pop', 'call')),
1916
+ ],
1917
+
1918
+ # bracket can be block or object
1919
+ 'bracket': [
1920
+ include('spaces'),
1921
+ (r'(?!(?:\$\s*[a-z]\b|\$(?!'+ident+')))' + ident_no_keyword, Name,
1922
+ ('#pop', 'bracket-check')),
1923
+ (r"'", String.Single, ('#pop', 'bracket-check', 'string-single')),
1924
+ (r'"', String.Double, ('#pop', 'bracket-check', 'string-double')),
1925
+ (r'', Text, ('#pop', 'block')),
1926
+ ],
1927
+
1928
+ 'bracket-check': [
1929
+ include('spaces'),
1930
+ (r':', Punctuation, ('#pop', 'object-sep', 'expr')), #is object
1931
+ (r'', Text, ('#pop', 'block', 'optional-semicolon', 'expr-chain')), #is block
1932
+ ],
1933
+
1934
+ # code block
1935
+ 'block': [
1936
+ include('spaces'),
1937
+ (r'\}', Punctuation, '#pop'),
1938
+ (r'', Text, 'expr-statement'),
1939
+ ],
1940
+
1941
+ # object in key-value pairs
1942
+ 'object': [
1943
+ include('spaces'),
1944
+ (r'\}', Punctuation, '#pop'),
1945
+ (r'', Text, ('#pop', 'object-sep', 'expr', 'colon', 'ident-or-string'))
1946
+ ],
1947
+
1948
+ # a key of an object
1949
+ 'ident-or-string': [
1950
+ include('spaces'),
1951
+ (ident_no_keyword, Name, '#pop'),
1952
+ (r"'", String.Single, ('#pop', 'string-single')),
1953
+ (r'"', String.Double, ('#pop', 'string-double')),
1954
+ ],
1955
+
1956
+ # after a key-value pair in object
1957
+ 'object-sep': [
1958
+ include('spaces'),
1959
+ (r'\}', Punctuation, '#pop'),
1960
+ (r',', Punctuation, ('#pop', 'object')),
1961
+ ],
1962
+
1963
+
1964
+
1349
1965
  }
1350
1966
 
1351
1967
  def analyse_text(text):
@@ -1797,7 +2413,7 @@ class CoffeeScriptLexer(RegexLexer):
1797
2413
  """
1798
2414
 
1799
2415
  name = 'CoffeeScript'
1800
- aliases = ['coffee-script', 'coffeescript']
2416
+ aliases = ['coffee-script', 'coffeescript', 'coffee']
1801
2417
  filenames = ['*.coffee']
1802
2418
  mimetypes = ['text/coffeescript']
1803
2419
 
@@ -3106,8 +3722,8 @@ class LassoLexer(RegexLexer):
3106
3722
  Additional options accepted:
3107
3723
 
3108
3724
  `builtinshighlighting`
3109
- If given and ``True``, highlight builtin tags, types, traits, and
3110
- methods (default: ``True``).
3725
+ If given and ``True``, highlight builtin types, traits, methods, and
3726
+ members (default: ``True``).
3111
3727
  `requiredelimiters`
3112
3728
  If given and ``True``, only highlight code between delimiters as Lasso
3113
3729
  (default: ``False``).
@@ -3186,13 +3802,15 @@ class LassoLexer(RegexLexer):
3186
3802
 
3187
3803
  # names
3188
3804
  (r'\$[a-z_][\w.]*', Name.Variable),
3189
- (r'#[a-z_][\w.]*|#\d+', Name.Variable.Instance),
3805
+ (r'#([a-z_][\w.]*|\d+)', Name.Variable.Instance),
3190
3806
  (r"(\.)('[a-z_][\w.]*')",
3191
3807
  bygroups(Name.Builtin.Pseudo, Name.Variable.Class)),
3192
- (r"(self)(->)('[a-z_][\w.]*')",
3808
+ (r"(self)(\s*->\s*)('[a-z_][\w.]*')",
3193
3809
  bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)),
3194
3810
  (r'(\.\.?)([a-z_][\w.]*)',
3195
- bygroups(Name.Builtin.Pseudo, Name.Other)),
3811
+ bygroups(Name.Builtin.Pseudo, Name.Other.Member)),
3812
+ (r'(->\\?\s*|&\s*)([a-z_][\w.]*)',
3813
+ bygroups(Operator, Name.Other.Member)),
3196
3814
  (r'(self|inherited|global|void)\b', Name.Builtin.Pseudo),
3197
3815
  (r'-[a-z_][\w.]*', Name.Attribute),
3198
3816
  (r'(::\s*)([a-z_][\w.]*)', bygroups(Punctuation, Name.Label)),
@@ -3207,15 +3825,13 @@ class LassoLexer(RegexLexer):
3207
3825
  r'Error_UpdateError)\b', Name.Exception),
3208
3826
 
3209
3827
  # definitions
3210
- (r'(define)(\s+)([a-z_][\w.]*)(\s*)(=>)(\s*)(type|trait|thread)\b',
3211
- bygroups(Keyword.Declaration, Text, Name.Class, Text, Operator,
3212
- Text, Keyword)),
3213
- (r'(define)(\s+)([a-z_][\w.]*)(->)([a-z_][\w.]*=?|[-+*/%<>]|==)',
3828
+ (r'(define)(\s+)([a-z_][\w.]*)(\s*=>\s*)(type|trait|thread)\b',
3829
+ bygroups(Keyword.Declaration, Text, Name.Class, Operator, Keyword)),
3830
+ (r'(define)(\s+)([a-z_][\w.]*)(\s*->\s*)([a-z_][\w.]*=?|[-+*/%<>]|==)',
3214
3831
  bygroups(Keyword.Declaration, Text, Name.Class, Operator,
3215
- Name.Function), 'signature'),
3832
+ Name.Function), 'signature'),
3216
3833
  (r'(define)(\s+)([a-z_][\w.]*)',
3217
- bygroups(Keyword.Declaration, Text, Name.Function),
3218
- 'signature'),
3834
+ bygroups(Keyword.Declaration, Text, Name.Function), 'signature'),
3219
3835
  (r'(public|protected|private|provide)(\s+)(([a-z_][\w.]*=?|'
3220
3836
  r'[-+*/%<>]|==)(?=\s*\())', bygroups(Keyword, Text, Name.Function),
3221
3837
  'signature'),
@@ -3224,14 +3840,13 @@ class LassoLexer(RegexLexer):
3224
3840
 
3225
3841
  # keywords
3226
3842
  (r'(true|false|none|minimal|full|all)\b', Keyword.Constant),
3227
- (r'(local|var|variable|data)\b', Keyword.Declaration),
3843
+ (r'(local|var|variable|data(?=\s))\b', Keyword.Declaration),
3228
3844
  (r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|'
3229
- r'null)\b', Keyword.Type),
3845
+ r'null|list|queue|set|stack|staticarray)\b', Keyword.Type),
3230
3846
  (r'([a-z_][\w.]*)(\s+)(in)\b', bygroups(Name, Text, Keyword)),
3231
3847
  (r'(let|into)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Text, Name)),
3232
3848
  (r'require\b', Keyword, 'requiresection'),
3233
- (r'(/?)(Namespace_Using)\b',
3234
- bygroups(Punctuation, Keyword.Namespace)),
3849
+ (r'(/?)(Namespace_Using)\b', bygroups(Punctuation, Keyword.Namespace)),
3235
3850
  (r'(/?)(Cache|Database_Names|Database_SchemaNames|'
3236
3851
  r'Database_TableNames|Define_Tag|Define_Type|Email_Batch|'
3237
3852
  r'Encode_Set|HTML_Comment|Handle|Handle_Error|Header|If|Inline|'
@@ -3249,16 +3864,13 @@ class LassoLexer(RegexLexer):
3249
3864
  r'frozen|group|handle_failure|import|in|into|join|let|match|max|'
3250
3865
  r'min|on|order|parent|protected|provide|public|require|skip|'
3251
3866
  r'split_thread|sum|take|thread|to|trait|type|where|with|yield)\b',
3252
- bygroups(Punctuation, Keyword)),
3867
+ bygroups(Punctuation, Keyword)),
3253
3868
 
3254
3869
  # other
3255
- (r'(([a-z_][\w.]*=?|[-+*/%<>]|==)(?=\s*\([^)]*\)\s*=>))',
3256
- Name.Function, 'signature'),
3870
+ (r',', Punctuation, 'commamember'),
3257
3871
  (r'(and|or|not)\b', Operator.Word),
3258
- (r'([a-z_][\w.]*)(\s*)(::\s*)([a-z_][\w.]*)(\s*)(=)',
3259
- bygroups(Name, Text, Punctuation, Name.Label, Text, Operator)),
3260
- (r'((?<!->)[a-z_][\w.]*)(\s*)(=(?!=))',
3261
- bygroups(Name, Text, Operator)),
3872
+ (r'([a-z_][\w.]*)(\s*::\s*)?([a-z_][\w.]*)?(\s*=(?!=))',
3873
+ bygroups(Name, Punctuation, Name.Label, Operator)),
3262
3874
  (r'(/?)([\w.]+)', bygroups(Punctuation, Name.Other)),
3263
3875
  (r'(=)(bw|ew|cn|lte?|gte?|n?eq|ft|n?rx)\b',
3264
3876
  bygroups(Operator, Operator.Word)),
@@ -3310,6 +3922,13 @@ class LassoLexer(RegexLexer):
3310
3922
  (r'[(,]', Punctuation),
3311
3923
  include('whitespacecomments'),
3312
3924
  ],
3925
+ 'commamember': [
3926
+ (r'(([a-z_][\w.]*=?|[-+*/%<>]|==)'
3927
+ r'(?=\s*(\(([^()]*\([^()]*\))*[^)]*\)\s*)?(::[\w.\s]+)?=>))',
3928
+ Name.Function, 'signature'),
3929
+ include('whitespacecomments'),
3930
+ (r'', Text, '#pop'),
3931
+ ],
3313
3932
  }
3314
3933
 
3315
3934
  def __init__(self, **options):
@@ -3319,10 +3938,13 @@ class LassoLexer(RegexLexer):
3319
3938
  options, 'requiredelimiters', False)
3320
3939
 
3321
3940
  self._builtins = set()
3941
+ self._members = set()
3322
3942
  if self.builtinshighlighting:
3323
- from pygments.lexers._lassobuiltins import BUILTINS
3943
+ from pygments.lexers._lassobuiltins import BUILTINS, MEMBERS
3324
3944
  for key, value in BUILTINS.iteritems():
3325
3945
  self._builtins.update(value)
3946
+ for key, value in MEMBERS.iteritems():
3947
+ self._members.update(value)
3326
3948
  RegexLexer.__init__(self, **options)
3327
3949
 
3328
3950
  def get_tokens_unprocessed(self, text):
@@ -3331,22 +3953,22 @@ class LassoLexer(RegexLexer):
3331
3953
  stack.append('delimiters')
3332
3954
  for index, token, value in \
3333
3955
  RegexLexer.get_tokens_unprocessed(self, text, stack):
3334
- if token is Name.Other:
3335
- if value.lower() in self._builtins:
3336
- yield index, Name.Builtin, value
3337
- continue
3956
+ if (token is Name.Other and value.lower() in self._builtins or
3957
+ token is Name.Other.Member and value.lower() in self._members):
3958
+ yield index, Name.Builtin, value
3959
+ continue
3338
3960
  yield index, token, value
3339
3961
 
3340
3962
  def analyse_text(text):
3341
3963
  rv = 0.0
3342
3964
  if 'bin/lasso9' in text:
3343
3965
  rv += 0.8
3344
- if re.search(r'<\?(=|lasso)', text, re.I):
3966
+ if re.search(r'<\?(=|lasso)|\A\[', text, re.I):
3345
3967
  rv += 0.4
3346
3968
  if re.search(r'local\(', text, re.I):
3347
3969
  rv += 0.4
3348
- if re.search(r'\[\n|\?>', text):
3349
- rv += 0.4
3970
+ if '?>' in text:
3971
+ rv += 0.1
3350
3972
  return rv
3351
3973
 
3352
3974