-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.lua
69 lines (64 loc) · 1.85 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require "globals"
local token = require "token"
local block = require "parser.block"
local paragraph = require "parser.paragraph"
local list = require "parser.list"
_G.grammar = {
"Doc",
Doc = Ct(choice {
V "Block",
(whitespace + line_ending),
} ^ 0) / token.pandoc,
Block = choice {
V "standard_ranged_tag",
V "verbatim_ranged_tag",
V "detached_modifier",
V "delimiting_mod",
V "Para" * line_ending,
},
Heading = block.heading,
list = V "UnorderedList" + V "OrderedList",
quote = list.quote,
UnorderedList = list.unordered_list,
OrderedList = list.ordered_list,
detached_modifier = choice {
-- structural
V "Heading",
-- nestable
V "list",
V "quote",
-- range-able
V "definition",
V "footnote",
V "table_cells",
},
ParaSeg = paragraph.inline_segment,
Para = paragraph.inline / token.para,
verbatim_ranged_tag = block.verbatim_ranged_tag,
standard_ranged_tag = block.standard_ranged_tag,
definition = block.definition_list,
footnote = block.footnote,
table_cells = block.table_cells,
delimiting_mod = choice {
block.week_delimiting_mod,
block.strong_delimiting_mod,
block.horizontal_rule,
},
_paragraph = paragraph.inline,
}
-- _G.grammar = require("src.pegdebug").trace(grammar)
G = P(grammar)
function Reader(input, _reader_options)
print "============[INPUT:]============"
print(input)
print "============[PARSE:]============"
local match = lpeg.match(G, tostring(input))
-- local match = pandoc.Pandoc {
-- pandoc.Para {
-- pandoc.RawInline("pdf", "HEADING"),
-- pandoc.RawInline("html", "<h1>heading</h1>"),
-- },
-- }
print "============[RESULT]============"
return match
end