@@ -371,29 +371,31 @@ end
371371---- ---------------------------------------------------------------------------
372372
373373---
374- -- Provide API Model elements from string describing global elements
375- -- such as:
374+ -- Build a global var from string such as:
376375-- * `global#foo`
377376-- * `foo#global.bar`
377+ -- @param #string str
378378local globals = function (str )
379379 -- Handling globals from modules
380- for modulename , fieldname in str :gmatch (' ([%a%.%d_]+)#global%.([%a%.%d_]+)' ) do
380+ local modulename , fieldname = str :gmatch (' ([%a%.%d_]+)#global%.([%a%.%d_]+)' )()
381+ if modulename and fieldname then
381382 local item = apimodel ._item (fieldname )
382383 local file = apimodel ._file ()
383384 file .name = modulename
384385 file :addglobalvar ( item )
385386 return item
386387 end
387388 -- Handling other globals
388- for name in str :gmatch (' global#([%a%.%d_]+)' ) do
389- -- print("globale", name)
389+ local name = str :gmatch (' global#([%a%.%d_]+)' )()
390+ if name then
390391 return apimodel ._externaltypref (' global' , name )
391392 end
392393 return nil
393394end
394395
395396---
396- -- Transform a string like `module#(type).field` in an API Model item
397+ -- Build an external field from string like `module#(type).field`
398+ -- @param #string str
397399local field = function ( str )
398400
399401 -- Match `module#type.field`
@@ -427,26 +429,34 @@ local field = function( str )
427429end
428430
429431---
430- -- Build an API internal reference from a string like: `#typeref`
431- local internal = function ( typestring )
432- for name in typestring :gmatch (' #([%a%.%d_]+)' ) do
433- -- Do not handle this name is it starts with reserved name "global"
434- if name :find (" global." ) == 1 then return nil end
435- return apimodel ._internaltyperef (name )
432+ -- Build an API internal reference from a string like: `#typeref` or #(type.ref)
433+ -- @param #string str
434+ local internal = function ( str )
435+ local typename = str :gmatch (' #([%a%.%d_]+)' )()
436+ if not typename then
437+ typename = str :gmatch (' #%(([%a%.%d_]+)%)' )()
438+ if not typename then
439+ -- No match
440+ return nil
441+ end
436442 end
437- return nil
443+
444+ -- Do not handle this name is it starts with reserved name "global"
445+ if typename :find (" global." ) == 1 then return nil end
446+ return apimodel ._internaltyperef (typename )
438447end
439448
440449---
441450-- Build an API external reference from a string like: `mod.ule#type`
442- local extern = function (type )
451+ -- @param #string str
452+ local extern = function (str )
443453
444454 -- Match `mod.ule#ty.pe`
445- local modulename , typename = type :gmatch (' ([%a%.%d_]+)#([%a%.%d_]+)' )()
455+ local modulename , typename = str :gmatch (' ([%a%.%d_]+)#([%a%.%d_]+)' )()
446456
447457 -- Trying `mod.ule#(ty.pe)`
448458 if not modulename then
449- modulename , typename = type :gmatch (' ([%a%.%d_]+)#%(([%a%.%d_]+)%)' )()
459+ modulename , typename = str :gmatch (' ([%a%.%d_]+)#%(([%a%.%d_]+)%)' )()
450460
451461 -- No match at all
452462 if not modulename then
@@ -457,9 +467,11 @@ local extern = function (type)
457467end
458468
459469---
460- -- Build an API external reference from a string like: `mod.ule`
461- local file = function (type )
462- for modulename in type :gmatch (' ([%a%.%d_]+)' ) do
470+ -- Build an API module(file) from a string like: `mod.ule`
471+ -- @param #string str
472+ local file = function (str )
473+ local modulename = str :gmatch (' ([%a%.%d_]+)' )()
474+ if modulename then
463475 local file = apimodel ._file ()
464476 file .name = modulename
465477 return file
0 commit comments