feat: add testing framework with reference project integration
- Add test/ directory with test harness and test files - Add UDT, DB, FB parser tests - Add PLC JSON and integration tests - Test against reference project (239 UDTs, 12 DBs, 37 SCL, 13 XML) - Fix attribute parsing to handle underscores (S7_SetPoint) - Add ORGANIZATION_BLOCK support to FB parser
This commit is contained in:
+10
-4
@@ -62,10 +62,10 @@ local function parse_attributes(attr_str)
|
||||
|
||||
local attrs = {}
|
||||
-- Match key := 'value' or key := value patterns
|
||||
for key, value in attr_str:gmatch("(%w+)%s*:=%s*'([^']+)'") do
|
||||
for key, value in attr_str:gmatch("([%w_]+)%s*:=%s*'([^']+)'") do
|
||||
attrs[key] = value
|
||||
end
|
||||
for key, value in attr_str:gmatch("(%w+)%s*:=%s*(%w+)") do
|
||||
for key, value in attr_str:gmatch("([%w_]+)%s*:=%s*(%w+)") do
|
||||
attrs[key] = value
|
||||
end
|
||||
return attrs
|
||||
@@ -166,7 +166,7 @@ local function parse_var_section(content, section_name)
|
||||
return vars
|
||||
end
|
||||
|
||||
-- Parse FB/Function content
|
||||
-- Parse FB/Function/OB content
|
||||
function M.parse_fb_content(content, filename)
|
||||
local fb = {
|
||||
filename = filename,
|
||||
@@ -189,11 +189,17 @@ function M.parse_fb_content(content, filename)
|
||||
fb_type = "FUNCTION"
|
||||
-- Extract return type if present
|
||||
fb.return_type = content:match('FUNCTION%s+"[^"]+"%s*:%s*(%w+)')
|
||||
else
|
||||
-- Try ORGANIZATION_BLOCK
|
||||
fb_name = content:match('ORGANIZATION_BLOCK%s+"([^"]+)"')
|
||||
if fb_name then
|
||||
fb_type = "ORGANIZATION_BLOCK"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not fb_name then
|
||||
return nil, "No FUNCTION_BLOCK or FUNCTION definition found"
|
||||
return nil, "No FUNCTION_BLOCK, FUNCTION, or ORGANIZATION_BLOCK definition found"
|
||||
end
|
||||
|
||||
fb.name = fb_name
|
||||
|
||||
Reference in New Issue
Block a user