Commits

Philipp Gesang  committed 0e37871

moved terminals out of parsers

  • Participants
  • Parent commits 924ae3c

Comments (0)

Files changed (2)

File formatters/acceptor_f-mediawiki.lua

 formatter.paragraph = function (text)
   text = pre_escape(text)
   text = auxtrim(text)
-  text = auxgsub(text) -- defaults to unnewline
+  text = auxgsub(text)
   docmain[#docmain+1] = lpegmatch(parsers.p_wiki_inline, text, 1, "paragraph")
 end
 

File parsers/acceptor_p-mediawiki.lua

   balanced         = V"balanced_brace" + V"balanced_bracket",
 }
 
+------------------------------------------------------------------------
+--  Fundamentals: Low-Level Rules and Terminals
+------------------------------------------------------------------------
+local newline               = P"\r\n" + P"\n\r" + P"\n" + P"\r"
+local eof                   = P(-1)
+local bol                   = newline
+local eol                   = newline + eof
+local tab                   = S"\t\v"
+                            
+local space                 = P" "
+local spaces                = space^1
+local space_tab             = space + tab
+local space_tabs            = space_tab^1
+local whitespace_char       = space_tab + newline
+local whitespace_rest       = space_tab^0 * newline
+                            
+local whitespace            = eof + whitespace_char^1 * eof^-1
+local newlines              = newline^1
+                            
+local decimal_digit         = R"09"
+local decimal_number        = decimal_digit^1
+local hex_digit             = decimal_digit + R"AF" + R"af"
+local hex_number            = hex_digit^1
+                            
+local asterisk              = P"*"
+local colon                 = P":"
+local dot                   = P"."
+local double_quote          = P[["]]
+local equals                = P"="
+local gartenzaun            = P"#"
+local html_unsafe_symbol    = P"<" + P">" + P"&"
+local semicolon             = P";"
+local triple_dot            = dot * dot * dot
+local underscore            = P"_"
+local percent               = P"%"
+
+local bar                   = P"|"
+local nobar                 = 1 - bar
+local nodoublebar           = 1 - bar * bar
+                            
+local dash                  = P"-"
+local exclam                = P"!"
+local double_exclam         = exclam * exclam
+
+local ucase_letter          = R"AZ"
+local lcase_letter          = R"az"
+local letter                = ucase_letter + lcase_letter
+local symbol                = html_unsafe_symbol
+                            + underscore
+                            + S",."
+local non_whitespace_char   = letter + decimal_digit + symbol
+                            
+local html_entity_char      = ucase_letter + lcase_letter + decimal_digit
+local html_entity_chars     = html_entity_char^1
+local html_entity           = (P"&"   * html_entity_chars * P";")
+                            + (P"&#"  * decimal_number    * P";")
+                            + (P"&#x" * hex_number        * P";")
+                            
+local character             = whitespace_char + non_whitespace_char + html_entity
+local characters            = character^1 -- not in the spec but referred to everywhere
+                            
+local lbrack                = P"["
+local rbrack                = P"]"
+local double_lbrack         = lbrack * lbrack
+local double_rbrack         = rbrack * rbrack
+local balanced_double_brack = P{
+  "balanced",
+  _balanced = (V"balanced" + (1 - double_rbrack))^1,
+  balanced  = double_lbrack * V"_balanced"^-1 * double_rbrack,
+}
+
+local lbrace                = P"{"
+local rbrace                = P"}"
+local double_lbrace         = lbrace * lbrace
+local double_rbrace         = rbrace * rbrace
+local balanced_double_brace = P{
+  "balanced",
+  _balanced = (V"balanced" + (1 - double_rbrace))^1,
+  balanced  = double_lbrace * V"_balanced"^-1 * double_rbrace,
+}
+
+                            
+--- No comment: „Harmless-characters mean characters that couldn't be anything
+---              else.“
+---              <http://www.mediawiki.org/wiki/Markup_spec/BNF/Inline_text#Text>
+--- Let’s give it a shot ...
+local  harmless_character   = letter + decimal_digit
+local word_char             = ucase_letter + lcase_letter + decimal_digit
+local non_word_char         = 1 - word_char
+                            
+  -- from this regex: " %!\"$&'()*,\\_.\\/0_9:;=?@A_Z\\\\^_`a_z~\\x80_\\xFF+"
+local title_legal_chars     = S[[ %!"$&'()*,_./:;=?@\~+-]]
+                            + word_char
+                            + R"^`"
+                            + R"\128\255"
+                            + newline -- really, try it out on mediawiki!
+                            + P"\28" -- ‽
+local bad_title_characters  = S"[]{}<>_|#"
+local title_character       = utf8char - bad_title_characters
+local page_name             = title_character^1
+                            
+local goodies               = Cs(triple_dot / "\\dots ")
+                            + Cs(underscore / "\\letterunderscore ")
+                            
+local url, CSS_parameter_list, permitted_HTML_tags
+do
+  local CSS_parameter_pair    = C(harmless_character^1) / stringlower
+                              * space_tab^0
+                              * equals
+                              * space_tab^0
+                              * (double_quote * C((1 - double_quote - newline)^1) * double_quote
+                              + C((harmless_character + underscore)^1))
+  local CSS_parameter__list   = (space_tab^0 * Cg(CSS_parameter_pair))^0
+  CSS_parameter_list          = Cf(Ct"" * CSS_parameter__list, rawset) * space_tab^0
+
+    --protocol                = ALLOWED_PROTOCOL_FROM_CONFIG (e.g. "http://", "mailto:")
+  local protocol              = P"http://" -- what else?
+                              + P"mailto:"
+                              + P"ftp://"
+  local escaped_url_char      = percent * hex_digit * hex_digit
+  local url_char              = word_char
+                              + S"!*'();:@&=+$,/?#[]-_.~"
+                              + escaped_url_char
+  local url_path              = url_char^1
+    --url_char                = LEGAL_URL_ENTITY
+  url                         = protocol * url_path
+
+  local permitted_HTML_tags   = P"var"    + P"ul"      + P"u"      + P"tt"
+                              + P"tr"     + P"th"      + P"td"     + P"table"
+                              + P"sup"    + P"sub"     + P"strong" + P"strike"
+                              + P"span"   + P"small"   + P"samp"   + P"s"      
+                              + P"ruby"   + P"rt"      + P"rp"     + P"rb"
+                              + P"pre"    + P"p"       + P"ol"     + P"li"
+                              + P"kbd"    + P"ins"     + P"i"      + P"hr"
+                              + P"h6"     + P"h5"      + P"h4"     + P"h3"
+                              + P"h2"     + P"h1"      + P"font"   + P"em"
+                              + P"dt"     + P"dl"      + P"div"    + P"dfn"
+                              + P"del"    + P"dd"      + P"code"   + P"cite"
+                              + P"center" + P"caption" + P"br"     + P"blockquote"
+                              + P"big"    + P"b"       + P"abbr"   
+  local other_known_HTML_tags = P"source" + P"math" + P"bold"
+  permitted_HTML_tag          = other_known_HTML_tags + permitted_HTML_tags
+end
+
+local table_start_marker    = P"{|"
+local table_stop_marker     = P"|}"
+local table_caption_marker  = P"|+"
+local table_newrow_marker   = P"|-"
+
+local list_item_marker      = colon + gartenzaun + asterisk
+
+--category_namespace = NS_CATEGORY
+--category_namespace = R("az", "AZ")^1,
+--- http://en.wikipedia.org/wiki/Help:Category
+--- TODO: What about other wikis??
+category_namespace          = P"Main"            + P"Talk"
+                            + P"User talk"       + P"User"
+                            + P"Wikipedia talk"  + P"Wikipedia"
+                            + P"File talk"       + P"File"
+                            + P"MediaWiki talk"  + P"MediaWiki"
+                            + P"Template talk"   + P"Template"
+                            + P"Help talk"       + P"Help"
+                            + P"Category talk"   + P"Category"
+                            + P"Portal talk"     + P"Portal"
+                            + P"Book talk"       + P"Book"
+
+
+--======================================================================
+--  Inline Text
+--======================================================================
 parsers.p_wiki_inline = P{
   "inline_text",
-  ------------------------------------------------------------------------
-  --  Inline Text
-  ------------------------------------------------------------------------
   inline_text          = Ct((V"innocent_text" + V"inline_element")^1),
-  innocent_text        = Cs((V"goodies" + 1 - V"inline_element")^1),
+  innocent_text        = Cs((goodies + 1 - V"inline_element")^1),
   ["ignore!"]          = V"template",
-  template             = V"double_lbrace"
-                       * C(V"balanced_double_brace")
-                       --* C((1 - V"double_rbrace")^0)
-                       / formatter.comment
-                       * V"double_rbrace"
+  template             = double_lbrace
+                       * C((balanced_double_brace + 1 - double_rbrace)^0) / formatter.comment
+                       * double_rbrace
                        ,
-  balanced_double_brace = (V"inner_double_brace" + 1 - V"double_rbrace")^0,
-  inner_double_brace    = V"double_lbrace"
-                        * V"balanced_double_brace"
-                        * V"double_rbrace"
-                        ,
   inline_element       = V"ignore!"
                        + V"HTML_comment"
                        + V"reference"
                        + V"close_guillemet"
                        + V"nbsp_before" -- those were unreferenced in the BNF
                        + V"nbsp_after"
-                       + V"html_entity"
-                       + V"html_unsafe_symbol"
+                       + html_entity
+                       + html_unsafe_symbol
                        --+ V"text"
                        --+ V"random_character"
                        ,
-  text                 = (V"plain_text" - V"newline")
+  text                 = (V"plain_text" - newline)
                        --+ V"wiki_markup_characters"
                        ,
   plain_text           = P"<nowiki>" * S[[|[]<>{}]]^0 * P"</nowiki>"
-                       + V"unicode_wiki" * V"space"^0 * S[["*#:;]]
-                       + V"unicode_wiki" * V"space"^-1 * P"=" * V"space"^-1 * V"unicode_wiki"
+                       + V"unicode_wiki" * space^0 * S[["*#:;]]
+                       + V"unicode_wiki" * space^-1 * P"=" * space^-1 * V"unicode_wiki"
                        + V"unicode_wiki" * V"no_format_apostrophe"
                        + P" '" * V"unicode_wiki"
                        + V"unicode_wiki"
                                 end)
                          ,
 
-  --- No comment: „Harmless-characters mean characters that couldn't be anything
-  ---              else.“
-  ---              <http://www.mediawiki.org/wiki/Markup_spec/BNF/Inline_text#Text>
-  --- Let’s give it a shot ...
-  harmless_character   = R("az", "AZ", "09"),
   --- Brrrr: “A "random character" is any character which hasn't matched
   ---         anything else.”
   random_character     = utf8char,
                    ,
   empty_reference  = P"<"
                    * V"reference_tag"
-                   * Cg(V"CSS_parameter_list", "parameters")^-1
+                   * Cg(CSS_parameter_list, "parameters")^-1
                    * P"/>"
                    ,
   normal_reference = V"reference_start"
                    * V"reference_body"
                    * V"reference_stop"
                    ,
-  reference_start  = P"<"   * V"reference_tag" * Cg(V"CSS_parameter_list", "parameters")^-1 * P">",
+  reference_start  = P"<"   * V"reference_tag" * Cg(CSS_parameter_list, "parameters")^-1 * P">",
   reference_stop   = P"</"  * V"reference_tag" * P">",
   reference_tag    = P"ref" + P"reference",
   reference_body   = Cg((1 - V"reference_stop")^0, "content")
                          --+ V"HTML_comment"
                          ,
   permitted_HTML_empty   = P"<"
-                         * C(V"permitted_HTML_tag")
-                         * C(V"CSS_parameter_list")^-1
-                         * V"space_tab"^0
+                         * C(permitted_HTML_tag)
+                         * C(CSS_parameter_list)^-1
+                         * space_tab^0
                          * P"/>" 
                          / formatter.inline_html_empty
                          ,
                          / formatter.inline_html
                          ,
   permitted_HTML_open    = P"<"
-                         * Cg(V"permitted_HTML_tag", "current_tag")
-                         * Cg(V"CSS_parameter_list", "parameters")^-1 
+                         * Cg(permitted_HTML_tag, "current_tag")
+                         * Cg(CSS_parameter_list, "parameters")^-1 
                          * P">"
                          ,
   permitted_HTML_close   = P"</"
-                         * Cmt(C(V"permitted_HTML_tag")
+                         * Cmt(C(permitted_HTML_tag)
                              * Cb("current_tag"), function (s, i, this, that)
                                                     return this == that
                                                   end)
-                         --* V"space_tab"^0
+                         --* space_tab^0
                          * P">"
                          ,
   permitted_HTML_body    = Cg((1 - V"permitted_HTML_close")^0, "content"),
-  permitted_HTML_tag     = V"other_known_HTML_tags"
-                         + V"permitted_HTML_tags"
-                         ,
-  other_known_HTML_tags  = P"source" + P"math" + P"bold",
-  --- TODO: reorder to avoid ambiguities
-  permitted_HTML_tags    = P"abbr"   + P"br"      + P"big"    + P"blockquote"
-                         + P"b"      + P"caption" + P"center" + P"cite"
-                         + P"code"   + P"dd"      + P"del"    + P"dfn"
-                         + P"div"    + P"dl"      + P"dt"     + P"em"
-                         + P"font"   + P"h1"      + P"h2"     + P"h3"
-                         + P"h4"     + P"h5"      + P"h6"     + P"hr"
-                         + P"i"      + P"ins"     + P"kbd"    + P"li"
-                         + P"ol"     + P"p"       + P"pre"    + P"rb"
-                         + P"rp"     + P"rt"      + P"ruby"   + P"sup"
-                         + P"samp"   + P"small"   + P"span"   + P"strike"
-                         + P"strong" + P"sub"     + P"s"      + P"table"
-                         + P"td"     + P"th"      + P"tr"     + P"tt"
-                         + P"u"      + P"ul"      + P"var"
-                         ,
-  --extra_characters       = V"word_boundary_char" * (V"character" - P">")^0,
+  --extra_characters       = V"word_boundary_char" * (character - P">")^0,
   extra_characters       = V"word_boundary_char" * (1 - P">")^0,
   word_boundary_char     = S[[ -:"/*#!$%]],
   --- Enforced Non-Breaking Spaces
-  nbsp_before            = V"character"
-                         * V"space"
+  nbsp_before            = character
+                         * space
                          * (P"&raquo;" + S"?:;!%")
                          ,
-  nbsp_after             = P"&laquo;" * V"space",
+  nbsp_after             = P"&laquo;" * space,
   --- Behavior Switches
   behaviour_switch              = V"behaviourswitch_toc" 
                                 + V"behaviourswitch_forcetoc"
                             * Cg(Carg(1), "environment"))
                          / formatter.image_inline
                          ,
-  image_prefix           = (P"Image" + P"File") * V"colon",
-  image_start            = V"double_lbr" * V"image_prefix",
-  image_stop             = V"double_rbr",
-  image_elms             = Cf(Ct"" * (V"bar" * V"image_option")^0, rawset),
-  image_name             = Cg((V"title_character"
-                             - V"image_suffix" * (V"bar" + V"rbr"))^1
+  image_prefix           = (P"Image" + P"File") * colon,
+  image_start            = double_lbrack * V"image_prefix",
+  image_stop             = double_rbrack,
+  image_elms             = Cf(Ct"" * (bar * V"image_option")^0, rawset),
+  image_name             = Cg((title_character
+                             - V"image_suffix" * (bar + rbrack))^1
                             * V"image_suffix",
                             "name"),
-  image_suffix           = V"dot" * V"image_extension",
+  image_suffix           = dot * V"image_extension",
   image_extension        = P"jpg" + P"jpeg" + P"png"
                          + P"svg" + P"gif"  + P"bmp"
                          + P"JPG" + P"JPEG" + P"PNG"
   img_thumbnail          = P"thumbnail" + P"thumb",
   img_frame              = P"framed" + P"enframed" + P"frame",
   img_frameless          = P"frameless",
-  image_size_parameter   = V"decimal_digit"^1 * P"px",
+  image_size_parameter   = decimal_digit^1 * P"px",
   image_align_parameter  = P"left" + P"center" + P"centre" + P"right" + P"none",
   image_valign_parameter = P"baseline" + P"sub"    + P"super"
                          + P"sup"      + P"top"    + P"text-top"
                          + P"middle"   + P"bottom" + P"text-bottom"
                          ,
   
-  caption                = V"balanced_double_br"^1,
+  caption                = balanced_anything^1,
   --- Media
   media_inline        = V"media_inline_start"
-                      * C((1 - V"double_rbr")^1)
-                      * V"double_rbr"
+                      * C((1 - double_rbrack)^1)
+                      * double_rbrack
                       / formatter.media_inline
                       ,
   media_extension     = P"ogg" + P"wav",
-  media_inline_start  = V"double_lbr" * V"media_inline_prefix" * V"colon",
+  media_inline_start  = double_lbrack * V"media_inline_prefix" * colon,
   media_inline_prefix = P"Media",
   --- Gallery
   gallery_block_start   = P"<gallery"
-                        * (V"space_tab" * Cg(V"CSS_parameter_list", "parameters"))^-1
+                        * (space_tab * Cg(CSS_parameter_list, "parameters"))^-1
                         * P">"
                         ,
   gallery_block_stop    = P"</gallery>",
   gallery_block         = Ct(V"gallery_block_start"
-                           * (V"whitespace_rest" * V"gallery_element")^1)
-                        * V"whitespace_rest"
+                           * (whitespace_rest * V"gallery_element")^1)
+                        * whitespace_rest
                         * V"gallery_block_stop"
                         / formatter.gallery_block
                         ,
   gallery_element       = V"gallery_image" + V"gallery_text",
   gallery_text          = #-V"gallery_block_stop"
-                        * Ct(Cg((1 - V"bar" - V"whitespace_rest")^1, "text")
-                           * (V"bar"
-                            * V"space_tab"^0
-                            * Cg((1 - V"whitespace_rest")^1, "caption"))^-1)
+                        * Ct(Cg((1 - bar - whitespace_rest)^1, "text")
+                           * (bar
+                            * space_tab^0
+                            * Cg((1 - whitespace_rest)^1, "caption"))^-1)
                         ,
   gallery_image         = V"image_prefix"
                         * Ct(V"gallery_image_name"
                            * V"gallery_image_caption"^-1)
                         ,
-  gallery_image_name    = Cg((1 - V"bar" - V"whitespace_rest")^0 , "name")
+  gallery_image_name    = Cg((1 - bar - whitespace_rest)^0 , "name")
                         ,
-  gallery_image_caption = V"bar"
-                        * V"space_tab"^0
-                        * Cg((1 - V"whitespace_rest")^0, "caption")
+  gallery_image_caption = bar
+                        * space_tab^0
+                        * Cg((1 - whitespace_rest)^0, "caption")
                         ,
   ------------------------------------------------------------------------
   --  Noparse-Block
                      * (1 - V"nowiki_closing_tag")^0
                      * V"nowiki_closing_tag"^-1
                      ,
-  nowiki_opening_tag = P"<nowiki"  * (V"whitespace" * V"characters")^0 * P">",
-  nowiki_closing_tag = P"</nowiki" * V"whitespace"  * P">",
-  --nowiki_body        = V"characters",
+  nowiki_opening_tag = P"<nowiki"  * (whitespace * characters)^0 * P">",
+  nowiki_closing_tag = P"</nowiki" * whitespace  * P">",
+  --nowiki_body        = characters,
 
   pre_block       = V"pre_opening_tag"
-                  --* V"whitespace"^0
+                  --* whitespace^0
                   --* V"pre_body"
-                  --* V"whitespace"^0
+                  --* whitespace^0
                   * (1 - V"pre_closing_tag")^0
                   * V"pre_closing_tag"^-1
                   ,
-  pre_opening_tag = P"<pre" * (V"whitespace" * V"characters")^0 * P">",
-  pre_closing_tag = P"</pre" * V"whitespace" * P">",
-  --pre_body        = V"characters",
+  pre_opening_tag = P"<pre" * (whitespace * characters)^0 * P">",
+  pre_closing_tag = P"</pre" * whitespace * P">",
+  --pre_body        = characters,
 
   HTML_block       = V"HTML_opening_tag"
                    * (1 - V"HTML_closing_tag")^0
                    * V"HTML_closing_tag"^-1
                    ,
-  HTML_opening_tag = P"<html"  * (V"whitespace" * V"characters")^0 * P">",
-  HTML_closing_tag = P"</html" * V"whitespace"  * P">",
-  HTML_body        = V"characters",
+  HTML_opening_tag = P"<html"  * (whitespace * characters)^0 * P">",
+  HTML_closing_tag = P"</html" * whitespace  * P">",
+  HTML_body        = characters,
 
   HTML_comment       = V"HTML_comment_start"
                      * C((1 - V"HTML_comment_stop")^0)
                       ,
   _internal_link      = V"internal_link_start"
                       * C(V"article_link")
-                      * (V"gartenzaun" * Cg(V"section_id", "section_id"))^-1
-                      * (V"bar" * Cg(V"internal_link_description", "description"))^-1
+                      * (gartenzaun * Cg(V"section_id", "section_id"))^-1
+                      * (bar * Cg(V"internal_link_description", "description"))^-1
                       * V"internal_link_end"
                       * Cg(V"extra_description", "extra_description")^-1 -- ?
                       ,
-  --article_link        = (V"interwiki_prefix" + V"colon")^-1
+  --article_link        = (V"interwiki_prefix" + colon)^-1
                       --* V"namespace_prefix"^-1 * V"article_title"
                       --,
-  article_link        = (V"interwiki_prefix" + V"colon")^-1 * V"namespace_prefix"^-1 * V"article_title"
+  article_link        = (V"interwiki_prefix" + colon)^-1 * V"namespace_prefix"^-1 * V"article_title"
                       + P"/"     * V"article_title"
                       + P"../"^0 * V"article_title"^-1
                       ,
-  article_title       = (V"title_legal_chars" - V"gartenzaun" + P"%")^1,
-  -- from this regex: " %!\"$&'()*,\\_.\\/0_9:;=?@A_Z\\\\^_`a_z~\\x80_\\xFF+"
-  title_legal_chars   = S[[ %!"$&'()*,_./:;=?@\~+-]]
-                      + V"word_char"
-                      + R"^`"
-                      + R"\128\255"
-                      + V"newline" -- really, try it out on mediawiki!
-                      --+ V"single_markup_char"
-                      + P"\28" -- ‽
-                      ,
+  article_title       = (title_legal_chars - gartenzaun + percent)^1,
+  interwiki_prefix    = V"interwiki" * colon,
+  --interwiki           = STRING_FROM_DB
+  interwiki           = (letter + dash)^1,
   
-  interwiki_prefix    = V"interwiki" * V"colon",
-  --interwiki           = STRING_FROM_DB
-  interwiki           = (R("az", "AZ") + P"-")^1,
+  namespace_prefix    = V"namespace"^-1 * colon,
+  namespace           = letter^1,
   
-  namespace_prefix    = V"namespace"^-1 * V"colon",
-  namespace           = R("az", "AZ")^1,
-  
-  --internal_link_description = Ct(Cs((V"goodies"
-                                   --+ 1 - V"inline_element" - V"double_rbr")^1
+  --internal_link_description = Ct(Cs((goodies
+                                   --+ 1 - V"inline_element" - double_rbrack)^1
                                   --+ V"inline_element")^0)
                             --,
   ignore_formatting   = (V"formatting" / "" + 1),
-  internal_link_description = Ct(Cs((V"goodies" -- formatting in links drives ConTeXt mad ...
-                                   + V"ignore_formatting" - V"double_rbr")^1)^0)
+  internal_link_description = Ct(Cs((goodies -- formatting in links drives ConTeXt mad ...
+                                   + V"ignore_formatting" - double_rbrack)^1)^0)
                             ,
-  external_link_description = Ct(Cs((V"goodies"
-                                   --+ 1 - V"inline_element" - V"rbr")^1
-                                   + V"ignore_formatting" - V"rbr")^1
+  external_link_description = Ct(Cs((goodies
+                                   --+ 1 - V"inline_element" - rbrack)^1
+                                   + V"ignore_formatting" - rbrack)^1
                                   + V"inline_element")^0)
                             ,
-  extra_description   = V"letter"^1,
+  extra_description   = letter^1,
   
-  internal_link_start = V"double_lbr",
-  internal_link_end   = V"double_rbr",
+  internal_link_start = double_lbrack,
+  internal_link_end   = double_rbrack,
   
-  bar                 = P"|",
-  
-  section_id          = (V"title_legal_chars" - P"|" + P"%" + P"#")^1,
+  section_id          = (title_legal_chars - P"|" + P"%" + P"#")^1,
 
   --- Categories
   category_link      = Ct(V"internal_link_start"
-                        * Cg(V"category_namespace", "namespace")
-                        * V"colon"
-                        * Cg((1 - V"bar" - V"internal_link_end")^0, "category")
-                        * (V"bar" * Cg(V"sort_key", "sortkey"))^-1
+                        * Cg(category_namespace, "namespace")
+                        * colon
+                        * Cg((1 - bar - V"internal_link_end")^0, "category")
+                        * (bar * Cg(V"sort_key", "sortkey"))^-1
                         * V"internal_link_end")
                      / formatter.category_link
                      ,
-  sort_key           = V"harmless_character"^1,  -- improvised (utf8char would match everything ...
-  --category_namespace = NS_CATEGORY
-  --category_namespace = R("az", "AZ")^1,
-  --- http://en.wikipedia.org/wiki/Help:Category
-  --- TODO: What about other wikis??
-  category_namespace = P"Main"            + P"Talk"
-                     + P"User Talk"       + P"User"
-                     + P"Wikipedia talk"  + P"Wikipedia"
-                     + P"File talk"       + P"File"
-                     + P"MediaWiki talk"  + P"MediaWiki"
-                     + P"Template talk"   + P"Template"
-                     + P"Help talk"       + P"Help"
-                     + P"Category talk"   + P"Category"
-                     + P"Portal talk"     + P"Portal"
-                     + P"Book talk"       + P"Book"
-                     ,
+  sort_key           = harmless_character^1,  -- improvised (utf8char would match everything ...
 
   --- External links
   external_link       = Ct(V"external_link_start"
-                         * C(V"url")
-                         --* V"whitespace"^-1 -- actually, it doesn’t accept newlines here!
-                         * V"space_tab"^0
+                         * C(url)
+                         --* whitespace^-1 -- actually, it doesn’t accept newlines here!
+                         * space_tab^0
                          * C(V"external_link_description"^-1)
                          * V"external_link_end"
-                         + C(V"url"))
+                         + C(url))
                       / formatter.external_link
                       ,
-  url                 = V"protocol" * V"url_path",
-  --protocol            = ALLOWED_PROTOCOL_FROM_CONFIG (e.g. "http://", "mailto:")
-  protocol            = P"http://" -- what else?
-                      + P"mailto:"
-                      + P"ftp://"
-                      ,
-  url_path            = V"url_char" * V"url_path"^-1,
-  --url_char            = LEGAL_URL_ENTITY
-  url_char            = V"word_char"
-                      + S"!*'();:@&=+$,/?#[]-_.~"
-                      + V"escaped_url_char"
-                      ,
-  escaped_url_char    = P"%" * V"hex_digit" * V"hex_digit",
-  external_link_start = V"lbr",
-  external_link_end   = V"rbr",
+  external_link_start = lbrack,
+  external_link_end   = rbrack,
 
   ------------------------------------------------------------------------
   --  Magic Links
   ------------------------------------------------------------------------
   magic_link    = V"isbn" + V"rfc_number" + V"pmid_number",
-  isbn          = P"ISBN" * P" "^0 * V"isbn_number" * V"non_word_char"^-1,
+  isbn          = P"ISBN" * P" "^0 * V"isbn_number" * non_word_char^-1,
   isbn_number   = (P"97" * S"89" * S" -"^-1)
-                * (V"decimal_digit" * S" -"^-1) -- 1
-                * (V"decimal_digit" * S" -"^-1) -- 2
-                * (V"decimal_digit" * S" -"^-1) -- 3
-                * (V"decimal_digit" * S" -"^-1) -- 4
-                * (V"decimal_digit" * S" -"^-1) -- 5
-                * (V"decimal_digit" * S" -"^-1) -- 6
-                * (V"decimal_digit" * S" -"^-1) -- 7
-                * (V"decimal_digit" * S" -"^-1) -- 8
-                * (V"decimal_digit" * S" -"^-1) -- 9
-                * (V"decimal_digit" + S"Xx")
+                * (decimal_digit * S" -"^-1) -- 1
+                * (decimal_digit * S" -"^-1) -- 2
+                * (decimal_digit * S" -"^-1) -- 3
+                * (decimal_digit * S" -"^-1) -- 4
+                * (decimal_digit * S" -"^-1) -- 5
+                * (decimal_digit * S" -"^-1) -- 6
+                * (decimal_digit * S" -"^-1) -- 7
+                * (decimal_digit * S" -"^-1) -- 8
+                * (decimal_digit * S" -"^-1) -- 9
+                * (decimal_digit + S"Xx")
                 ,
-  rfc_number    = P"RFC"  * V"whitespace" * V"decimal_digit"^1,
-  pmid_number   = P"PMID" * V"whitespace" * V"decimal_digit"^1,
-
-
-  ------------------------------------------------------------------------
-  --  Fundamentals: Low-Level Rules and Terminals
-  ------------------------------------------------------------------------
-  character           = V"whitespace_char" + V"non_whitespace_char" + V"html_entity",
-  characters          = V"character"^1, -- not in the spec but referred to everywhere
-
-  html_entity         = (P"&"   * V"html_entity_chars" * P";")
-                      + (P"&#"  * V"decimal_number" * P";")
-                      + (P"&#x" * V"hex_number" * P";")
-                      ,
-  html_entity_chars   = V"html_entity_char" * V"html_entity_chars"^-1,
-  html_entity_char    = V"ucase_letter" + V"lcase_letter" + V"decimal_digit",
-
-  space_tab           = V"space" + V"tab",
-  spaces              = V"space" * V"spaces"^-1,
-  space               = P" ",
-  whitespace          = V"whitespace_char" * V"whitespace"^-1 + V"eof",
-  newlines            = V"newline" * V"newlines"^-1,
-  space_tabs          = V"space_tab" * V"space_tabs"^-1,
-  
-  newline             = P"\r\n" + P"\n\r" + P"\n" + P"\r",
-  bol                 = V"newline",-- + V"bof",
-  eol                 = V"newline" + V"eof",
-  eof                 = P(-1),
-  tab                 = S"\t\v",
-  
-  whitespace_char     = V"space_tab" + V"newline",
-  whitespace_rest     = V"space_tab"^0 * V"newline",
-
-  lbr                 = P"[",
-  rbr                 = P"]",
-  double_lbr          = V"lbr" * V"lbr",
-  double_rbr          = V"rbr" * V"rbr",
-  balanced_double_br  = (V"_balanced_double_br" + (1 - V"double_rbr"))^1,
-  _balanced_double_br = V"double_lbr" * V"balanced_double_br"^-1 * V"double_rbr",
-
-  lbrace              = P"{",
-  rbrace              = P"}",
-  double_lbrace       = V"lbrace" * V"lbrace",
-  double_rbrace       = V"rbrace" * V"rbrace",
-
-  non_whitespace_char = V"letter" + V"decimal_digit" + V"symbol",
-  letter              = V"ucase_letter" + V"lcase_letter",
-  ucase_letter        = R"AZ",
-  lcase_letter        = R"az",
-  symbol              = V"html_unsafe_symbol"
-                      + V"underscore"
-                      + S",."
-                      --+ V"punctuation"
-                      ,
-  bad_title_characters = S"[]{}<>_|#",
-  title_character      = utf8char - V"bad_title_characters",
-  page_name            = V"title_character"^1,
-
-  decimal_number      = V"decimal_digit" * V"decimal_number"^-1,
-  decimal_digit       = R"09",
-  hex_number          = V"hex_digit" * V"hex_number"^-1,
-  hex_digit           = V"decimal_digit" + R"AF" + R"af",
-
-  asterisk            = P"*",
-  colon               = P":",
-  dot                 = P".",
-  double_quote        = P[["]],
-  equals              = P"=",
-  gartenzaun          = P"#",
-  html_unsafe_symbol  = P"<" + P">" + P"&",
-  semicolon           = P";",
-  triple_dot          = V"dot" * V"dot" * V"dot",
-  underscore          = P"_",
-
-  goodies             = Cs(V"triple_dot" / "\\dots ")
-                      + Cs(V"underscore" / "\\letterunderscore ")
-                      ,
-  
-  word_char           = V"ucase_letter" + V"lcase_letter" + V"decimal_digit",
-  non_word_char       = 1 - V"word_char",
-
-  CSS_parameter_list      = Cf(Ct"" * V"CSS_parameter__list", rawset)
-                          * V"space_tab"^0
-                          ,
-  CSS_parameter__list     = (V"space_tab"^0 * Cg(V"CSS_parameter_pair"))^0,
-  CSS_parameter_pair      = C(V"harmless_character"^1) / stringlower
-                          * V"space_tab"^0
-                          * V"equals"
-                          * V"space_tab"^0
-                          * (V"double_quote" * C((1 - V"double_quote" - V"newline")^1) * V"double_quote"
-                           + C((V"harmless_character"
-                              + V"underscore")^1))
-                          ,
-}
+  rfc_number    = P"RFC"  * whitespace * decimal_digit^1,
+  pmid_number   = P"PMID" * whitespace * decimal_digit^1,
+} --[[ 6018 Rules ]]
 
 
 ------------------------------------------------------------------------
   "wiki_page",
 
   ------------------------------------------------------------------------
-  --  Fundamentals: Low-Level Rules and Terminals
-  ------------------------------------------------------------------------
-
-  character           = V"whitespace_char" + V"non_whitespace_char" + V"html_entity",
-  characters          = V"character"^1, -- not in the spec but referred to everywhere
-
-  html_entity         = (P"&"   * V"html_entity_chars" * P";")
-                      + (P"&#"  * V"decimal_number" * P";")
-                      + (P"&#x" * V"hex_number" * P";")
-                      ,
-  html_entity_chars   = V"html_entity_char" * V"html_entity_chars"^-1,
-  html_entity_char    = V"ucase_letter" + V"lcase_letter" + V"decimal_digit",
-
-  whitespace          = V"whitespace_char" * V"whitespace"^-1 + V"eof",
-  newlines            = V"newline" * V"newlines"^-1,
-  space_tabs          = V"space_tab" * V"space_tabs"^-1,
-  
-  whitespace_rest     = V"space_tab"^0 * V"newline",
-  whitespace_char     = V"space_tab" + V"newline",
-  
-  space_tab           = V"space" + V"tab",
-  spaces              = V"space" * V"spaces"^-1,
-  space               = P" ",
-  
-  newline             = P"\r\n" + P"\n\r" + P"\n" + P"\r",
-  bol                 = V"newline",-- + V"bof",
-  eol                 = V"newline" + V"eof",
-  eof                 = P(-1),
-  tab                 = S"\t\v",
-  
-  non_whitespace_char = V"letter" + V"decimal_digit" + V"symbol",
-  letter              = V"ucase_letter" + V"lcase_letter",
-  harmless_character  = V"letter" + V"decimal_digit",
-  ucase_letter        = R"AZ",
-  lcase_letter        = R"az",
-  symbol              = V"html_unsafe_symbol"
-                      + V"underscore"
-                      + S",."
-                      --+ V"punctuation"
-                      ,
-  --punctuation         = S".,;:+-=?!/"
-                      --+ P"„" + P"“" + P"”"
-                      --+ P"‚" + P"‘" + P"’"
-                      --+ P"«" + P"»"
-                      --+ P"‽" + P"⸮" + P"¿" + P"¡"
-                      --+ P"‐" + P"‒" + P"–" + P"—" + P"―"
-                      --,
-  html_unsafe_symbol  = P"<" + P">" + P"&",
-  underscore          = P"_",
-  equals              = P"=",
-  double_quote        = P[["]],
-  dash                = P"-",
-  exclam              = P"!",
-  double_exclam       = V"exclam" * V"exclam",
-  
-  lbr                 = P"[",
-  rbr                 = P"]",
-  double_lbr          = V"lbr" * V"lbr",
-  double_rbr          = V"rbr" * V"rbr",
-  balanced_double_br  = (V"_balanced_double_br" + (1 - V"double_rbr"))^0,
-  _balanced_double_br = V"double_lbr" * V"balanced_double_br"^-1 * V"double_rbr",
-
-  lbrace              = P"{",
-  rbrace              = P"}",
-  double_lbrace       = V"lbrace" * V"lbrace",
-  double_rbrace       = V"rbrace" * V"rbrace",
-  balanced_double_brace = (V"inner_double_brace" + 1 - V"double_rbrace")^0,
-  inner_double_brace    = V"double_lbrace"
-                        * V"balanced_double_brace"
-                        * V"double_rbrace"
-                        ,
-
-  decimal_number      = V"decimal_digit" * V"decimal_number"^-1,
-  decimal_digit       = R"09",
-  hex_number          = V"hex_digit" * V"hex_number"^-1,
-  hex_digit           = V"decimal_digit" + R"AF" + R"af",
-
-  word_char           = V"ucase_letter" + V"lcase_letter" + V"decimal_digit",
-  non_word_char       = 1 - V"word_char",
-
-  colon               = P":",
-  semicolon           = P";",
-  gartenzaun          = P"#",
-  asterisk            = P"*",
-  list_item_marker    = V"colon" + V"gartenzaun" + V"asterisk",
-
-  bar                 = P"|",
-  nobar               = 1 - V"bar",
-  nodoublebar         = 1 - V"bar" * V"bar",
-
-  ------------------------------------------------------------------------
-  --  CSS parameters
-  ------------------------------------------------------------------------
-  CSS_parameter_list      = Cf(Ct"" * V"CSS_parameter__list", rawset)
-                          * V"space_tab"^0
-                          ,
-  CSS_parameter__list     = (V"space_tab"^0 * Cg(V"CSS_parameter_pair"))^1,
-  CSS_parameter_pair      = C(V"harmless_character"^1)
-                          * V"space_tab"^0
-                          * V"equals"
-                          * V"space_tab"^0
-                          * (V"double_quote" * C((1 - V"double_quote" - V"newline")^1) * V"double_quote"
-                           + C((V"harmless_character"
-                              + V"underscore")^1))
-                          ,
-  ------------------------------------------------------------------------
   -- Titles
   ------------------------------------------------------------------------
   canonical_article_title   = V"canonical_page" * V"canonical_sub_pages"^-1,
   canonical_page            = V"canonical_page_first_char" * V"canonical_page_chars"^-1,
   canonical_page_chars      = V"canonical_page_char" * V"canonical_page_chars"^-1,
   
-  canonical_page_first_char = V"ucase_letter" + V"decimal_digit" + V"underscore",
-  canonical_page_char       = V"letter" + V"decimal_digit" + V"underscore",
+  canonical_page_first_char = ucase_letter + decimal_digit + underscore,
+  canonical_page_char       = letter + decimal_digit + underscore,
   
   sub_page_separator        = P"/",
 
   sub_page             = V"sub_page_separator" * V"page_chars",
   page                 = V"page_first_char" * V"page_chars"^-1,
   page_chars           = V"page_char" * V"page_chars"^-1,
-  page_first_char      = V"canonical_page_first_char" + V"lcase_letter",
-  page_char            = V"canonical_page_char" + V"space",
-  page_name            = V"title_character"^1,
+  page_first_char      = V"canonical_page_first_char" + lcase_letter,
+  page_char            = V"canonical_page_char" + space,
+  page_name            = title_character^1,
   bad_title_characters = S"[]{}<>_|#",
-  title_character      = utf8char - V"bad_title_characters",
+  title_character      = utf8char - bad_title_characters,
 
   ------------------------------------------------------------------------
   --  Article
                ,
                            
   redirect     = V"redirect_tag"
-               * V"characters"
+               * characters
                * V"internal_link_start"
                * (1 - V"redirect_stop")^1
                * V"redirect_stop"
                ,
-  redirect_stop       = V"internal_link_end" + V"bar" + V"newline",
-  internal_link_start = V"double_lbr",
-  internal_link_end   = V"double_rbr",
+  redirect_stop       = V"internal_link_end" + bar + newline,
+  internal_link_start = double_lbrack,
+  internal_link_end   = double_rbrack,
   
   --redirect_tag = FROM_LANGUAGE_FILE
   redirect_tag = P"#redirect",
 
-  article                = (V"whitespace_rest"^0 * V"block")^1
+  article                = (whitespace_rest^0 * V"block")^1
                          ,
   block                  = V"special_block_and_more"
                          + V"paragraph_and_more"
                          ,
   special_block_and_more = V"special_block"
-                         --* V"whitespace_rest"^0
-                         --/ dbg
                          ,
   paragraph_and_more     = V"paragraph"
-                         --* V"whitespace_rest"^0
                          ,
 
   paragraph     = C(V"lines_of_text")
                 ,
   lines_of_text = V"line_of_text"^1,
   line_of_text  = -#V"block_start"
-                * (1 - V"newline")^1
-                * V"newline"
+                * (1 - newline)^1
+                * newline
                 ,
 
   block_start   = (V"horizontal_rule"
                  + V"list_start"
                  + V"table_start")
                  --+ V"space_block")
-                + V"whitespace_rest"
+                + whitespace_rest
                 ,
   ------------------------------------------------------------------------
   --  Start Markers
   ------------------------------------------------------------------------
-  list_start    = V"list_item_marker",
-  table_start   = V"table_start_marker",
+  list_start    = list_item_marker,
+  table_start   = table_start_marker,
 
   ------------------------------------------------------------------------
   --  Special Blocks
   template_block   = V"template_start"
                    * V"template_content"
                    * V"template_end"
-                   * V"whitespace_rest"^-1
+                   * whitespace_rest^-1
                    ,
-  template_start   = V"double_lbrace",
-  template_end     = V"double_rbrace",
-  template_content = C(V"balanced_double_brace")
+  template_start   = double_lbrace,
+  template_end     = double_rbrace,
+  template_content = C(balanced_double_brace)
                    / formatter.template_block
                    ,
   --- Rules
-  horizontal_rule  = P"----" * V"dash"^0 * (1 - V"newline")^1 * V"newline",
+  horizontal_rule  = dash^4 * (1 - newline)^1 * newline,
   --dashes           = P"-" * V"dashes",
   --- Headings
   --- The following exception renders any definition by means of fixed amounts
   --- Therefore, the associated function will have to determine the heading
   --- level based on the shorter marker string.
   heading          = C(V"heading_marker")
-                   --* C((1 - V"heading_marker" * V"whitespace_rest")^1)
+                   --* C((1 - V"heading_marker" * whitespace_rest)^1)
                    * C((1 - V"heading_marker")^1)
                    * C(V"heading_marker")
-                   * V"whitespace_rest"^-1
+                   * whitespace_rest^-1
                    / formatter.heading
                    ,
-  heading_marker   = V"equals"^1,
+  heading_marker   = equals^1,
   --- Lists
   --- “indent_item” -> definition list
   --list_item        = V"indent_item" +  V"enumerated_item" + V"bullet_item",
-  --indent_item      = V"colon"      * (V"list_item" + V"item_body")^-1,
-  --enumerated_item  = V"gartenzaun" * (V"list_item" + V"item_body")^-1,
-  --bullet_item      = V"asterisk"   * (V"list_item" + V"item_body")^-1,
+  --indent_item      = colon      * (V"list_item" + V"item_body")^-1,
+  --enumerated_item  = gartenzaun * (V"list_item" + V"item_body")^-1,
+  --bullet_item      = asterisk   * (V"list_item" + V"item_body")^-1,
   --- rewritten to avoid recursion
   list_item        = (V"indent_item" +  V"enumerated_item" + V"bullet_item")^1 * V"item_body"^-1,
-  indent_item      = V"colon",
-  enumerated_item  = V"gartenzaun",
-  bullet_item      = V"asterisk",
+  indent_item      = colon,
+  enumerated_item  = gartenzaun,
+  bullet_item      = asterisk,
   item_body        = V"defined_term"
-                   + V"whitespace"^-1 * (1 - V"newline")^1
+                   + whitespace^-1 * (1 - newline)^1
                    ,
-  defined_term     = V"semicolon" * (1 - V"newline")^1 * V"definition"^-1,
-  definition       = V"colon"     * (1 - V"newline")^1,
+  defined_term     = semicolon * (1 - newline)^1 * V"definition"^-1,
+  definition       = colon     * (1 - newline)^1,
   --- Table
   table                    = Ct(V"_table")
                            / formatter.table
                            ,
-  _table                   = V"table_start_marker"
-                           * Cg(V"CSS_parameter_list"^-1, "parameters") * V"whitespace_rest"^-1
-                           * V"table_caption"^-1 * V"whitespace_rest"^-1
-                           * Cg(V"table_header"  * V"whitespace_rest"^-1, "header")^-1
+  _table                   = table_start_marker
+                           * Cg(CSS_parameter_list^-1, "parameters") * whitespace_rest^-1
+                           * V"table_caption"^-1 * whitespace_rest^-1
+                           * Cg(V"table_header"  * whitespace_rest^-1, "header")^-1
                            --* V"table_first_row"
                            * V"table_row"^1
-                           * Cg(V"table_header"  * V"whitespace_rest"^-1, "bottom")^-1
-                           * (V"table_newrow_marker" * V"whitespace_rest")^-1
-                           * V"table_stop_marker"
+                           * Cg(V"table_header"  * whitespace_rest^-1, "bottom")^-1
+                           * (table_newrow_marker * whitespace_rest)^-1
+                           * table_stop_marker
                            ,
-  table_header             = V"table_newrow_marker" * V"space_tab"^0
-                           * Cg(V"CSS_parameter_list", "row_parameters")^-1
-                           * V"whitespace_rest"
+  table_header             = table_newrow_marker * space_tab^0
+                           * Cg(CSS_parameter_list, "row_parameters")^-1
+                           * whitespace_rest
                            * Ct(V"table_hcolumn"^1)
                            ,
   table_hcolumn            = V"table_hcolumn_multi_line"
                            * V"table_hcolumn_line"
                            ,
-  table_hcolumn_line        = V"exclam" * V"space_tab"^0
-                           * Ct((Cg(V"CSS_parameter_list", "parameters") * V"bar")^-1
-                              * V"space_tab"^0
-                              * Cg((balanced_anything + 1 - V"exclam" - V"newline")^0, "content"))
-                           * ((V"exclam" * V"table_hcolumn_line")
-                             + V"newline")
+  table_hcolumn_line        = exclam * space_tab^0
+                           * Ct((Cg(CSS_parameter_list, "parameters") * bar)^-1
+                              * space_tab^0
+                              * Cg((balanced_anything + 1 - exclam - newline)^0, "content"))
+                           * ((exclam * V"table_hcolumn_line")
+                             + newline)
                            ,
-  table_hcolumn_multi_line = V"exclam" * V"space_tab"^0
-                           * Ct((Cg(V"CSS_parameter_list", "parameters") * V"bar")^-1
-                              * V"space_tab"^0
-                              * Cg((balanced_anything + 1 - V"double_exclam" - (V"newline" * V"exclam"))^0, "content")) -- no such rule: “AnyText”!
-                           * V"newline"
+  table_hcolumn_multi_line = exclam * space_tab^0
+                           * Ct((Cg(CSS_parameter_list, "parameters") * bar)^-1
+                              * space_tab^0
+                              * Cg((balanced_anything + 1 - double_exclam - (newline * exclam))^0, "content")) -- no such rule: “AnyText”!
+                           * newline
                            ,
                            
-  table_start_marker       = P"{|",
-  table_stop_marker        = P"|}",
-  table_caption_marker     = P"|+",
-  table_newrow_marker      = P"|-",
-  table_newcell_marker     = V"bar"
-                           - V"table_stop_marker"
-                           - V"table_newrow_marker"
-                           - V"table_caption_marker" -- redundant-p
+  table_newcell_marker     = bar
+                           - table_stop_marker
+                           - table_newrow_marker
+                           - table_caption_marker -- redundant-p
                            ,
   table_first_row          = V"table_row"^1
-                           --+ (V"table_column_line" * V"newline")^1
+                           --+ (V"table_column_line" * newline)^1
                            --+ V"table_column_multi_line"^1
                            ,
-  table_row                = V"table_newrow_marker" * V"space_tab"^0
-                           * Cg(V"CSS_parameter_list", "row_parameters")^-1
-                           * V"whitespace_rest"
+  table_row                = table_newrow_marker * space_tab^0
+                           * Cg(CSS_parameter_list, "row_parameters")^-1
+                           * whitespace_rest
                            * Ct(V"table_column"^1)
                            --* V"table_row"^-1
                            ,
   table_column             = V"table_column_multi_line" + V"table_column_line",
   table_column_line        = V"table_newcell_marker"
-                           * Ct((Cg(V"CSS_parameter_list", "parameters") * V"bar")^-1
-                              * V"space_tab"^0
-                              * Cg((balanced_anything + V"nobar" - V"newline")^0, "content"))
-                           * ((V"bar" * V"table_column_line")
-                             + V"newline")
+                           * Ct((Cg(CSS_parameter_list, "parameters") * bar)^-1
+                              * space_tab^0
+                              * Cg((balanced_anything + nobar - newline)^0, "content"))
+                           * ((bar * V"table_column_line")
+                             + newline)
                            ,
   table_column_multi_line  = V"table_newcell_marker"
-                           * Ct((Cg(V"CSS_parameter_list", "parameters") * V"bar")^-1
-                              * V"space_tab"^0
-                              * Cg((balanced_anything + V"nodoublebar" - (V"newline" * V"bar"))^0, "content")) -- no such rule: “AnyText”!
-                           * V"newline"
+                           * Ct((Cg(CSS_parameter_list, "parameters") * bar)^-1
+                              * space_tab^0
+                              * Cg((balanced_anything + nodoublebar - (newline * bar))^0, "content")) -- no such rule: “AnyText”!
+                           * newline
                            ,
-  table__caption           = C((V"nobar" - V"newline")^1),
-  table_caption_style      = C(V"nobar"^1),
-  table_caption            = V"table_caption_marker"
-                           * Cg(Ct((V"CSS_parameter_list" * V"bar")^-1
-                                 * V"space_tab"^0
+  table__caption           = C((nobar - newline)^1),
+  table_caption_style      = C(nobar^1),
+  table_caption            = table_caption_marker
+                           * Cg(Ct((CSS_parameter_list * bar)^-1
+                                 * space_tab^0
                                  * V"table__caption")
                               , "caption")
                            ,
-  --table_header             = (V"space" * V"table_parameters")^-1
-                           --* V"newline"
+  --table_header             = (space * V"table_parameters")^-1
+                           --* newline
                            --* V"table_caption"
                            --,
   --- Space Block          
-  space_block              = P" " * (1 - V"newline")^1 * V"newline" * V"space_block_2"^0,
-  space_block_2            = P" " * (1 - V"newline")^0 * V"newline",
-}
+  space_block              = space * (1 - newline)^1 * newline * V"space_block_2"^0,
+  space_block_2            = space * (1 - newline)^0 * newline,
+} --[[ 3519 Rules ]]
 
 ------------------------------------------------------------------------
 --  Infoboxes
   "infobox",
 
   infobox           = Ct(V"first_line" * V"assignments"),
-  first_line        = P"Infobox" * V"space_tab"^0 * V"subtype"^-1 * V"whitespace_rest",
-  subtype           = C((1 - V"whitespace_rest")^1),
+  first_line        = P"Infobox" * space_tab^0 * V"subtype"^-1 * whitespace_rest,
+  subtype           = C((1 - whitespace_rest)^1),
   assignments       = Cf(Ct"" * V"assignment"^1, rawset),
-  assignment_start  = V"space_tab"^0 * V"bar",
+  assignment_start  = space_tab^0 * bar,
   assignment        = V"assignment_start"
-                    * V"space_tab"^0
-                    * Cg(V"key" * V"space_tab"^0 * V"equals" * V"space_tab"^0
-                      * (V"empty" + V"value")) * (V"eol" + V"eof")^-1
+                    * space_tab^0
+                    * Cg(V"key" * space_tab^0 * equals * space_tab^0
+                      * (V"empty" + V"value")) * (eol + eof)^-1
                     ,
-  key               = C((V"letter" + V"digit" + V"underscore")^1),
-  empty             = (#V"eol" + #V"bar" + V"eof") * Cc(nil),
+  key               = C((letter + decimal_digit + underscore)^1),
+  empty             = (#eol + #bar + eof) * Cc(nil),
   value             = C((balanced_anything + 1 - V"end_of_value")^1)
-                    * V"space_tab"^0
+                    * space_tab^0
                     ,
-  eol               = S"\n\r",
-  eof               = -P(1),
-  space_tab         = S" \t\v",
-  equals            = P"=",
-  underscore        = P"_",
-  bar               = P"|",
-  letter            = R("az", "AZ"),
-  digit             = R"09",
-  end_of_value      = V"space_tab"^0 * (V"bar" + V"eol" + V"eof"),
-  whitespace_rest   = V"space_tab"^0 * (V"eol" + V"eof"),
+  end_of_value      = space_tab^0 * (bar + eol + eof),
+  whitespace_rest   = space_tab^0 * (eol + eof),
 }
 
 do
     html            = V"html1" + V"html2",
     html1           = V"opening" * (1 - V"closing")^0 * V"closing",
     html2           = P"<" * (1 - P"/>")^1 * P"/>",
-    opening         = P"<" * Cg(V"letter"^1, "matchme") * (1 - P">")^0 * P">",
+    opening         = P"<" * Cg(letter^1, "matchme") * (1 - P">")^0 * P">",
     closing         = P"</"
                     * Cmt(C((1 - S" >")^1) * Cb("matchme"), function (_,_,m1,m2) return m1 == m2 end)
                     * (1 - P">")^0
                     * P">"
                     ,
-    letter          = R("az", "AZ"),
     space_char      = S" \n\r\t\v",
     --- people who use “'” instead of “’” should be punished ...
     --- ... otoh, those who use it as markup are even worse!
               + 1)^1),
     balanced = P"{" * (V"balanced" + (1 - P"}"))^0 * P"}",
     skip1    = P"\\starttyping" * (1 - P"\\stoptyping")^1,
-    skip2    = P"\\type"        * P"space"^0 * V"balanced",
-    skip3    = P"\\mathematics" * P"space"^0 * V"balanced",
+    skip2    = P"\\type"        * space^0 * V"balanced",
+    skip3    = P"\\mathematics" * space^0 * V"balanced",
     skip4    = P"\\asciimode"   * (1 - P"\\noasciimode")^1,
     skip     = V"skip1" + V"skip2" + V"skip3",
     space    = P" ",