summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rst_context.lua13
-rw-r--r--rst_parser.lua49
2 files changed, 60 insertions, 2 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 57725ed..528ecdf 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -391,4 +391,17 @@ function rst_context.option_item (tab)
]], tab[1], tab[2])
end
+function rst_context.literal_block (str)
+ local stop = P"\n"^0 * -P(1) -- remove trailing blank lines
+ local rstrip = C((1 - stop)^1) * stop
+ str = rstrip:match(str)
+ return [[
+
+\\starttyping[lines=hyphenated]
+]] .. str .. [[
+
+\\stoptyping
+]]
+end
+
return rst_context
diff --git a/rst_parser.lua b/rst_parser.lua
index 7b739bd..470b789 100644
--- a/rst_parser.lua
+++ b/rst_parser.lua
@@ -196,11 +196,51 @@ local parser = P{
+ V"comment"
+ Cs(V"section") / rst.escape
+ Cs(V"transition") --/ rst.escape
+ + V"literal_block"
+ Cs(V"list") / rst.escape
+ Cs(V"paragraph") / rst.escape
,
--------------------------------------------------------------------------------
+-- Literal blocks
+--------------------------------------------------------------------------------
+
+ literal_block = V"literal_block_marker"
+ * Cs(V"literal_block_lines"
+ * (V"blank_line"^1 * V"literal_block_lines")^0)
+ * V"blank_line"^0
+ / rst.literal_block,
+
+ literal_block_marker = V"double_colon" * V"eol" * V"blank_line",
+
+ literal_block_lines = V"literal_block_first"
+ * (V"literal_block_other"
+ - V"blank_line")^0,
+
+ literal_block_first = Cmt(V"space"^1, function (s, i, indent)
+ warn("lbk-f", #indent, "", "", i)
+ if not indent or
+ indent == "" then
+ return false
+ end
+ tracklists.currentindent = indent
+ return true
+ end)
+ * V"rest_of_line"
+ * V"eol",
+
+ literal_block_other = Cmt(V"space"^1, function (s, i, indent)
+ warn("lbk-m",
+ #indent,
+ #tracklists.currentindent,
+ #indent >= #tracklists.currentindent,
+ i)
+ return #indent >= #tracklists.currentindent
+ end)
+ * V"rest_of_line"
+ * V"eol",
+
+--------------------------------------------------------------------------------
-- Lists
--------------------------------------------------------------------------------
@@ -247,7 +287,9 @@ local parser = P{
+ V"option_dos_vms")
* V"option_arg"^-1,
- option_arg = (V"equals" + V"space") * V"letter"^1,
+ option_arg = (V"equals" + V"space")
+ * ((V"letter" * (V"letter" + V"digit")^1)
+ + (V"angle_left" * (1 - V"angle_right")^1 * V"angle_right")),
option_posixshort = V"dash" * (V"letter" + V"digit"),
@@ -697,6 +739,7 @@ local parser = P{
comma = P",",
colon = P":",
+ double_colon = V"colon" * V"colon",
escaped_colon = V"backslash" * V"colon",
dot = P".",
double_dot = V"dot" * V"dot",
@@ -737,11 +780,13 @@ local parser = P{
Roman_numeral = S"IVXLCDM"^1,
inline_delimiter = P"**" + P"``" + S"*`",
+ angle_left = P"<",
+ angle_right = P">",
enclosed_open = S[['"([{<]],
enclosed_close = S[['")]}>]],
}
-f = io.open("option_lists.rst", "r")
+f = io.open("litblock.rst", "r")
testdata = f:read("*all")
f:close()