3 pygments.lexers.int_fiction |
3 pygments.lexers.int_fiction |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for interactive fiction languages. |
6 Lexers for interactive fiction languages. |
7 |
7 |
8 :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 import re |
12 import re |
13 |
13 |
36 _name = r'[a-zA-Z_]\w*' |
36 _name = r'[a-zA-Z_]\w*' |
37 |
37 |
38 # Inform 7 maps these four character classes to their ASCII |
38 # Inform 7 maps these four character classes to their ASCII |
39 # equivalents. To support Inform 6 inclusions within Inform 7, |
39 # equivalents. To support Inform 6 inclusions within Inform 7, |
40 # Inform6Lexer maps them too. |
40 # Inform6Lexer maps them too. |
41 _dash = u'\\-\u2010-\u2014' |
41 _dash = '\\-\u2010-\u2014' |
42 _dquote = u'"\u201c\u201d' |
42 _dquote = '"\u201c\u201d' |
43 _squote = u"'\u2018\u2019" |
43 _squote = "'\u2018\u2019" |
44 _newline = u'\\n\u0085\u2028\u2029' |
44 _newline = '\\n\u0085\u2028\u2029' |
45 |
45 |
46 tokens = { |
46 tokens = { |
47 'root': [ |
47 'root': [ |
48 (r'\A(!%%[^%s]*[%s])+' % (_newline, _newline), Comment.Preproc, |
48 (r'\A(!%%[^%s]*[%s])+' % (_newline, _newline), Comment.Preproc, |
49 'directive'), |
49 'directive'), |
116 # Values |
116 # Values |
117 'value': [ |
117 'value': [ |
118 include('_whitespace'), |
118 include('_whitespace'), |
119 # Strings |
119 # Strings |
120 (r'[%s][^@][%s]' % (_squote, _squote), String.Char, '#pop'), |
120 (r'[%s][^@][%s]' % (_squote, _squote), String.Char, '#pop'), |
121 (r'([%s])(@\{[0-9a-fA-F]{1,4}\})([%s])' % (_squote, _squote), |
121 (r'([%s])(@\{[0-9a-fA-F]*\})([%s])' % (_squote, _squote), |
122 bygroups(String.Char, String.Escape, String.Char), '#pop'), |
122 bygroups(String.Char, String.Escape, String.Char), '#pop'), |
123 (r'([%s])(@.{2})([%s])' % (_squote, _squote), |
123 (r'([%s])(@.{2})([%s])' % (_squote, _squote), |
124 bygroups(String.Char, String.Escape, String.Char), '#pop'), |
124 bygroups(String.Char, String.Escape, String.Char), '#pop'), |
125 (r'[%s]' % _squote, String.Single, ('#pop', 'dictionary-word')), |
125 (r'[%s]' % _squote, String.Single, ('#pop', 'dictionary-word')), |
126 (r'[%s]' % _dquote, String.Double, ('#pop', 'string')), |
126 (r'[%s]' % _dquote, String.Double, ('#pop', 'string')), |
178 # Strings |
178 # Strings |
179 'dictionary-word': [ |
179 'dictionary-word': [ |
180 (r'[~^]+', String.Escape), |
180 (r'[~^]+', String.Escape), |
181 (r'[^~^\\@({%s]+' % _squote, String.Single), |
181 (r'[^~^\\@({%s]+' % _squote, String.Single), |
182 (r'[({]', String.Single), |
182 (r'[({]', String.Single), |
183 (r'@\{[0-9a-fA-F]{,4}\}', String.Escape), |
183 (r'@\{[0-9a-fA-F]*\}', String.Escape), |
184 (r'@.{2}', String.Escape), |
184 (r'@.{2}', String.Escape), |
185 (r'[%s]' % _squote, String.Single, '#pop') |
185 (r'[%s]' % _squote, String.Single, '#pop') |
186 ], |
186 ], |
187 'string': [ |
187 'string': [ |
188 (r'[~^]+', String.Escape), |
188 (r'[~^]+', String.Escape), |
189 (r'[^~^\\@({%s]+' % _dquote, String.Double), |
189 (r'[^~^\\@({%s]+' % _dquote, String.Double), |
190 (r'[({]', String.Double), |
190 (r'[({]', String.Double), |
191 (r'\\', String.Escape), |
191 (r'\\', String.Escape), |
192 (r'@(\\\s*[%s]\s*)*@((\\\s*[%s]\s*)*[0-9])*' % |
192 (r'@(\\\s*[%s]\s*)*@((\\\s*[%s]\s*)*[0-9])*' % |
193 (_newline, _newline), String.Escape), |
193 (_newline, _newline), String.Escape), |
194 (r'@(\\\s*[%s]\s*)*\{((\\\s*[%s]\s*)*[0-9a-fA-F]){,4}' |
194 (r'@(\\\s*[%s]\s*)*\{((\\\s*[%s]\s*)*[0-9a-fA-F])*' |
195 r'(\\\s*[%s]\s*)*\}' % (_newline, _newline, _newline), |
195 r'(\\\s*[%s]\s*)*\}' % (_newline, _newline, _newline), |
196 String.Escape), |
196 String.Escape), |
197 (r'@(\\\s*[%s]\s*)*.(\\\s*[%s]\s*)*.' % (_newline, _newline), |
197 (r'@(\\\s*[%s]\s*)*.(\\\s*[%s]\s*)*.' % (_newline, _newline), |
198 String.Escape), |
198 String.Escape), |
199 (r'[%s]' % _dquote, String.Double, '#pop') |
199 (r'[%s]' % _dquote, String.Double, '#pop') |
255 ('default', 'expression', '_constant')), |
255 ('default', 'expression', '_constant')), |
256 (r'(?i)(end\b)(.*)', bygroups(Keyword, Text)), |
256 (r'(?i)(end\b)(.*)', bygroups(Keyword, Text)), |
257 (r'(?i)(extend|verb)\b', Keyword, 'grammar'), |
257 (r'(?i)(extend|verb)\b', Keyword, 'grammar'), |
258 (r'(?i)fake_action\b', Keyword, ('default', '_constant')), |
258 (r'(?i)fake_action\b', Keyword, ('default', '_constant')), |
259 (r'(?i)import\b', Keyword, 'manifest'), |
259 (r'(?i)import\b', Keyword, 'manifest'), |
260 (r'(?i)(include|link)\b', Keyword, |
260 (r'(?i)(include|link|origsource)\b', Keyword, |
261 ('default', 'before-plain-string')), |
261 ('default', 'before-plain-string?')), |
262 (r'(?i)(lowstring|undef)\b', Keyword, ('default', '_constant')), |
262 (r'(?i)(lowstring|undef)\b', Keyword, ('default', '_constant')), |
263 (r'(?i)message\b', Keyword, ('default', 'diagnostic')), |
263 (r'(?i)message\b', Keyword, ('default', 'diagnostic')), |
264 (r'(?i)(nearby|object)\b', Keyword, |
264 (r'(?i)(nearby|object)\b', Keyword, |
265 ('object-body', '_object-head')), |
265 ('object-body', '_object-head')), |
266 (r'(?i)property\b', Keyword, |
266 (r'(?i)property\b', Keyword, |
363 ], |
363 ], |
364 # Include, Link, Message |
364 # Include, Link, Message |
365 'diagnostic': [ |
365 'diagnostic': [ |
366 include('_whitespace'), |
366 include('_whitespace'), |
367 (r'[%s]' % _dquote, String.Double, ('#pop', 'message-string')), |
367 (r'[%s]' % _dquote, String.Double, ('#pop', 'message-string')), |
368 default(('#pop', 'before-plain-string', 'directive-keyword?')) |
368 default(('#pop', 'before-plain-string?', 'directive-keyword?')) |
369 ], |
369 ], |
370 'before-plain-string': [ |
370 'before-plain-string?': [ |
371 include('_whitespace'), |
371 include('_whitespace'), |
372 (r'[%s]' % _dquote, String.Double, ('#pop', 'plain-string')) |
372 (r'[%s]' % _dquote, String.Double, ('#pop', 'plain-string')), |
|
373 default('#pop') |
373 ], |
374 ], |
374 'message-string': [ |
375 'message-string': [ |
375 (r'[~^]+', String.Escape), |
376 (r'[~^]+', String.Escape), |
376 include('plain-string') |
377 include('plain-string') |
377 ], |
378 ], |
384 'first', 'has', 'held', 'initial', 'initstr', 'last', 'long', 'meta', 'multi', |
385 'first', 'has', 'held', 'initial', 'initstr', 'last', 'long', 'meta', 'multi', |
385 'multiexcept', 'multiheld', 'multiinside', 'noun', 'number', 'only', 'private', |
386 'multiexcept', 'multiheld', 'multiinside', 'noun', 'number', 'only', 'private', |
386 'replace', 'reverse', 'scope', 'score', 'special', 'string', 'table', 'terminating', |
387 'replace', 'reverse', 'scope', 'score', 'special', 'string', 'table', 'terminating', |
387 'time', 'topic', 'warning', 'with'), suffix=r'\b'), |
388 'time', 'topic', 'warning', 'with'), suffix=r'\b'), |
388 Keyword, '#pop'), |
389 Keyword, '#pop'), |
|
390 (r'static\b', Keyword), |
389 (r'[%s]{1,2}>|[+=]' % _dash, Punctuation, '#pop') |
391 (r'[%s]{1,2}>|[+=]' % _dash, Punctuation, '#pop') |
390 ], |
392 ], |
391 '_directive-keyword': [ |
393 '_directive-keyword': [ |
392 include('_directive-keyword!'), |
394 include('_directive-keyword!'), |
393 include('value') |
395 include('value') |
854 (r'["\'\s&{<}\\]', token) |
856 (r'["\'\s&{<}\\]', token) |
855 ] |
857 ] |
856 |
858 |
857 tokens = { |
859 tokens = { |
858 'root': [ |
860 'root': [ |
859 (u'\ufeff', Text), |
861 ('\ufeff', Text), |
860 (r'\{', Punctuation, 'object-body'), |
862 (r'\{', Punctuation, 'object-body'), |
861 (r';+', Punctuation), |
863 (r';+', Punctuation), |
862 (r'(?=(argcount|break|case|catch|continue|default|definingobj|' |
864 (r'(?=(argcount|break|case|catch|continue|default|definingobj|' |
863 r'delegated|do|else|for|foreach|finally|goto|if|inherited|' |
865 r'delegated|do|else|for|foreach|finally|goto|if|inherited|' |
864 r'invokee|local|nil|new|operator|replaced|return|self|switch|' |
866 r'invokee|local|nil|new|operator|replaced|return|self|switch|' |