2 Inform 6 syntax highlighting.
4 This is an ultra-minimal version compared to the standard Pygments Inform6
5 lexer, but is much more forgiving of syntax errors. And it handles the
6 exclamation-inside-string case properly.
9 from pygments.lexer import RegexLexer
10 from pygments.token import (Text, Comment, Operator, Keyword, Name,
11 String, Number, Punctuation, Token)
13 objects = ["Class", "Nearby", "Object"]
15 directives = ["Abbreviate", "Array", "Attribute", "Btrace", "Class",
16 "Constant", "Default", "Dictionary", "End", "Endif", "Etrace",
17 "Extend", "Fake_action", "Global", "Ifdef", "Iffalse",
18 "Ifndef", "Ifnot", "Iftrue", "Ifv3", "Ifv5", "Import",
19 "Include", "Link", "Listsymbols", "Listdict", "Listverbs",
20 "Lowstring", "Ltrace", "Message", "Nearby", "Nobtrace",
21 "Noetrace", "Noltrace", "Notrace", "Object", "Property",
22 "Release", "Replace", "Serial", "Statusline", "Stub",
23 "Switches", "System_file", "Trace", "Verb", "Version",
26 defining = ["[", "array", "attribute", "class", "constant", "fake_action",
27 "global", "lowstring", "nearby", "object", "property"]
29 attributes = ["absent", "animate", "clothing", "concealed", "container",
30 "door", "edible", "enterable", "female", "general", "light",
31 "lockable", "locked", "male", "moved", "neuter", "on", "open",
32 "openable", "pluralname", "proper", "scenery", "scored",
33 "static", "supporter", "switchable", "talkable", "transparent",
34 "visited", "workflag", "worn"]
36 properties = ["n_to", "s_to", "e_to", "w_to", "ne_to", "se_to", "nw_to",
37 "sw_to", "u_to", "d_to", "in_to", "out_to", "add_to_scope",
38 "after", "article", "articles", "before", "cant_go", "capacity",
39 "daemon", "describe", "description", "door_dir", "door_to",
40 "each_turn", "found_in", "grammar", "initial",
41 "inside_description", "invent", "life", "list_together",
42 "name", "number", "orders", "parse_name", "plural",
43 "react_after", "react_before", "short_name", "short_name_indef",
44 "time_left", "time_out", "when_closed", "when_open", "when_on",
45 "when_off", "with_key"]
47 extension_properties = ["pname"]
49 keywords = ["box", "break", "continue", "do", "else", "font",
50 "for", "give", "has", "hasnt", "if", "in", "inversion", "jump",
51 "move", "new_line", "notin", "objectloop", "ofclass", "or",
52 "print", "print_ret", "provides", "quit", "read", "remove",
53 "restore", "return", "rfalse", "rtrue", "save", "spaces",
54 "string", "style bold", "style fixed", "style reverse",
55 "style roman", "style underline", "switch", "to", "until",
58 constants = ["false", "true"]
61 return "(" + "|".join(list) + r")\b"
63 class InformLexer(RegexLexer):
69 aliases = ['inform', 'inform6', 'i6']
71 mimetypes = ['text/x-inform', 'application/x-inform']
75 (r'"', String.Double, 'stringdouble'),
76 (r"'", String.Single, 'stringsingle'),
80 (r'!.*$', Comment.Single),
84 (r"[A-Za-z_,]+:", Name.Label),
85 (r"<.+?>", Name.Label),
87 (wordlist(objects), Name.Class),
88 (wordlist(keywords), Token.Keyword.Reserved),
89 (wordlist(properties), Name.Builtin),
90 (wordlist(directives), Name.Entity),
91 (wordlist(attributes), Name.Attribute),
92 (wordlist(constants), Name.Constant),
94 (wordlist(extension_properties), Name.Builtin),
96 (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name),
97 (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
98 (r'\d+', Number.Integer),
104 (r'"', String.Double, '#pop'),
105 (r'.', String.Double),
106 (r'\n', String.Double),
110 (r"'", String.Single, '#pop'),
111 (r'.', String.Single),