Add glossary references in the correct places.
[ibg.git] / tools / inform.py
index 63d098b790eedc43b6d6b85dbb07b8de82510882..94b4b03b4dd566ba5040e315c159c0b2907016d7 100644 (file)
@@ -1,7 +1,9 @@
 """
 """
-Inform syntax highlighting.
+Inform syntax highlighting.
 
 
-TODO: get it working!
+This is an ultra-minimal version compared to the standard Pygments Inform6
+lexer, but is much more forgiving of syntax errors.  And it handles the
+exclamation-inside-string case properly.
 """
 
 from pygments.lexer import RegexLexer
 """
 
 from pygments.lexer import RegexLexer
@@ -49,9 +51,9 @@ keywords = ["box", "break", "continue", "do", "else", "font off", "font on",
             "restore", "return", "rfalse", "rtrue", "save", "spaces",
             "string", "style bold", "style fixed", "style reverse",
             "style roman", "style underline", "switch", "to", "until",
             "restore", "return", "rfalse", "rtrue", "save", "spaces",
             "string", "style bold", "style fixed", "style reverse",
             "style roman", "style underline", "switch", "to", "until",
-            "while"]
+            "while", "with"]
 
 
-action_re = r"\s-*\*"
+constants = ["false", "true"]
 
 def wordlist(list):
     return "(" + "|".join(list) + r")\b"
 
 def wordlist(list):
     return "(" + "|".join(list) + r")\b"
@@ -61,29 +63,31 @@ class InformLexer(RegexLexer):
     Inform code lexer.
     """
 
     Inform code lexer.
     """
 
-    name = 'Inform'
-    aliases = ['inform']
+    name = 'Inform 6'
+    aliases = ['inform', 'inform6', 'i6']
     filenames = ['*.inf']
     mimetypes = ['text/x-inform', 'application/x-inform']
 
     tokens = {
         'root': [
     filenames = ['*.inf']
     mimetypes = ['text/x-inform', 'application/x-inform']
 
     tokens = {
         'root': [
+            (r'"', String.Double, 'stringdouble'),
+            (r"'", String.Single, 'stringsingle'),
+
             (r'\n', Text),
             (r'[^\S\n]+', Text),
             (r'!.*$', Comment.Single),
             (r'\\\n', Text),
             (r'\\', Text),
             (r'=', Operator),
             (r'\n', Text),
             (r'[^\S\n]+', Text),
             (r'!.*$', Comment.Single),
             (r'\\\n', Text),
             (r'\\', Text),
             (r'=', Operator),
-            (r'"[^"]*"', String.Double),
-            (r"'[^']*'", String.Single),
-            (r"\S+:", Name.Label),
-            (r"<<.+>>", Name.Label),
+            (r"[A-Za-z_,]+:", Name.Label),
+            (r"<<\S+>>", Name.Label),
 
             (wordlist(objects), Name.Class),
             (wordlist(keywords), Token.Keyword.Reserved),
             (wordlist(properties), Name.Builtin),
             (wordlist(directives), Name.Entity),
             (wordlist(attributes), Name.Attribute),
 
             (wordlist(objects), Name.Class),
             (wordlist(keywords), Token.Keyword.Reserved),
             (wordlist(properties), Name.Builtin),
             (wordlist(directives), Name.Entity),
             (wordlist(attributes), Name.Attribute),
+            (wordlist(constants), Name.Constant),
 
             (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name),
             (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
 
             (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name),
             (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
@@ -91,4 +95,15 @@ class InformLexer(RegexLexer):
 
             (r'.', Punctuation),
         ],
 
             (r'.', Punctuation),
         ],
+
+        'stringdouble': [
+            (r'"', String.Double, '#pop'),
+            (r'.', String.Double),
+            (r'\n', String.Double),
+        ],
+
+        'stringsingle': [
+            (r"'", String.Single, '#pop'),
+            (r'.', String.Single),
+        ],
     }
     }