summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rst_context.lua17
-rw-r--r--rst_parser.lua90
2 files changed, 90 insertions, 17 deletions
diff --git a/rst_context.lua b/rst_context.lua
index ee943ab..8913fb9 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -418,4 +418,21 @@ function rst_context.literal_block (str)
]]
end
+function rst_context.line_block (str)
+ return [[
+
+\\startlines
+]] .. str .. [[\\stoplines
+]]
+end
+
+function rst_context.line_block_line(str)
+ str = str:gsub("\n", " ")
+ return str .. "\n"
+end
+
+function rst_context.line_block_empty()
+ return "\n"
+end
+
return rst_context
diff --git a/rst_parser.lua b/rst_parser.lua
index 2aa4e38..075ff29 100644
--- a/rst_parser.lua
+++ b/rst_parser.lua
@@ -194,6 +194,7 @@ local parser = P{
block = V"target_block"
+ V"comment"
+ + V"line_block"
+ Cs(V"section") / rst.escape
+ Cs(V"transition") --/ rst.escape
+ V"literal_block"
@@ -202,16 +203,65 @@ local parser = P{
,
--------------------------------------------------------------------------------
--- Literal blocks
+-- Line blocks
--------------------------------------------------------------------------------
- literal_block = V"unquoted_literal_block"
- + V"quoted_literal_block",
+ line_block = Cs(V"line_block_first"
+ * (V"line_block_other"
+ + V"line_block_empty")^1)
+ * V"blank_line"
+ / rst.line_block
+ ,
+
+ line_block_marker = V"space"^0 * V"bar" * V"space",
+
+ line_block_empty_marker = V"space"^0 * V"bar" * V"space"^0 * V"eol",
+
+
+ line_block_first = Cmt(V"line_block_marker", function(s, i, marker)
+ warn("lbk-i", #marker, "", marker, "", i)
+ tracklists.currentindent = marker
+ return true
+ end) / ""
+ * V"line_block_line"
+ ,
+
+ line_block_empty = Cmt(V"line_block_empty_marker", function(s, i, marker)
+ warn("lbk-e", #marker, #tracklists.currentindent, marker, tracklists.currentindent, i)
+ marker = marker:gsub("|.*", "| ")
+ return tracklists.currentindent == marker
+ end) / ""
+ / rst.line_block_empty
+ ,
+
+ line_block_other = Cmt(V"line_block_marker", function(s, i, marker)
+ warn("lbk-m", #marker, #tracklists.currentindent, marker, tracklists.currentindent, i)
+ return tracklists.currentindent == marker
+ end) / ""
+ * V"line_block_line"
+ ,
+
+ line_block_line = Cs(V"text_elements"^1
+ * V"line_block_cont"^0
+ * V"eol")
+ / rst.line_block_line
+ ,
+
+ line_block_cont = (V"eol" - V"line_block_marker")
+ * Cmt(V"space"^1, function(s, i, spaces)
+ warn("lbk-c", #spaces, #tracklists.currentindent, spaces, tracklists.currentindent, i)
+ return #spaces >= #tracklists.currentindent
+ end) / ""
+ * V"text_elements"^1
+ ,
--------------------------------------------------------------------------------
--- Quoted literal blocks
+-- Literal blocks
--------------------------------------------------------------------------------
+ literal_block = V"unquoted_literal_block"
+ + V"quoted_literal_block",
+
literal_block = V"literal_block_marker"
* Cs(V"literal_block_lines"
* (V"blank_line"^1 * V"literal_block_lines")^0)
@@ -296,7 +346,7 @@ local parser = P{
/rst.option_list,
option_list_item = Ct(C(V"option_group")
- * C(V"option_description"))
+ * Cs(V"option_description"))
/ rst.option_item,
option_description = V"option_desc_next"
@@ -304,17 +354,20 @@ local parser = P{
+ V"option_desc_single",
option_desc_single = V"space"^2
- * V"rest_of_line"
+ --* V"rest_of_line"
+ * V"text_elements"^1
* V"eol",
option_desc_more = V"space"^2
- * V"rest_of_line"
+ --* V"rest_of_line"
+ * V"text_elements"^1
* V"eol"
* V"indented_lines"
* (V"blank_line" * V"indented_lines")^0,
option_desc_next = V"eol"
- * V"indented_lines",
+ * V"indented_lines"
+ * (V"blank_line" * V"indented_lines")^0,
option_group = V"option"
* (V"comma" * V"space" * V"option")^0,
@@ -356,7 +409,7 @@ local parser = P{
field_name = (V"escaped_colon" + (1 - V"colon"))^1,
- field_body = C(V"rest_of_line" * V"eol"
+ field_body = C(V"text_elements"^1 * V"eol"
* V"indented_lines"^-1),
--------------------------------------------------------------------------------
@@ -620,15 +673,17 @@ local parser = P{
--paragraph = -(V"double_dot" + V"double_underscore") -- + V"bullet_indent")
paragraph = -V"punctuation"
- * Cs((V"included_literal_block"
+ * Cs((V"text_elements" + (V"eol" - V"endpar"))^1)
+ * V"endpar"
+ / rst.paragraph,
+
+ text_elements = V"included_literal_block"
+ V"enclosed_inline"
+ V"inline_elements"
+ V"word"
+ V"punctuation"
- + (V"eol" - V"endpar")
- + V"spacing")^1)
- * V"endpar"
- / rst.paragraph,
+ + V"spacing"
+ ,
-- Ignore single occurences of inline markup delimiters in certain
-- environments.
@@ -749,14 +804,14 @@ local parser = P{
tracklists.currentindent = indent
return true
end)
- * V"rest_of_line"
+ * V"text_elements"^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"rest_of_line"
+ * V"text_elements"^1
* V"eol",
--------------------------------------------------------------------------------
@@ -787,6 +842,7 @@ local parser = P{
doubleslash = V"slash" * V"slash",
backslash = P"\\",
+ bar = P"|",
groupchars = S"()[]{}",
@@ -880,7 +936,7 @@ local parser = P{
enclosed_close = S[['")]}>]],
}
-f = io.open("litblock.rst", "r")
+f = io.open("option_lists.rst", "r")
testdata = f:read("*all")
f:close()