summaryrefslogtreecommitdiff
path: root/rst_parser.lua
diff options
context:
space:
mode:
Diffstat (limited to 'rst_parser.lua')
-rw-r--r--rst_parser.lua58
1 files changed, 39 insertions, 19 deletions
diff --git a/rst_parser.lua b/rst_parser.lua
index d68645f..cc4304d 100644
--- a/rst_parser.lua
+++ b/rst_parser.lua
@@ -16,7 +16,7 @@ rst = require "rst_context"
helpers = require "rst_helpers"
-local rst_debug = false
+local rst_debug = true
local warn = function(str, ...)
if not rst_debug then return false end
@@ -281,10 +281,6 @@ local parser = P{
gt_body = ((V"gt_contentrow" - V"gt_bodysep")^1 * V"gt_bodysep")^1,
- --gt_row = (V"gt_contentrow" - V"gt_bodysep")^1
- --* C(V"gt_bodysep")
- --,
-
gt_bodysep = V"gt_matchindent"
* C(Cmt(V"table_intersection"
* (V"table_hline"^1 * V"table_intersection")^1, function(s, i, separator)
@@ -524,7 +520,6 @@ local parser = P{
* V"eol",
option_desc_more = V"space"^2
- --* V"rest_of_line"
* (1 - V"eol")^1
* V"eol"
* V"indented_lines"
@@ -688,7 +683,6 @@ local parser = P{
end
return false
end)
- --* V"bullet_indent" / rst.startitemize,
* Cs(V"bullet_indent") / rst.startitemize,
bullet_indent = V"space"^0 * V"bullet_expr" * V"space"^1,
@@ -808,7 +802,7 @@ local parser = P{
return a == b
end),
- target_link = ( V"space"^0 * V"target_firstindent" -- * C((1 - V"eol")^1) * V"eol")
+ target_link = ( V"space"^0 * V"target_firstindent"
* Ct(C(1 - V"whitespace" - V"eol")^1
* (V"target_indentmatch"
* C(1 - V"whitespace" - V"eol")^1)^0)
@@ -840,7 +834,6 @@ local parser = P{
* Ct(C((1 - V"eol")^1) * V"eol"
* (V"par_matchindent" * C((1 - V"eol")^1) * V"eol")^0)
* V"blank_line"^1
- --* V"endpar"
/ rst.paragraph,
par_setindent = Cmt(V"space"^0, function (s, i, indent)
@@ -1048,15 +1041,42 @@ local parser = P{
table_header_hline = P"=",
}
-f = io.open("inlinefmt.rst", "r")
-testdata = f:read("*all")
-f:close()
+local function load_file (name)
+ f = assert(io.open(name, "r"), "Not a file!")
+ if not f then return 1 end
+ local tmp = f:read("*all")
+ f:close()
+ return tmp
+end
+
+local function save_file (name, data)
+ f = assert(io.open(name, "w"), "Could not open file "..name.." for writing! Check its permissions")
+ if not f then return 1 end
+ f:write(data)
+ f:close()
+ return 0
+end
+
+local function main()
+ local testdata = load_file(arg[1])
+ if testdata == 1 then return 1 end
-print(parser:match(testdata))
---print(">>>Last used char>: " ..tracklists.lastbullet.." <<<<")
---print(">>>Max list nestin>: "..tracklists.bullets.max .." <<<<")
+ local processeddata = parser:match(testdata)
+
+ if processeddata then
+ save_file(arg[2], processeddata)
+ else
+ return 1
+ end
+
+ --print(">>>Last used char>: " ..tracklists.lastbullet.." <<<<")
+ --print(">>>Max list nestin>: "..tracklists.bullets.max .." <<<<")
+
+ --for i,j in next, rst.collected_references do
+ --print (string.format("== %7s => %s <=", i,j))
+ --end
+ --parser:print()
+ return 0
+end
---for i,j in next, rst.collected_references do
- --print (string.format("== %7s => %s <=", i,j))
---end
---parser:print()
+return main()