From fced673c2458283b9003b4ffc791ba44352f67c3 Mon Sep 17 00:00:00 2001
From: Philipp Gesang <phg@phi-gamma.net>
Date: Sun, 2 Mar 2014 14:40:47 +0100
Subject: eliminate redundand use of grammars

---
 src/rst_parser.lua | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)

(limited to 'src')

diff --git a/src/rst_parser.lua b/src/rst_parser.lua
index 4fc36cf..93d8a11 100644
--- a/src/rst_parser.lua
+++ b/src/rst_parser.lua
@@ -125,24 +125,18 @@ state.footnotes.symbol     = {}
 
 state.addme                = {}
 
+local valid_adornment
 do
-    local first_adornment = ""
-    local valid_adornment = P {
-        [1] = "adorncheck",
-        adorncheck  = V"check_first" * V"check_other"^1 * -P(1),
-        check_first = Cmt(V"adornment_char", function(_,_, first)
-                            first_adornment = first
-                            return true
-                        end)
-                    ,
-        check_other = Cmt(V"adornment_char", function(_,_, char)
-                            local prev = first_adornment
-                            return char == prev
-                        end)
-                    ,
-        adornment_char = S[[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]] + P[[\\]],
-    }
-    state.valid_adornment = valid_adornment
+    local first_adornment    = ""
+    local adornment_char     = S[[!"#$%&'()*+,-./:;<=>?@[]^_`{|}~]] + P[[\\]]
+    local check_first        = Cmt(adornment_char, function(_,_, first)
+                                       first_adornment = first
+                                       return true
+                                   end)
+    local check_other        = Cmt(adornment_char, function(_,_, char)
+                                       return char == first_adornment
+                                   end)
+    valid_adornment          = check_first * check_other^1 * -P(1)
 end
 
 local enclosed_mapping = {
@@ -1042,7 +1036,7 @@ local rst_parser = P {
     -- The whitespace handling after the overline is necessary because headings
     -- without overline aren't allowed to be indented.
     section_before = C(Cmt(V"section_adorn", function(s,i, adorn)
-                          local adorn_matched = lpegmatch (state.valid_adornment, adorn)
+                          local adorn_matched = lpegmatch (valid_adornment, adorn)
                           state.previousadorn = adorn
                           warn ("sec-f", adorn_matched,
                                 stringsub (adorn, 1,2) .. "...", "", i)
@@ -1060,7 +1054,7 @@ local rst_parser = P {
 
     section_after = C(Cmt(V"section_adorn", function(s,i, adorn)
                          local tests = false
-                         if lpegmatch (state.valid_adornment, adorn) then
+                         if lpegmatch (valid_adornment, adorn) then
                            tests = true
                          end
                          if state.previousadorn then
@@ -1075,7 +1069,7 @@ local rst_parser = P {
 
     section_once = C(Cmt(V"section_adorn", function(s,i, adorn)
                          local tests = false
-                         if lpegmatch (state.valid_adornment, adorn) then
+                         if lpegmatch (valid_adornment, adorn) then
                            tests = true
                          end
                          warn ("sec-o", tests, stringsub (adorn, 1,2) .. "…", "", i)
-- 
cgit v1.2.3