File: alan.lang

package info (click to toggle)
highlight 4.10-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,556 kB
  • sloc: cpp: 27,579; makefile: 411; sh: 341; ansic: 264; php: 236; python: 217; ruby: 132; perl: 61; tcl: 1
file content (266 lines) | stat: -rw-r--r-- 13,087 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
--[[
"alan.lang"        v2.1.0 | 2021/08/21 | Alan 3.0beta8 | Highlight 4.1 | Lua 5.4
********************************************************************************
*                                                                              *
*                          ALAN IF Syntax Definition                           *
*                                                                              *
*                              by Tristano Ajmone                              *
*                                                                              *
********************************************************************************
Syntax definition for the Alan Interactive Fiction Language:
    https://www.alanif.se
Created by Tristano Ajmone:
    <tajmone@gmail.com>
    https://github.com/tajmone
    https://gitlab.com/tajmone
Released into the public domain according to the Unlicense terms:
    https://unlicense.org
--------------------------------------------------------------------------------
File extensions: "*.alan", "*.i"
------------------------------------------------------------------------------]]
Description = "ALAN Interactive Fiction Language"

Categories = {"source"}

IgnoreCase = true --> Alan is not case-sensitive

EnableIndentation = false

--[[============================================================================
                                  IDENTIFIERS
================================================================================
RegEx that defines keywords identifier's pattern — i.e. which tokens are valid
keyword candidates. Alan keywords are letters-only, but:
  (1) Keywords must not be preceded by a single quote, otherwise it would be a
      quoted identifier (which can be named like a keyword, but isn't one).
  (2) Also capture '=>', '.', ',' and ':' as keywords (they are not operators).

Quoted IDs Hack
===============
We want the Identifiers RegEx to also capture Quoted Identifies, which then will
not be matched by any actual Keywords list or RegEx, and therefore will be
rendered as STANDARD text in the highlighted output.
This hack is needed to avoid highlighting as keywords the contents of Quoted IDs.
------------------------------------------------------------------------------]]
Identifiers = [=[ (?x)(
  # Quoted Identifiers:
  '.*?'(?!'')|

  # Special Kewyords:
  \=>|\.|,|:|

  # Alan Keywords:
  (?<!')\b[a-zA-Z]+\b
            ) ]=]
--==============================================================================
--                                  COMMENTS
--==============================================================================
-- Define SINGLE-LINE-COMMENTS delimiter:
Comments = {
  -- Block comment doesn't work: never ends the block!
  { Block     = true,
    Nested    = false,
    Delimiter = {
      [=[ ^\/{4}.*$ ]=], -- //// followed by anything
      [=[ ^\/{4,}$  ]=]  -- //// followed optionally followed by more slashes
    }
  },
  { Block     = false,
    Nested    = false,
    Delimiter = { [=[ -- ]=] }
  }
}
--==============================================================================
--                                 STRINGS
--==============================================================================
Strings = {
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--                              STRING DELIMITERS
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Delimiter = [=[ " ]=],
  AssertEqualLength = true,  -- Delimiters must have the same length?

--[[~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                ESCAPE SEQUENCES
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Character combinations with special meaning for the printout:
  $p  => New paragraph (usually one empty line)
  $n  => New line
  $i  => Indent on a new line
  $t  => Insert a tabulation
  $$  => Do not insert a space
  $a  => The name of the actor that is executing
  $l  => The name of the current location
  $v  => The verb the player used (the first word)
  $   => Print a dollar sign
------------------------------------------------------------------------------]]
  Escape = [=[ [\$][pnitalv\$] ]=],

--[[~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                INTERPOLATION
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These refer to parameters while executing a verb:
  $<n>   => The parameter <n> (<n> is a digit > 0, e.g. "$1")
  $+<n>  => Definite form of parameter <n>
  $0<n>  => Indefinite form of parameter <n>
  $-<n>  => Negative form of parameter <n>
  $!<n>  => Pronoun for the parameter <n>
  $o     => The current object (first parameter) *DEPRECATED*
------------------------------------------------------------------------------]]
  Interpolation = [=[ \$[+\-!0]?[1-9]|\$o ]=],
}

--[[============================================================================
                                  OPERATORS
================================================================================
Arithmetic: '+', '-', '*', '/'
Comparison: '=', '<', '>', '<=', '>=', '<>', '=='
Other:
  (1) parameter indicators: '!', '*'
--------------------------------------------------------------------------------
NOTE: This RegEx is designed to avoid capturing '=>' as an operator, because we
      want to capture it as a keyword (shorthand for 'THEN'). Otherwise it could
      have been optimized to be much shorter.
------------------------------------------------------------------------------]]
Operators = [=[ \+|\-|\*|\/|<|(?<!\=)>|<>|<\=|>\=|\=(?!>)|\=\=|\(|\)|\{|\}|! ]=]

--[[============================================================================
                                    DIGITS
================================================================================
Alan has only integer-type numerals.
------------------------------------------------------------------------------]]
Digits = [=[ \b\d+\b ]=]

--==============================================================================
--                                   KEYWORDS
--==============================================================================
-- NOTE: All keywords must be in lowercase here, because of 'IgnoreCase = true'.
Keywords = {
--------------------------------------------------------------------------------
--                              Alan Keywords List
--------------------------------------------------------------------------------
  { Id = 1,
    List = {
      -- Keywords (124):
      "add", "after", "an", "and", "are", "article", "at", "attributes",
      "before", "between", "by", "can", "cancel", "character", "characters",
      "check", "container", "contains", "count", "current", "decrease",
      "definite", "depend", "depending", "describe", "description", "directly",
      "do", "does", "each", "else", "elsif", "empty", "end", "entered",
      "event", "every", "exclude", "exit", "extract", "first", "for", "form",
      "from", "has", "header", "here", "if", "import", "in", "include",
      "increase", "indefinite", "indirectly", "initialize", "into", "is",
      "isa", "it", "last", "limits", "list", "locate", "look", "make", "max",
      "mentioned", "message", "meta", "min", "name", "near", "nearby",
      "negative", "no", "not", "of", "off", "on", "only", "opaque", "option",
      "options", "or", "play", "prompt", "pronoun", "quit", "random",
      "restart", "restore", "save", "say", "schedule", "score", "script",
      "set", "show", "start", "step", "stop", "strip", "style", "sum",
      "synonyms", "syntax", "system", "taking", "the", "then", "this", "to",
      "transcript", "transitively", "until", "use", "verb", "visits", "wait",
      "when", "where", "with", "word", "words",
      -- Treat as keywords:
      "=>",          --> Shorthand for 'THEN'.
      ".", ",", ":"  --> These are never used as operators.
    }
  },
--------------------------------------------------------------------------------
--                           Predefined Alan Classes
--------------------------------------------------------------------------------
-- These are the seven predefined classes of the Alan language.
--
-- NOTE: Usually there is no need to syntax-highlight the predefined classes or
--       the 'hero' instance (next keywords group) as there isn't anything
--       special about them beside being hard-coded into the language.
--       You can always style this group as normal text if you wish; I've
--       created a dedicated keywords group for them in order to allow styling
--       them if needed (for example, in documentation or tutorials it might be
--       desirable to do so).
  { Id = 2,
    List = {
      "actor", "entity", "integer", "literal", "location", "object", "string", "thing",
    }
  },
--------------------------------------------------------------------------------
--                             Predefined Instances
--------------------------------------------------------------------------------
-- The 'hero' is a special predefined actor instance, used for the protagonist.
-- (See NOTE above!)
  { Id = 3,
    List = {
      "hero"
    }
  }
}

--[[****************************************************************************
*                                                                              *
*                            CUSTOM HOOK-FUNCTIONS                             *
*                                                                              *
********************************************************************************

================================================================================
#01 -- Ignore Escape Sequences Outside Strings
================================================================================
This function ensures that escape sequences outside strings are ignored: tokens
matching an escape sequence are rejected if the previously parsed token was not
a string, an interpolation or another escape sequence.
Based on André Simon's reply to Issue #23:
    https://github.com/andre-simon/highlight/issues/23#issuecomment-332002639

The `elseif` block is a hack to ensure that closing comment block delimiters are
properly captured.
------------------------------------------------------------------------------]]
function OnStateChange(oldState, newState, token, kwgroup)
  if  newState == HL_ESC_SEQ and
      oldState ~= HL_STRING  and
      oldState ~= HL_ESC_SEQ and
      oldState ~= HL_INTERPOLATION then
        return HL_REJECT
  elseif  newState == HL_BLOCK_COMMENT and
          oldState == HL_BLOCK_COMMENT then
        return HL_BLOCK_COMMENT_END

  end
  return newState
end

--[[============================================================================
                                  CHANGELOG
================================================================================
This syntax definition abides to Semantic Versioning 2.0.0:
    http://semver.org
--------------------------------------------------------------------------------
v2.1.0 (2021/08/21) | Alan 3.0beta8 | Highlight v4.1
      - Implement block comments (new with Alan3.0beta8).
v2.0.1 (2018/09/18)
      - Add missing "integer" to the Predefined Alan classes.
v2.0.0 (2018/09/11) | Alan 3.0beta6 | Highlight v3.44
    - BUG FIXES:
      - Add missing keywords "meta", "indirectly" and "transitively".
      - Add missing "literal" and "string" to the Predefined Alan classes.
        For more details, see discussion with Alan develepor Thomas Nilefalk at:
            https://github.com/alan-if/alan-docs/issues/15
            https://github.com/alan-if/alan-docs/issues/17
    - MAJOR CHANGES:
      - Add new Keywords group and move "hero" there. This new group is for
        "predefined instances", but its sole member is "hero", the predefined
        actor instance representing the player. In some contexts, like tutorials
        and documentation, it might be desirable to be able to syntax highlight
        this special instance; in all other cases it can just be styled as
        normal text (or non-styled) to visually hide it.
v1.0.2 (2018/06/26) | Alan 3.0beta5 | Highlight v3.43)
    - BUG FIXES:
      - Now Quoted IDs are passed through as STANDARD text. Before, if Quoted IDs
        contained an Alan keyword or operators, etc., these would be highlighted
        as such. The new hack adds a pattern to Identifiers' RegEx that will
        match any Quoted ID, but since these will not match against any actual
        Keywords list or RegEx, the token will be consumed as STANDARD text and
        not processed further.
v1.0.1 (2018/06/26 | Alan 3.0beta5 | Highlight v3.43)
    - BUG FIXES:
      - Escape Sequences after Interpolation (eg: "$1$p") were not captured.
v1.0.0 (2018/06/16 | Alan 3.0beta5 | Highlight v3.43)
    - First release.
--------------------------------------------------------------------------------
--]]