"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/langDefs/polygen.lang" (12 May 2020, 8434 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 "polygen.lang": 3.53_vs_3.54.

    1 --[[
    2 ********************************************************************************
    3 *                                                                              *
    4 *                       Polygen Grammars Syntax Definition                     *
    5 *                                                                              *
    6 *                 v1.0.1 (2018/01/18) | Highlight v3.41 | Lua 5.3              *
    7 *                                                                              *
    8 *                               by Tristano Ajmone                             *
    9 *                                                                              *
   10 ********************************************************************************
   11 Associated file extensions: ".grm"
   12 Syntax type: EBNF
   13 --------------------------------------------------------------------------------
   14 Polygen is a cross-platform command line tool for generating random sentences
   15 according to a grammar definition -- ie: following custom syntactical and
   16 lexical rules. It takes an Ascii text file ("*.grm") as source program defining
   17 a grammar by means of EBNF-like probabilistic rules and executes it. At each
   18 execution, the grammar will be run against different random seeds, therefore
   19 producing a different text output.
   20 
   21 The main goal of Polygen is to generate cursory nonsense for entertainment;
   22 or, in the words of its author, "a first effort towards satyre in computer
   23 science". Polygen was created by Alvise Spanò.
   24 
   25 Polygen Website and GitHub repository:
   26     http://www.polygen.org/
   27     https://github.com/alvisespano/Polygen
   28 
   29 Polygen grammars documentation (in Italian):
   30     http://www.polygen.org/it/manuale
   31 
   32 An outdated English translation (probably from an earlier version of Polygen,
   33 since it doesn't cover the full syntax) can be found at:
   34     http://lapo.it/polygen/polygen-1.0.6-20040705-doc.zip
   35 --------------------------------------------------------------------------------
   36 Written by Tristano Ajmone:
   37     <tajmone@gmail.com>
   38     https://github.com/tajmone
   39 Released into the public domain according to the Unlicense terms:
   40     http://unlicense.org/
   41 --------------------------------------------------------------------------------
   42 --]]
   43 Description="Polygen"
   44 
   45 Categories = {"source", "script"}
   46 
   47 IgnoreCase=false
   48 EnableIndentation=false
   49 ---------------------------------------------------------------------------------
   50 -- DISABLE/OVERRIDE UNUSED SYNTAX ELEMENTS
   51 ---------------------------------------------------------------------------------
   52 NEVER_MATCH_RE=[=[ \A(?!x)x ]=] -- A Never-Matching RegEx!
   53 
   54 Digits=NEVER_MATCH_RE -- Numbers are just text in Polygen!
   55 
   56 Identifiers=NEVER_MATCH_RE -- Highlight's default Identifiers RegEx prevents
   57 -- capturing the Epsilon operator ('_'). Since in this syntax, all identifiers
   58 -- are defined as RegEx Keywords, and because we don't use any Keywords lists,
   59 -- we may as well disable Identifiers by defining them as a never-matching RegEx.
   60 -- NOTE: Defining Identifiers as a never-matching RegEx prevents using Kewyords
   61 --       lists (the parser will fail to capture them).
   62 
   63 -- ==============================================================================
   64 --                                    COMMENTS
   65 -- ==============================================================================
   66 -- OCaml style comments, no nesting: (* ...COMMENT BLOCK... *)
   67 Comments={
   68   { Block=true,
   69     Nested=false,
   70     Delimiter = {
   71       [=[ \(\* ]=], -- Comment start: '(*'
   72       [=[ \*\) ]=]  -- Comment end:   '*)'
   73     }
   74   },
   75 }
   76 -- =============================================================================
   77 --                                    STRINGS
   78 -- =============================================================================
   79 Strings={
   80   ------------------------------------------------------------------------------
   81   --                             STRING DELIMITERS
   82   ------------------------------------------------------------------------------
   83   -- Polygen reckognises only double quotes as string delimiter: "...STRING..."
   84   Delimiter=[=[ " ]=],
   85 --[[----------------------------------------------------------------------------
   86                                   ESCAPE SEQUENCES
   87     ----------------------------------------------------------------------------
   88     Escape sequences can occur only inside strings -- here enforced via a custom
   89     OnStateChange() hook-function, further on. Valid escape sequences:
   90 
   91       \\    Backslash
   92       \"    Quote
   93       \n    New line
   94       \r    Carriage return
   95       \b    Backspace
   96       \t    Tab
   97       \nnn  ASCII decimal code (must always be three digits)                 --]]
   98   Escape=[=[ \\\d{3}|\\[nrbt\\"] ]=],
   99 }
  100 --[[============================================================================
  101                                     OPERATORS
  102     ============================================================================
  103     ::=   :=    :   ;   ^   .   ,   _   |   +   -   >   <   \
  104     >>  <<  (   )   [   ]   {   }
  105 
  106 --]]
  107 Operators=[=[ ::?=|\^|\.|:|\+|-|>|<|\(|\)|\[|]|\{|}|\||,|;|_|\\ ]=]
  108 -- =============================================================================
  109 --                                    KEYWORDS
  110 -- =============================================================================
  111 Keywords={
  112   -- KNOWN ISSUES: An unspaced non-terminal symbol definition will be parsed as
  113   -- as a label (eg: 'S::=` and 'X:=`, instead of 'S ::=` and 'X :=`) because of
  114   -- the colon; and a label with spaces before the colon will be parsed as a non-
  115   -- terminal symbol (eg: 'Label :' instead of 'Label:'). Since both usages are
  116   -- considered bad (albeit valid) styles in Polygen grammars (and indeed are
  117   -- rarely found in actual gramamrs), it's not worth implementing complex RegExs
  118   -- to capture such edge cases.
  119   ------------------------------------------------------------------------------
  120   --                            Non-Terminal Symbol
  121   ------------------------------------------------------------------------------
  122   { Id=1,
  123     Regex=[=[ (?<!\.)([A-Z][A-Za-z0-9]*)\b(?!:) ]=],
  124     Group=1
  125   },
  126   ------------------------------------------------------------------------------
  127   --                              Label Identifier
  128   ------------------------------------------------------------------------------
  129   -- Captures a label identifier at definition time:    LABEL: <..definition...>
  130   { Id=2,
  131     Regex=[=[ ([A-Za-z0-9]+)(?::) ]=],
  132     Group=1
  133   },
  134   ------------------------------------------------------------------------------
  135   --                               Label Selector
  136   ------------------------------------------------------------------------------
  137   -- Either a dot followed by a single Label or by a group of labels within round
  138   -- brackets:    .LABEL    .(LABEL1|LABEL2)    .(++LABEL1|-LABEL2)
  139   -- The dot selector is excluded from the match; the whole bracketed group will
  140   -- be treated as a single keyword (as in PolyGUI tool).
  141   { Id=3,
  142     Regex=[=[ (?:\.)(\(.*?\)|[A-Za-z0-9]+) ]=],
  143     Group=1
  144   },
  145 }
  146 -- *****************************************************************************
  147 -- *                                                                           *
  148 -- *                          CUSTOM HOOK-FUNCTIONS                            *
  149 -- *                                                                           *
  150 -- *****************************************************************************
  151 
  152 -- =============================================================================
  153 --                     Escape Sequences Only Inside String
  154 -- =============================================================================
  155 function OnStateChange(oldState, newState, token, kwgroup)
  156 --  This function ensures that escape sequences outside strings are ignored.
  157 --  Based on André Simon's reply to Issue #23:
  158 --  https://github.com/andre-simon/highlight/issues/23#issuecomment-332002639
  159   if newState==HL_ESC_SEQ and oldState~=HL_STRING  then
  160     return HL_STANDARD
  161   end
  162   return newState
  163 end
  164 --[[============================================================================
  165                                     CHANGELOG
  166 ================================================================================
  167 v1.0.1 (2018/01/18) | Highlight v3.41)
  168   - Changed "PolyGen" to "Polygen" (the author has now officially adopted the
  169     latter syntax).
  170 v1.0.0 (2018/01/04) | Highlight v3.41)
  171   - First release.
  172 --]]