Parse log file

This commit is contained in:
Marcel Fabian Krüger 2021-05-30 03:29:50 +02:00
parent 483ab6a572
commit ba4b30d49b

View File

@ -1,6 +1,35 @@
require'emulated_nodes'
local convert = require'luamml-convert'
local mappings = require'luamml-legacy-mappings'
local to_xml = require'luamml-xmlwriter'
convert.register_family(1, mappings.oml)
convert.register_family(2, mappings.oms)
convert.register_family(3, mappings.omx)
local parse_showlists = require'parse_showlists' local parse_showlists = require'parse_showlists'
local l = lpeg or require'lpeg' local l = lpeg or require'lpeg'
local line = (1-l.P'\n')^0 * '\n'
local Cline = l.C((1-l.P'\n')^0) * '\n'
local list_block = (l.C(l.S'\\._^/ps' * (1-l.P'\n')^0)^-1 * '\n')^0
local math_lists_block = l.Ct('### ' * l.Cg(l.C'display' * ' ', 'display')^-1 * 'math mode entered at line ' * l.Cg(l.R'09'^1 / tonumber, 'line') * '\n'
* list_block)^1
local generic_list_block = '### ' * line * list_block
local luamml_block = l.Ct('LUAMML_META_BEGIN\n\n'
* (math_lists_block + generic_list_block/0)^0
* (line - 'LUAMML_META_END\n')^0
* 'LUAMML_META_END\n')
local math_lists = (function()
local f = assert(io.open(arg[1], 'r'))
local content = f:read'a'
f:close()
-- The following does *not* end with * -1 since we want to allow the last line to not end with \n.
-- In that case we ignore the last line, but that's safe since the last line never contains our markers.
local log_file = l.Ct((luamml_block + line)^0)
return log_file:match(content)
end)()
local lines = l.Ct((l.C((1-l.P'\n')^0) * '\n')^0 * l.C(l.P(1)^1)^-1):match( local lines = l.Ct((l.C((1-l.P'\n')^0) * '\n')^0 * l.C(l.P(1)^1)^-1):match(
[[\mathinner [[\mathinner
.\left"28300 .\left"28300
@ -18,62 +47,134 @@ local lines = l.Ct((l.C((1-l.P'\n')^0) * '\n')^0 * l.C(l.P(1)^1)^-1):match(
._.\fam1 = ._.\fam1 =
._\mathord ._\mathord
._.\fam0 2 ._.\fam0 2
.\mathchoice
.D\mathord
.D.\fam1 d
.D\mathord
.D.\fam1 i
.D\mathord
.D.\fam1 s
.D\mathord
.D.\fam1 p
.D\mathord
.D.\fam1 l
.D\mathord
.D.\fam1 a
.D\mathord
.D.\fam1 y
.D\scriptstyle
.D\mathord
.D.\fam1 a
.D\mathord
.D.\fam1 b
.D\mathord
.D.\fam1 c
.T\mathord
.T.\fam1 t
.T\mathord
.T.\fam1 e
.T\mathord
.T.\fam1 x
.T\mathord
.T.\fam1 t
.T\scriptscriptstyle
.T\mathord
.T.\fam1 a
.T\mathord
.T.\fam1 b
.T\mathord
.T.\fam1 c
.S\mathord
.S.\fam1 s
.S\mathord
.S.\fam1 c
.S\mathord
.S.\fam1 r
.S\mathord
.S.\fam1 i
.S\mathord
.S.\fam1 p
.S\mathord
.S.\fam1 t
.S\textstyle
.S\mathord
.S.\fam1 a
.S\mathord
.S.\fam1 b
.S\mathord
.S.\fam1 c
.s\mathord
.s.\fam1 s
.s\mathord
.s.\fam1 c
.s\mathord
.s.\fam1 r
.s\mathord
.s.\fam1 i
.s\mathord
.s.\fam1 p
.s\mathord
.s.\fam1 t
.s\mathord
.s.\fam1 s
.s\mathord
.s.\fam1 c
.s\mathord
.s.\fam1 r
.s\mathord
.s.\fam1 i
.s\mathord
.s.\fam1 p
.s\mathord
.s.\fam1 t
.s\displaystyle
.s\mathord
.s.\fam1 a
.s\mathord
.s.\fam1 b
.s\mathord
.s.\fam1 c
.\mathbin .\mathbin
..\fam0 + ..\fam0 +
.\accent\fam0 _ .\accent\fam0 _
..\fam1 z ..\fam1 z
._\fam0 0 ._\fam0 0
.\middle"26A30C .\right"29301
.\mathrel \mathrel
..\fam0 = .\fam0 =
.\mathop\limits \mathop\nolimits
..\fam3 P .\fam3 P
.\mathop\nolimits ^\fam0 1
..\fam3 P _\mathord
.\mathop _.\fam1 i
..\fam3 P _\mathrel
.^\mathord _.\fam0 =
.^.\fam0 1 _\mathord
.^\mathord _.\fam0 1
.^.\fam0 0 \mathord
.^\mathord .\fraction, thickness = default
.^.\fam0 0 .\\mathbin
.^\mathord .\.\fam2 ^^@
.^.\fam0 0 .\\mathord
._\mathord .\.\fam1 p
._.\fam1 i .\\mathbin
._\mathrel .\.\fam2 ^^F
._.\fam0 = .\\radical"270370
._\mathord .\.\mathord
._.\fam0 1 .\..\fam1 p
.\mathord .\.\mathbin
..\fraction, thickness = default .\..\fam2 ^^@
..\\mathbin .\.\mathord
..\.\fam2 ^^@ .\..\fam0 4
..\\mathord .\.\mathord
..\.\fam1 p .\..\fam1 q
..\\mathbin ./\mathord
..\.\fam2 ^^F ./.\fam0 2
..\\radical"270370
..\.\mathord
..\..\fam1 p
..\.\mathbin
..\..\fam2 ^^@
..\.\mathord
..\..\fam0 4
..\.\mathord
..\..\fam1 q
../\mathord
../.\fam0 2
.\right"0
]]) ]])
local parsed = parse_showlists(lines) for i, block in ipairs(math_lists) do
require'emulated_nodes' block = block[1]
local convert = require'luamml-convert' local parsed = parse_showlists(block)
local mappings = require'luamml-legacy-mappings' local style = block.display and 0 or 2
convert.register_family(1, mappings.oml) print(to_xml(convert.make_root(convert.process(parsed, style), style)))
convert.register_family(2, mappings.oms) end
convert.register_family(3, mappings.omx)
local to_xml = require'luamml-xmlwriter'
print(to_xml(convert.make_root(convert.process(parsed), 2)))