summaryrefslogtreecommitdiff
path: root/rst_parser.lua
diff options
context:
space:
mode:
Diffstat (limited to 'rst_parser.lua')
-rw-r--r--rst_parser.lua124
1 files changed, 123 insertions, 1 deletions
diff --git a/rst_parser.lua b/rst_parser.lua
index 4e767b5..6630767 100644
--- a/rst_parser.lua
+++ b/rst_parser.lua
@@ -54,6 +54,7 @@ tracklists.bullets.max = 0
tracklists.lastbullet = ""
tracklists.roman_cache = {} -- storing roman numerals that were already converted
tracklists.currentindent = "" -- used in definition lists and elsewhere
+tracklists.currentlayout = {} -- table layout
local enclosed_mapping = {
["'"] = "'",
@@ -197,6 +198,7 @@ local parser = P{
block = V"target_block"
+ V"comment"
+ V"line_block"
+ + Cs(V"table_block") / rst.escape
+ Cs(V"section") / rst.escape
+ Cs(V"transition") --/ rst.escape
+ V"literal_block"
@@ -206,6 +208,121 @@ local parser = P{
,
--------------------------------------------------------------------------------
+-- Table block
+--------------------------------------------------------------------------------
+
+ table_block = V"grid_table"
+ --+ V"simple_table"
+ / rst.table
+ ,
+
+
+--------------------------------------------------------------------------------
+-- Grid table
+--------------------------------------------------------------------------------
+
+ grid_table = Cs(V"gt_first_row"
+ * V"gt_other_rows")
+ * V"blank_line"^1
+ / rst.grid_table
+ ,
+
+ gt_first_row = V"gt_setindent"
+ * V"gt_setlayout"
+ * V"eol"
+ / ""
+ ,
+
+ --gt_setindent = Cg(V"space"^0, "tableindent"),
+ gt_setindent = Cmt(V"space"^0, function(s, i, indent)
+ warn("tab-i", true, #indent, "set", i)
+ tracklists.currentindent = indent
+ return true
+ end)
+ ,
+
+ gt_layoutmarkers = V"table_intersection" + V"table_hline" + V"table_header_hline",
+
+ gt_setlayout = Cmt(V"gt_layoutmarkers"^3, function (s, i, layout)
+ --warn("tab-l", layout)
+ local l = {}
+ for n, dimension in ipairs(string.explode(layout, "++")) do
+ l[n] = #dimension
+ end
+ l["length"] = #layout
+ warn("tab-l", unpack(l))
+ tracklists.currentlayout = l
+ return true
+ end)
+ ,
+
+ gt_other_rows = V"gt_head"^-1
+ * V"gt_body"
+ ,
+
+ --gt_matchindent = Cmt(V"space"^0 * Cb"tableindent", function (s, i, this, matchme)
+ gt_matchindent = Cmt(V"space"^0, function (s, i, this)
+ local matchme = tracklists.currentindent
+ warn("tab-m", this == matchme, #this, #matchme, i)
+ return this == matchme
+ end)
+ ,
+
+ --gt_cell = Cmt(V"gt_content_cell" + V"gt_line_cell", function (s, i, cell)
+ --print("NEXT CELL:",cell)
+ --return true
+ --end),
+
+ gt_cell = C(V"gt_content_cell" + V"gt_line_cell"),
+
+ gt_content_cell = (V"table_vline" + V"table_intersection")
+ * C((1 - V"table_vline" - V"table_intersection" - V"eol")^1),
+
+ gt_line_cell = V"table_intersection"
+ --* C((V"table_hline" - V"table_intersection")^1)
+ * C(V"table_hline"^1)
+ ,
+
+ gt_contentrow = Ct(V"gt_matchindent"
+ * V"gt_cell"^1
+ * (V"table_vline" + V"table_intersection")
+ * V"eol"
+ )
+ / rst.table_row
+ ,
+
+ gt_body = V"gt_row"^1,
+
+ gt_row = (V"gt_contentrow" - V"gt_bodysep")^1
+ * Cmt(V"gt_bodysep", function(s,i,str)print(str)return true end),
+
+ gt_bodysep = V"gt_matchindent"
+ * Cmt(V"table_intersection"
+ * (V"table_hline"^1 * V"table_intersection")^1, function(s, i, separator)
+ warn("tab-s", #separator, #separator == tracklists.currentlayout.length, "",i)
+ local l = {}
+ for n, dimension in ipairs(string.explode(separator, "++")) do
+ l[n] = #dimension
+ end
+ l["length"] = #separator
+ --return l == tracklists.currentlayout
+ return l.length == tracklists.currentlayout.length
+ end)
+ * V"eol"
+ ,
+
+ gt_head = V"gt_contentrow"^1
+ * Cmt(V"gt_headsep", function(s,i,str)print(str)return true end)
+ ,
+
+ gt_headsep = V"gt_matchindent"
+ * V"table_intersection"
+ * (V"table_header_hline"^1 * V"table_intersection")^1
+ * V"eol"
+ ,
+
+
+--------------------------------------------------------------------------------
-- Block quotes
--------------------------------------------------------------------------------
@@ -997,9 +1114,14 @@ local parser = P{
angle_right = P">",
enclosed_open = S[['"([{<]],
enclosed_close = S[['")]}>]],
+
+ table_intersection = P"+",
+ table_hline = V"dash",
+ table_vline = V"bar",
+ table_header_hline = P"=",
}
-f = io.open("blockquote.rst", "r")
+f = io.open("table.rst", "r")
testdata = f:read("*all")
f:close()