7 module("yu",package
.seeall
)
11 local function fixpath(p
)
12 p
=string.gsub(p
,'\\','/')
16 local function extractDir(p
)
18 return string.match(p
, ".*/")
21 local function extractFileName(p
)
23 return string.match(p
, "[%w_.%%]+$")
26 local function extractModName(p
)
28 p
=string.gsub(p
,'%.lx$','')
29 return string.gsub(p
,'%.','_')
33 function newBuilder(option
)
41 function builder
:build(path
)
42 self
.baseDir
=extractDir(path
)
43 local m
=self
:requireModule(path
)
44 for i
,mm
in ipairs(self
.buildingModules
) do
45 local res
=yu
.newResolver()
46 -- print('---------resolving module:',mm.path)
52 function builder
:getAbsPath(path
)
56 function builder
:buildModule(path
)
57 local m
=parseFile(path
)
60 m
.name
=extractModName(path
)
61 self
.moduleTable
[path
]=m
64 local currentBase
=extractDir(path
)
65 -- print('---------collecting module:',path)
67 for i
,node
in ipairs(heads
) do
70 local modpath
=currentBase
..node
.src
71 local requiredModule
=self
:requireModule(modpath
)
72 if m
==requiredModule
then
73 --todo:error 'import self'
74 yu
.compileErr('attempt to import self',node
,m
)
76 m
.externModules
[requiredModule
.path
]=requiredModule
77 node
.mod=requiredModule
82 yu
.newDeclCollector():visitNode(m
)
83 -- yu.newResolver():visitNode(m)
84 self
:addBuildingModule(m
)
88 function builder
:addBuildingModule(m
)
89 local b
=self
.buildingModules
90 for i
,v
in ipairs(b
) do
91 if v
==m
then return end
96 function builder
:requireModule(path
)
98 --todo:unify path format
99 local m
=self
.moduleTable
[path
]
101 --todo:search for precompiled module first
102 m
=self
:buildModule(path
)