forked from thenumbernine/lua-parser
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_xform.lua
More file actions
Latest commit
42 lines (35 loc) · 1.03 KB
/
Copy pathload_xform.lua
File metadata and controls
42 lines (35 loc) · 1.03 KB
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
-- parser.load_xorm uses ext.load to modify the load(), loadfile() and require() functions
--DEBUG: local showcode = require 'template.showcode'
localLuaParser=require'parser.lua.parser'
localcallbacks=setmetatable({}, {__index=table})
localstate=require'ext.load'()
callbacks.state=state
state.xforms:insert(function(d, source)
--DEBUG: print()
--DEBUG: print(debug.traceback())
--DEBUG: print'!!! BEFORE PARSE !!!'
--DEBUG: print('parser.load_xform source: '..source)
--DEBUG: print(showcode(d))
--DEBUG: print()
localparser=LuaParser()
localsuccess, msg=parser:setData(d, source)
ifnotsuccessthen
ifparser.tthen
msg=parser.t:getpos()..': '..msg
end
returnnil, msg
end
localtree=parser.tree
for_,cbinipairs(callbacks) do
cb(tree, source)
end
localcode=tree:toLua()
--DEBUG: print()
--DEBUG: print(debug.traceback())
--DEBUG: print'!!! AFTER PARSE !!!'
--DEBUG: print('parser.load_xform source: '..source)
--DEBUG: print(showcode(code))
--DEBUG: print()
returncode
end)
returncallbacks