80 |
80 |
81 atom_re = r"(?:[a-z]\w*|'[^\n']*[^\\]')" |
81 atom_re = r"(?:[a-z]\w*|'[^\n']*[^\\]')" |
82 |
82 |
83 variable_re = r'(?:[A-Z_]\w*)' |
83 variable_re = r'(?:[A-Z_]\w*)' |
84 |
84 |
85 escape_re = r'(?:\\(?:[bdefnrstv\'"\\/]|[0-7][0-7]?[0-7]?|\^[a-zA-Z]))' |
85 esc_char_re = r'[bdefnrstv\'"\\]' |
|
86 esc_octal_re = r'[0-7][0-7]?[0-7]?' |
|
87 esc_hex_re = r'(?:x[0-9a-fA-F]{2}|x\{[0-9a-fA-F]+\})' |
|
88 esc_ctrl_re = r'\^[a-zA-Z]' |
|
89 escape_re = r'(?:\\(?:'+esc_char_re+r'|'+esc_octal_re+r'|'+esc_hex_re+r'|'+esc_ctrl_re+r'))' |
86 |
90 |
87 macro_re = r'(?:'+variable_re+r'|'+atom_re+r')' |
91 macro_re = r'(?:'+variable_re+r'|'+atom_re+r')' |
88 |
92 |
89 base_re = r'(?:[2-9]|[12][0-9]|3[0-6])' |
93 base_re = r'(?:[2-9]|[12][0-9]|3[0-6])' |
90 |
94 |
110 (variable_re, Name.Variable), |
114 (variable_re, Name.Variable), |
111 (atom_re, Name), |
115 (atom_re, Name), |
112 (r'\?'+macro_re, Name.Constant), |
116 (r'\?'+macro_re, Name.Constant), |
113 (r'\$(?:'+escape_re+r'|\\[ %]|[^\\])', String.Char), |
117 (r'\$(?:'+escape_re+r'|\\[ %]|[^\\])', String.Char), |
114 (r'#'+atom_re+r'(:?\.'+atom_re+r')?', Name.Label), |
118 (r'#'+atom_re+r'(:?\.'+atom_re+r')?', Name.Label), |
|
119 |
|
120 # Erlang script shebang |
|
121 (r'\A#!.+\n', Comment.Hashbang), |
|
122 |
|
123 # EEP 43: Maps |
|
124 # http://www.erlang.org/eeps/eep-0043.html |
|
125 (r'#\{', Punctuation, 'map_key'), |
115 ], |
126 ], |
116 'string': [ |
127 'string': [ |
117 (escape_re, String.Escape), |
128 (escape_re, String.Escape), |
118 (r'"', String, '#pop'), |
129 (r'"', String, '#pop'), |
119 (r'~[0-9.*]*[~#+bBcdefginpPswWxX]', String.Interpol), |
130 (r'~[0-9.*]*[~#+BPWXb-ginpswx]', String.Interpol), |
120 (r'[^"\\~]+', String), |
131 (r'[^"\\~]+', String), |
121 (r'~', String), |
132 (r'~', String), |
122 ], |
133 ], |
123 'directive': [ |
134 'directive': [ |
124 (r'(define)(\s*)(\()('+macro_re+r')', |
135 (r'(define)(\s*)(\()('+macro_re+r')', |
125 bygroups(Name.Entity, Text, Punctuation, Name.Constant), '#pop'), |
136 bygroups(Name.Entity, Text, Punctuation, Name.Constant), '#pop'), |
126 (r'(record)(\s*)(\()('+macro_re+r')', |
137 (r'(record)(\s*)(\()('+macro_re+r')', |
127 bygroups(Name.Entity, Text, Punctuation, Name.Label), '#pop'), |
138 bygroups(Name.Entity, Text, Punctuation, Name.Label), '#pop'), |
128 (atom_re, Name.Entity, '#pop'), |
139 (atom_re, Name.Entity, '#pop'), |
|
140 ], |
|
141 'map_key': [ |
|
142 include('root'), |
|
143 (r'=>', Punctuation, 'map_val'), |
|
144 (r':=', Punctuation, 'map_val'), |
|
145 (r'\}', Punctuation, '#pop'), |
|
146 ], |
|
147 'map_val': [ |
|
148 include('root'), |
|
149 (r',', Punctuation, '#pop'), |
|
150 (r'(?=\})', Punctuation, '#pop'), |
129 ], |
151 ], |
130 } |
152 } |
131 |
153 |
132 |
154 |
133 class ErlangShellLexer(Lexer): |
155 class ErlangShellLexer(Lexer): |
216 |
238 |
217 KEYWORD = ('fn', 'do', 'end', 'after', 'else', 'rescue', 'catch') |
239 KEYWORD = ('fn', 'do', 'end', 'after', 'else', 'rescue', 'catch') |
218 KEYWORD_OPERATOR = ('not', 'and', 'or', 'when', 'in') |
240 KEYWORD_OPERATOR = ('not', 'and', 'or', 'when', 'in') |
219 BUILTIN = ( |
241 BUILTIN = ( |
220 'case', 'cond', 'for', 'if', 'unless', 'try', 'receive', 'raise', |
242 'case', 'cond', 'for', 'if', 'unless', 'try', 'receive', 'raise', |
221 'quote', 'unquote', 'unquote_splicing', 'throw', 'super' |
243 'quote', 'unquote', 'unquote_splicing', 'throw', 'super', |
222 ) |
244 ) |
223 BUILTIN_DECLARATION = ( |
245 BUILTIN_DECLARATION = ( |
224 'def', 'defp', 'defmodule', 'defprotocol', 'defmacro', 'defmacrop', |
246 'def', 'defp', 'defmodule', 'defprotocol', 'defmacro', 'defmacrop', |
225 'defdelegate', 'defexception', 'defstruct', 'defimpl', 'defcallback' |
247 'defdelegate', 'defexception', 'defstruct', 'defimpl', 'defcallback', |
226 ) |
248 ) |
227 |
249 |
228 BUILTIN_NAMESPACE = ('import', 'require', 'use', 'alias') |
250 BUILTIN_NAMESPACE = ('import', 'require', 'use', 'alias') |
229 CONSTANT = ('nil', 'true', 'false') |
251 CONSTANT = ('nil', 'true', 'false') |
230 |
252 |
239 '->', '<-', '|', '.', '=', '~>', '<~', |
261 '->', '<-', '|', '.', '=', '~>', '<~', |
240 ) |
262 ) |
241 OPERATORS1 = ('<', '>', '+', '-', '*', '/', '!', '^', '&') |
263 OPERATORS1 = ('<', '>', '+', '-', '*', '/', '!', '^', '&') |
242 |
264 |
243 PUNCTUATION = ( |
265 PUNCTUATION = ( |
244 '\\\\', '<<', '>>', '=>', '(', ')', ':', ';', ',', '[', ']' |
266 '\\\\', '<<', '>>', '=>', '(', ')', ':', ';', ',', '[', ']', |
245 ) |
267 ) |
246 |
268 |
247 def get_tokens_unprocessed(self, text): |
269 def get_tokens_unprocessed(self, text): |
248 for index, token, value in RegexLexer.get_tokens_unprocessed(self, text): |
270 for index, token, value in RegexLexer.get_tokens_unprocessed(self, text): |
249 if token is Name: |
271 if token is Name: |