|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.ambient |
|
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexers for AmbientTalk language. |
|
7 |
|
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 import re |
|
13 |
|
14 from pygments.lexer import RegexLexer, include, words |
|
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
|
16 Number, Punctuation |
|
17 |
|
18 __all__ = ['AmbientTalkLexer'] |
|
19 |
|
20 |
|
21 class AmbientTalkLexer(RegexLexer): |
|
22 """ |
|
23 Lexer for `AmbientTalk <https://code.google.com/p/ambienttalk>`_ source code. |
|
24 |
|
25 .. versionadded:: 2.0 |
|
26 """ |
|
27 name = 'AmbientTalk' |
|
28 filenames = ['*.at'] |
|
29 aliases = ['at', 'ambienttalk', 'ambienttalk/2'] |
|
30 mimetypes = ['text/x-ambienttalk'] |
|
31 |
|
32 flags = re.MULTILINE | re.DOTALL |
|
33 |
|
34 builtin = words(('if:', 'then:', 'else:', 'when:', 'whenever:', 'discovered:', |
|
35 'disconnected:', 'reconnected:', 'takenOffline:', 'becomes:', |
|
36 'export:', 'as:', 'object:', 'actor:', 'mirror:', 'taggedAs:', |
|
37 'mirroredBy:', 'is:')) |
|
38 tokens = { |
|
39 'root': [ |
|
40 (r'\s+', Text), |
|
41 (r'//.*?\n', Comment.Single), |
|
42 (r'/\*.*?\*/', Comment.Multiline), |
|
43 (r'(def|deftype|import|alias|exclude)\b', Keyword), |
|
44 (builtin, Name.Builtin), |
|
45 (r'(true|false|nil)\b', Keyword.Constant), |
|
46 (r'(~|lobby|jlobby|/)\.', Keyword.Constant, 'namespace'), |
|
47 (r'"(\\\\|\\"|[^"])*"', String), |
|
48 (r'\|', Punctuation, 'arglist'), |
|
49 (r'<:|[*^!%&<>+=,./?-]|:=', Operator), |
|
50 (r"`[a-zA-Z_]\w*", String.Symbol), |
|
51 (r"[a-zA-Z_]\w*:", Name.Function), |
|
52 (r"[{}()\[\];`]", Punctuation), |
|
53 (r'(self|super)\b', Name.Variable.Instance), |
|
54 (r"[a-zA-Z_]\w*", Name.Variable), |
|
55 (r"@[a-zA-Z_]\w*", Name.Class), |
|
56 (r"@\[", Name.Class, 'annotations'), |
|
57 include('numbers'), |
|
58 ], |
|
59 'numbers': [ |
|
60 (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), |
|
61 (r'\d+', Number.Integer) |
|
62 ], |
|
63 'namespace': [ |
|
64 (r'[a-zA-Z_]\w*\.', Name.Namespace), |
|
65 (r'[a-zA-Z_]\w*:', Name.Function, '#pop'), |
|
66 (r'[a-zA-Z_]\w*(?!\.)', Name.Function, '#pop') |
|
67 ], |
|
68 'annotations': [ |
|
69 (r"(.*?)\]", Name.Class, '#pop') |
|
70 ], |
|
71 'arglist': [ |
|
72 (r'\|', Punctuation, '#pop'), |
|
73 (r'\s*(,)\s*', Punctuation), |
|
74 (r'[a-zA-Z_]\w*', Name.Variable), |
|
75 ], |
|
76 } |