summaryrefslogtreecommitdiff
path: root/rst_parser.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-07 18:32:22 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-07 18:32:22 +0200
commitd7996cadc2e117cc163291abe953dec15cee6826 (patch)
treef6fc5aedfa5a9e2056140e42b16c92c8e2a1f3ec /rst_parser.lua
parentf87e85ad1dd07bfb4f3c07f2571f5af6401733c9 (diff)
downloadcontext-rst-d7996cadc2e117cc163291abe953dec15cee6826.tar.gz
revised table implementation. helper module.
Diffstat (limited to 'rst_parser.lua')
-rw-r--r--rst_parser.lua135
1 files changed, 62 insertions, 73 deletions
diff --git a/rst_parser.lua b/rst_parser.lua
index 6630767..343b45c 100644
--- a/rst_parser.lua
+++ b/rst_parser.lua
@@ -11,11 +11,12 @@
--------------------------------------------------------------------------------
--
-require "lpeg"
+--require "lpeg"
rst = require "rst_context"
+helpers = require "rst_helpers"
-local rst_debug = true
+local rst_debug = false
local warn = function(str, ...)
if not rst_debug then return false end
@@ -54,7 +55,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
+tracklists.currentwidth = 0-- table layout
local enclosed_mapping = {
["'"] = "'",
@@ -221,16 +222,18 @@ local parser = P{
-- Grid table
--------------------------------------------------------------------------------
- grid_table = Cs(V"gt_first_row"
+ grid_table = Ct(V"gt_first_row"
* V"gt_other_rows")
* V"blank_line"^1
- / rst.grid_table
+ --/ rst.grid_table
+ / function(tab)
+ return rst.grid_table(helpers.table.create(tab))
+ end
,
gt_first_row = V"gt_setindent"
- * V"gt_setlayout"
+ * C(V"gt_sethorizontal")
* V"eol"
- / ""
,
--gt_setindent = Cg(V"space"^0, "tableindent"),
@@ -243,18 +246,12 @@ local parser = P{
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_sethorizontal = Cmt(V"gt_layoutmarkers"^3, function (s, i, width)
+ warn("tab-h", "width", "true", #width, "set", i)
+ tracklists.currentwidth = #width
+ return true
+ end)
+ ,
gt_other_rows = V"gt_head"^-1
* V"gt_body"
@@ -262,63 +259,55 @@ local parser = P{
--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)
- ,
+ local matchme = tracklists.currentindent
+ warn("tab-m", "indent", #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_cell = (V"gt_content_cell" + V"gt_line_cell")
+ * (V"table_intersection" + V"table_vline")
+ ,
- gt_content_cell = (V"table_vline" + V"table_intersection")
- * C((1 - V"table_vline" - V"table_intersection" - V"eol")^1),
+ gt_content_cell = ((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_line_cell = 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_contentrow = V"gt_matchindent"
+ * C((V"table_intersection" + V"table_vline")
+ * V"gt_cell"^1)
+ * V"whitespace"^-1 * V"eol"
,
- gt_body = V"gt_row"^1,
+ gt_body = ((V"gt_contentrow" - V"gt_bodysep")^1 * V"gt_bodysep")^1,
- gt_row = (V"gt_contentrow" - V"gt_bodysep")^1
- * Cmt(V"gt_bodysep", function(s,i,str)print(str)return true end),
+ --gt_row = (V"gt_contentrow" - V"gt_bodysep")^1
+ --* C(V"gt_bodysep")
+ --,
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"
+ * C(Cmt(V"table_intersection"
+ * (V"table_hline"^1 * V"table_intersection")^1, function(s, i, separator)
+ local matchme = tracklists.currentwidth
+ warn("tab-m", "body", #separator == matchme, #separator, matchme, i)
+ return #separator == matchme
+ end))
+ * V"whitespace"^-1 * V"eol"
,
gt_head = V"gt_contentrow"^1
- * Cmt(V"gt_headsep", function(s,i,str)print(str)return true end)
+ * V"gt_headsep"
,
gt_headsep = V"gt_matchindent"
- * V"table_intersection"
- * (V"table_header_hline"^1 * V"table_intersection")^1
- * V"eol"
+ * C(Cmt(V"table_intersection"
+ * (V"table_header_hline"^1 * V"table_intersection")^1, function(s, i, separator)
+ local matchme = tracklists.currentwidth
+ warn("tab-s", "head", #separator == matchme, #separator, matchme, i)
+ return #separator == matchme
+ end))
+ * V"whitespace"^-1 * V"eol"
,
@@ -341,7 +330,7 @@ local parser = P{
return true
end) / ""
* -V"attrib_dash"
- * V"text_elements"^1
+ * V"text_element"^1
* V"eol"
,
@@ -351,7 +340,7 @@ local parser = P{
return tracklists.currentindent == indent
end) / ""
* -V"attrib_dash"
- * V"text_elements"^1
+ * V"text_element"^1
* V"eol"
,
@@ -366,7 +355,7 @@ local parser = P{
t.currentindent = ret and indent or t.currentindent
return ret
end) / ""
- * V"text_elements"^1
+ * V"text_element"^1
* V"eol"
,
@@ -375,7 +364,7 @@ local parser = P{
indent, tracklists.currentindent, i)
return utf.len(tracklists.currentindent) == #indent
end) / ""
- * V"text_elements"^1
+ * V"text_element"^1
* V"eol"
,
@@ -418,7 +407,7 @@ local parser = P{
* V"line_block_line"
,
- line_block_line = Cs(V"text_elements"^1
+ line_block_line = Cs(V"text_element"^1
* V"line_block_cont"^0
* V"eol")
/ rst.line_block_line
@@ -429,7 +418,7 @@ local parser = P{
warn("lbk-c", #spaces, #tracklists.currentindent, spaces, tracklists.currentindent, i)
return #spaces >= #tracklists.currentindent
end) / ""
- * V"text_elements"^1
+ * V"text_element"^1
,
--------------------------------------------------------------------------------
@@ -532,12 +521,12 @@ local parser = P{
option_desc_single = V"space"^2
--* V"rest_of_line"
- * V"text_elements"^1
+ * V"text_element"^1
* V"eol",
option_desc_more = V"space"^2
--* V"rest_of_line"
- * V"text_elements"^1
+ * V"text_element"^1
* V"eol"
* V"indented_lines"
* (V"blank_line" * V"indented_lines")^0,
@@ -586,7 +575,7 @@ local parser = P{
field_name = (V"escaped_colon" + (1 - V"colon"))^1,
- field_body = C(V"text_elements"^1 * V"eol"
+ field_body = C(V"text_element"^1 * V"eol"
* V"indented_lines"^-1),
--------------------------------------------------------------------------------
@@ -850,11 +839,11 @@ local parser = P{
--paragraph = -(V"double_dot" + V"double_underscore") -- + V"bullet_indent")
paragraph = -V"punctuation"
- * Cs((V"text_elements" + (V"eol" - V"endpar"))^1)
+ * Cs((V"text_element" + (V"eol" - V"endpar"))^1)
* V"endpar"
/ rst.paragraph,
- text_elements = V"included_literal_block"
+ text_element = V"included_literal_block"
+ V"enclosed_inline"
+ V"inline_elements"
+ V"word"
@@ -981,14 +970,14 @@ local parser = P{
tracklists.currentindent = indent
return true
end)
- * V"text_elements"^1
+ * V"text_element"^1
* V"eol",
indented_other = Cmt(V"space"^1, function (s, i, indent)
warn("idt-m", indent, tracklists.currentindent, indent == tracklists.currentindent, i)
return indent == tracklists.currentindent
end)
- * V"text_elements"^1
+ * V"text_element"^1
* V"eol",
--------------------------------------------------------------------------------