"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/langDefs/alan.lang" (12 May 2020, 12483 Bytes) of package /windows/www/highlight-3.57-x64.zip:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "alan.lang": 3.53_vs_3.54.

    1 --[[ "alan.lang" v2.0.1 (2018/09/18) | Alan 3.0beta6 | Highlight v3.44 | Lua 5.3
    2 ********************************************************************************
    3 *                                                                              *
    4 *                          ALAN IF Syntax Definition                           *
    5 *                                                                              *
    6 *                              by Tristano Ajmone                              *
    7 *                                                                              *
    8 ********************************************************************************
    9 Syntax definition for the Alan Interactive Fiction Language:
   10     https://www.alanif.se
   11 Created by Tristano Ajmone:
   12     <tajmone@gmail.com>
   13     https://github.com/tajmone
   14     https://gitlab.com/tajmone
   15 Released into the public domain according to the Unlicense terms:
   16     http://unlicense.org
   17 --------------------------------------------------------------------------------
   18 File extensions: "*.alan", "*.i"
   19 ------------------------------------------------------------------------------]]
   20 Description = "ALAN Interactive Fiction Language"
   21 
   22 Categories = {"source"}
   23 
   24 IgnoreCase = true --> Alan is not case-sensitive
   25 
   26 EnableIndentation = false
   27 
   28 --[[============================================================================
   29                                   IDENTIFIERS
   30 ================================================================================
   31 RegEx that defines keywords identifier's pattern — ie, which tokens are valid
   32 keyword candidates. Alan keywords are letters-only, but:
   33   (1) Kewyords must not be preceded by a single quote, otherwise it would be a
   34       quoted identifier (which can be named like a keyword, but isn't one).
   35   (2) Also capture '=>', '.', ',' and ':' as keywords (they are not operators).
   36 
   37 Quoted IDs Hack
   38 ===============
   39 We want the Identifiers RegEx to also capture Quoted Identifies, which then will
   40 not be matched by any actual Keywords list or RegEx, and therefore will be
   41 rendered as STANDARD text in the highlighted output.
   42 This hack is needed to avoid highlighting as keywords the contents of Quoted IDs.
   43 ------------------------------------------------------------------------------]]
   44 Identifiers = [=[ (?x)(
   45   # Quoted Identifiers:
   46   '.*?'(?!'')|
   47 
   48   # Special Kewyords:
   49   \=>|\.|,|:|
   50 
   51   # Alan Keywords:
   52   (?<!')\b[a-zA-Z]+\b
   53             ) ]=]
   54 --==============================================================================
   55 --                                  COMMENTS
   56 --==============================================================================
   57 -- Define SINGLE-LINE-COMMENTS delimiter:
   58 Comments = {
   59   { Block     = false,
   60     Nested    = false,
   61     Delimiter = { [=[ -- ]=] }
   62   }
   63 }
   64 --==============================================================================
   65 --                                 STRINGS
   66 --==============================================================================
   67 Strings = {
   68 --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   69 --                              STRING DELIMITERS
   70 --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   71   Delimiter = [=[ " ]=],
   72   AssertEqualLength = true,  -- Delimiters must have the same length?
   73 
   74 --[[~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   75                                 ESCAPE SEQUENCES
   76 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   77 Character combinations with special meaning for the printout:
   78   $p  => New paragraph (usually one empty line)
   79   $n  => New line
   80   $i  => Indent on a new line
   81   $t  => Insert a tabulation
   82   $$  => Do not insert a space
   83   $a  => The name of the actor that is executing
   84   $l  => The name of the current location
   85   $v  => The verb the player used (the first word)
   86   $   => Print a dollar sign
   87 ------------------------------------------------------------------------------]]
   88   Escape = [=[ [\$][pnitalv\$] ]=],
   89 
   90 --[[~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   91                                 INTERPOLATION
   92 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   93 These refer to parameters while executing a verb:
   94   $<n>   => The parameter <n> (<n> is a digit > 0, e.g. "$1")
   95   $+<n>  => Definite form of parameter <n>
   96   $0<n>  => Indefinite form of parameter <n>
   97   $-<n>  => Negative form of parameter <n>
   98   $!<n>  => Pronoun for the parameter <n>
   99   $o     => The current object (first parameter) *DEPRECATED*
  100 ------------------------------------------------------------------------------]]
  101   Interpolation = [=[ \$[+\-!0]?[1-9]|\$o ]=],
  102 }
  103 
  104 --[[============================================================================
  105                                   OPERATORS
  106 ================================================================================
  107 Arythmetic: '+', '-', '*', '/'
  108 Comparison: '=', '<', '>', '<=', '>=', '<>', '=='
  109 Other:
  110   (1) parameter indicators: '!', '*'
  111 --------------------------------------------------------------------------------
  112 NOTE: This RegEx is designed to avoid capturing '=>' as an operator, because we
  113       want to capture it as a keyword (shorthand for 'THEN'). Otherwise it could
  114       have been optimized to be much shorter.
  115 ------------------------------------------------------------------------------]]
  116 Operators = [=[ \+|\-|\*|\/|<|(?<!\=)>|<>|<\=|>\=|\=(?!>)|\=\=|\(|\)|\{|\}|! ]=]
  117 
  118 --[[============================================================================
  119                                     DIGITS
  120 ================================================================================
  121 Alan has only integer-type numerals.
  122 ------------------------------------------------------------------------------]]
  123 Digits = [=[ \b\d+\b ]=]
  124 
  125 --==============================================================================
  126 --                                   KEYWORDS
  127 --==============================================================================
  128 -- NOTE: All keywords must be in lowercase here, because of 'IgnoreCase = true'.
  129 Keywords = {
  130 --------------------------------------------------------------------------------
  131 --                              Alan Keywords List
  132 --------------------------------------------------------------------------------
  133   { Id = 1,
  134     List = {
  135       -- Keywords (124):
  136       "add", "after", "an", "and", "are", "article", "at", "attributes",
  137       "before", "between", "by", "can", "cancel", "character", "characters",
  138       "check", "container", "contains", "count", "current", "decrease",
  139       "definite", "depend", "depending", "describe", "description", "directly",
  140       "do", "does", "each", "else", "elsif", "empty", "end", "entered",
  141       "event", "every", "exclude", "exit", "extract", "first", "for", "form",
  142       "from", "has", "header", "here", "if", "import", "in", "include",
  143       "increase", "indefinite", "indirectly", "initialize", "into", "is",
  144       "isa", "it", "last", "limits", "list", "locate", "look", "make", "max",
  145       "mentioned", "message", "meta", "min", "name", "near", "nearby",
  146       "negative", "no", "not", "of", "off", "on", "only", "opaque", "option",
  147       "options", "or", "play", "prompt", "pronoun", "quit", "random",
  148       "restart", "restore", "save", "say", "schedule", "score", "script",
  149       "set", "show", "start", "step", "stop", "strip", "style", "sum",
  150       "synonyms", "syntax", "system", "taking", "the", "then", "this", "to",
  151       "transcript", "transitively", "until", "use", "verb", "visits", "wait",
  152       "when", "where", "with", "word", "words",
  153       -- Treat as keywords:
  154       "=>",          --> Shorthand for 'THEN'.
  155       ".", ",", ":"  --> These are never used as operators.
  156     }
  157   },
  158 --------------------------------------------------------------------------------
  159 --                           Predefined Alan Classes
  160 --------------------------------------------------------------------------------
  161 -- These are the seven predefined classes of the Alan language.
  162 --
  163 -- NOTE: Usually there is no need to syntax-highlight the predefined classes or
  164 --       the 'hero' instance (next keywords group) as there isn't anything
  165 --       special about them beside being hard-coded into the language.
  166 --       You can always style this group as normal text if you wish; I've
  167 --       created a dedicated keywords group for them in order to allow styling
  168 --       them if needed (for example, in documentation or tutorials it might be
  169 --       desirable to do so).
  170   { Id = 2,
  171     List = {
  172       "actor", "entity", "integer", "literal", "location", "object", "string", "thing",
  173     }
  174   },
  175 --------------------------------------------------------------------------------
  176 --                             Predefined Instances
  177 --------------------------------------------------------------------------------
  178 -- The 'hero' is a special predefined actor instance, used for the protagonist.
  179 -- (See NOTE above!)
  180   { Id = 3,
  181     List = {
  182       "hero"
  183     }
  184   }
  185 }
  186 
  187 --[[****************************************************************************
  188 *                                                                              *
  189 *                            CUSTOM HOOK-FUNCTIONS                             *
  190 *                                                                              *
  191 ********************************************************************************
  192 
  193 ================================================================================
  194 #01 -- Ignore Escape Sequences Outside Strings
  195 ================================================================================
  196 This function ensures that escape sequences outside strings are ignored: tokens
  197 matching an escape sequence are rejected if the previously parsed token was not
  198 a string, an interpolation or another escape sequence.
  199 Based on André Simon's reply to Issue #23:
  200     https://github.com/andre-simon/highlight/issues/23#issuecomment-332002639
  201 ------------------------------------------------------------------------------]]
  202 function OnStateChange(oldState, newState, token, kwgroup)
  203   if  newState == HL_ESC_SEQ and
  204       oldState ~= HL_STRING  and
  205       oldState ~= HL_ESC_SEQ and
  206       oldState ~= HL_INTERPOLATION then
  207         return HL_REJECT
  208   end
  209   return newState
  210 end
  211 
  212 --[[============================================================================
  213                                   CHANGELOG
  214 ================================================================================
  215 This syntax definition abides to Semantic Versioning 2.0.0:
  216     http://semver.org
  217 --------------------------------------------------------------------------------
  218 v2.0.1 (2018/09/18)
  219       - Add missing "integer" to the Predefined Alan classes.
  220 v2.0.0 (2018/09/11) | Alan 3.0beta6 | Highlight v3.44
  221     - BUG FIXES:
  222       - Add missing keywords "meta", "indirectly" and "transitively".
  223       - Add missing "literal" and "string" to the Predefined Alan classes.
  224         For more details, see discussion with Alan develepor Thomas Nilefalk at:
  225             https://github.com/alan-if/alan-docs/issues/15
  226             https://github.com/alan-if/alan-docs/issues/17
  227     - MAJOR CHANGES:
  228       - Add new Keywords group and move "hero" there. This new group is for
  229         "predefined instances", but its sole member is "hero", the predefined
  230         actor instance representing the player. In some contexts, like tutorials
  231         and documentation, it might be desirable to be able to syntax highlight
  232         this special instance; in all other cases it can just be styled as
  233         normal text (or non-styled) to visually hide it.
  234 v1.0.2 (2018/06/26) | Alan 3.0beta5 | Highlight v3.43)
  235     - BUG FIXES:
  236       - Now Quoted IDs are passed through as STANDARD text. Before, if Quoted IDs
  237         contained an Alan keyword or operators, etc., these would be highlighted
  238         as such. The new hack adds a pattern to Identifiers' RegEx that will
  239         match any Quoted ID, but since these will not match against any actual
  240         Keywords list or RegEx, the token will be consumed as STANDARD text and
  241         not processed further.
  242 v1.0.1 (2018/06/26 | Alan 3.0beta5 | Highlight v3.43)
  243     - BUG FIXES:
  244       - Escape Sequences after Interpolation (eg: "$1$p") were not captured.
  245 v1.0.0 (2018/06/16 | Alan 3.0beta5 | Highlight v3.43)
  246     - First release.
  247 --------------------------------------------------------------------------------
  248 --]]