From 7149f9762ee9b58ce18f377e65d3ee9c5098c69b Mon Sep 17 00:00:00 2001 From: Glenn Hutchings Date: Sun, 3 Apr 2016 14:36:51 +0100 Subject: [PATCH] Use builtin inform syntax highlighting Turns out pygments already has builtin support for inform6, which is way better than what I cobbled together. --- about.rst | 2 +- chapters/02.rst | 5 +-- chapters/03.rst | 38 ++++++++++---------- conf.py | 2 -- tools/inform.py | 94 ------------------------------------------------- 5 files changed, 23 insertions(+), 118 deletions(-) delete mode 100644 tools/inform.py diff --git a/about.rst b/about.rst index 84c4437..7ba7ee0 100644 --- a/about.rst +++ b/about.rst @@ -2,7 +2,7 @@ About this guide ================== -.. highlight:: inform +.. highlight:: inform6 .. epigraph:: diff --git a/chapters/02.rst b/chapters/02.rst index 4698aee..933abae 100644 --- a/chapters/02.rst +++ b/chapters/02.rst @@ -27,7 +27,7 @@ in which you initially write the game doesn't bear much resemblance to the text which the interpreter ultimately displays. For example, the "William Tell" game, in the form that we wrote it, starts like this: -.. code-block:: inform +.. code-block:: inform6 !============================================================================ Constant Story "William Tell"; @@ -43,7 +43,8 @@ Tell" game, in the form that we wrote it, starts like this: Class Room has light; - ... + + ! ... You will never need to look at it in the form produced by the compiler:: diff --git a/chapters/03.rst b/chapters/03.rst index d9a1800..040aa8e 100644 --- a/chapters/03.rst +++ b/chapters/03.rst @@ -41,7 +41,7 @@ that we design will start out like this. Follow these steps: #. In that folder, use your text editor to create this source file ``Heidi.inf``: - .. code-block:: inform + .. code-block:: inform6 !% -SD !============================================================================ @@ -191,7 +191,7 @@ looking at the source file. character. On this line, the first ``!`` is part of the sequence (or string) of characters to be displayed: - .. code-block:: inform + .. code-block:: inform6 print "Hello world!"; ! <- is the start of this comment @@ -199,7 +199,7 @@ looking at the source file. space (except when the spaces are part of a character string). So, these two rules tell us that we *could* have typed the source file like this: - .. code-block:: inform + .. code-block:: inform6 Constant Story "Heidi"; Constant Headline @@ -222,7 +222,7 @@ looking at the source file. * Every game needs the three lines which ``Include`` the standard library files -- that is, they merge those files' contents into your source file: - .. code-block:: inform + .. code-block:: inform6 Include "Parser"; Include "VerbLib"; @@ -235,7 +235,7 @@ looking at the source file. * Every game needs to define an ``Initialise`` routine (note the British spelling): - .. code-block:: inform + .. code-block:: inform6 [ Initialise; ]; @@ -250,7 +250,7 @@ looking at the source file. that's why we were able to take three lines to define the ``Headline`` constant - .. code-block:: inform + .. code-block:: inform6 Constant Headline "^A simple Inform example @@ -278,7 +278,7 @@ In IF, we talk about each of these locations as a **room**, even though in this example none of them has four walls. So let's use Inform to define those rooms. Here's a first attempt: -.. code-block:: inform +.. code-block:: inform6 Object "In front of a cottage" with description @@ -372,7 +372,7 @@ clearing. Now, although our descriptions mention or imply these available routes, we also need to explicitly add them to the room definitions in a form that the game itself can make sense of. Like this: -.. code-block:: inform +.. code-block:: inform6 Object before_cottage "In front of a cottage" with description @@ -462,7 +462,7 @@ At this stage, you should study the four room definitions, comparing them with the sketch map until you're comfortable that you understand how to create simple rooms and define the connections between them. -.. code-block:: inform +.. code-block:: inform6 !============================================================================ Constant Story "Heidi"; @@ -535,7 +535,7 @@ Given what we said earlier, you won't be surprised to hear that both the bird and its nest are Inform objects. We'll start their definitions like this: -.. code-block:: inform +.. code-block:: inform6 Object bird "baby bird" with description "Too young to fly, the nestling tweets helplessly.", @@ -563,7 +563,7 @@ relevant vocabulary so that the player can use whatever term seems appropriate to her, with a good chance of it being understood. We add a line to each definition: -.. code-block:: inform +.. code-block:: inform6 Object bird "baby bird" with description "Too young to fly, the nestling tweets helplessly.", @@ -614,7 +614,7 @@ that the player can type PUT (or INSERT) BIRD IN (or INTO) NEST. Furthermore, we label it as ``open``; this prevents the interpreter from asking us to open it before putting in the bird. -.. code-block:: inform +.. code-block:: inform6 Object nest "bird's nest" with description "The nest is carefully woven of twigs and moss.", @@ -626,7 +626,7 @@ To do this, we need to choose the locations where the player will find them. Let's say that the bird is found in the forest, while the nest is in the clearing. This is how we set this up: -.. code-block:: inform +.. code-block:: inform6 Object bird "baby bird" forest with description "Too young to fly, the nestling tweets helplessly.", @@ -648,7 +648,7 @@ but you'll find it convenient to insert them following the rooms where they're found. This means adding the bird just after the forest, and the nest just after the clearing. Here's the middle piece of the source file: -.. code-block:: inform +.. code-block:: inform6 !============================================================================ ! The game objects @@ -710,7 +710,7 @@ Adding the tree and the branch The description of the clearing mentions a tall sycamore tree, up which the player character supposedly "climbs". We'd better define it: -.. code-block:: inform +.. code-block:: inform6 Object tree "tall sycamore tree" clearing with description @@ -727,7 +727,7 @@ labelling the tree as ``scenery`` we suppress that, and also prevent it from being picked up by the player character. One final object: the branch at the top of the tree. Again, not many surprises in this definition: -.. code-block:: inform +.. code-block:: inform6 Object branch "wide firm bough" top_of_tree with description "It's flat enough to support a small object.", @@ -743,7 +743,7 @@ objects *onto* the branch. (In passing, we'll mention that an object can't normally be both a ``container`` and a ``supporter``.) And so here are our objects again: -.. code-block:: inform +.. code-block:: inform6 !============================================================================ ! The game objects @@ -811,7 +811,7 @@ carrying the bird and the nest separately: we want the player character to put the bird into the nest first. One easy way to enforce this is by adding a line near the top of the file: -.. code-block:: inform +.. code-block:: inform6 !============================================================================ Constant Story "Heidi"; @@ -833,7 +833,7 @@ to put the bird in the nest, take the nest to the top of the tree, and place it on the branch; when that happens, the game should be over. This is one way of making it happen: -.. code-block:: inform +.. code-block:: inform6 Object branch "wide firm bough" top_of_tree with description "It's flat enough to support a small object.", diff --git a/conf.py b/conf.py index 6d84b88..58e5793 100644 --- a/conf.py +++ b/conf.py @@ -21,12 +21,10 @@ import shlex # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath('tools')) -from inform import InformLexer from transcript import TranscriptLexer # Setup function. def setup(app): - app.add_lexer('inform', InformLexer()) app.add_lexer('transcript', TranscriptLexer()) # -- General configuration ------------------------------------------------ diff --git a/tools/inform.py b/tools/inform.py deleted file mode 100644 index 63d098b..0000000 --- a/tools/inform.py +++ /dev/null @@ -1,94 +0,0 @@ -""" -Inform syntax highlighting. - -TODO: get it working! -""" - -from pygments.lexer import RegexLexer -from pygments.token import (Text, Comment, Operator, Keyword, Name, - String, Number, Punctuation, Token) - -objects = ["Class", "Nearby", "Object"] - -directives = ["Abbreviate", "Array", "Attribute", "Btrace", "Class", - "Constant", "Default", "Dictionary", "End", "Endif", "Etrace", - "Extend", "Fake_action", "Global", "Ifdef", "Iffalse", - "Ifndef", "Ifnot", "Iftrue", "Ifv3", "Ifv5", "Import", - "Include", "Link", "Listsymbols", "Listdict", "Listverbs", - "Lowstring", "Ltrace", "Message", "Nearby", "Nobtrace", - "Noetrace", "Noltrace", "Notrace", "Object", "Property", - "Release", "Replace", "Serial", "Statusline", "Stub", - "Switches", "System_file", "Trace", "Verb", "Version", - "Zcharacter"] - -defining = ["[", "array", "attribute", "class", "constant", "fake_action", - "global", "lowstring", "nearby", "object", "property"] - -attributes = ["absent", "animate", "clothing", "concealed", "container", - "door", "edible", "enterable", "female", "general", "light", - "lockable", "locked", "male", "moved", "neuter", "on", "open", - "openable", "pluralname", "proper", "scenery", "scored", - "static", "supporter", "switchable", "talkable", "transparent", - "visited", "workflag", "worn"] - -properties = ["n_to", "s_to", "e_to", "w_to", "ne_to", "se_to", "nw_to", - "sw_to", "u_to", "d_to", "in_to", "out_to", "add_to_scope", - "after", "article", "articles", "before", "cant_go", "capacity", - "daemon", "describe", "description", "door_dir", "door_to", - "each_turn", "found_in", "grammar", "initial", - "inside_description", "invent", "life", "list_together", - "name", "number", "orders", "parse_name", "plural", - "react_after", "react_before", "short_name", "short_name_indef", - "time_left", "time_out", "when_closed", "when_open", "when_on", - "when_off", "with_key"] - -keywords = ["box", "break", "continue", "do", "else", "font off", "font on", - "for", "give", "has", "hasnt", "if", "in", "inversion", "jump", - "move", "new_line", "notin", "objectloop", "ofclass", "or", - "print", "print_ret", "provides", "quit", "read", "remove", - "restore", "return", "rfalse", "rtrue", "save", "spaces", - "string", "style bold", "style fixed", "style reverse", - "style roman", "style underline", "switch", "to", "until", - "while"] - -action_re = r"\s-*\*" - -def wordlist(list): - return "(" + "|".join(list) + r")\b" - -class InformLexer(RegexLexer): - """ - Inform code lexer. - """ - - name = 'Inform' - aliases = ['inform'] - filenames = ['*.inf'] - mimetypes = ['text/x-inform', 'application/x-inform'] - - tokens = { - 'root': [ - (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), - - (wordlist(objects), Name.Class), - (wordlist(keywords), Token.Keyword.Reserved), - (wordlist(properties), Name.Builtin), - (wordlist(directives), Name.Entity), - (wordlist(attributes), Name.Attribute), - - (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name), - (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), - (r'\d+', Number.Integer), - - (r'.', Punctuation), - ], - } -- 2.31.1