home *** CD-ROM | disk | FTP | other *** search
/ Computer Arts: Projects 57 / CAP57.bin / pc / data / Interface / alongi.dir / menu_4_NodeTree.Parser.basic.ls < prev    next >
Encoding:
Text File  |  2004-03-09  |  2.1 KB  |  78 lines

  1. on mCreateNodeTree me, aDescriptorStr
  2.   me._Debug("Parsing node tree description string")
  3.   nodeTree = [:]
  4.   iconList = [:]
  5.   if aDescriptorStr.ilk <> #string then
  6.     return nodeTree
  7.   end if
  8.   mx = aDescriptorStr.line.count
  9.   the itemDelimiter = TAB
  10.   currentParent = []
  11.   parentNode = nodeTree
  12.   repeat with i = 1 to mx
  13.     chnk = aDescriptorStr.line[i]
  14.     if chnk = EMPTY then
  15.       next repeat
  16.     end if
  17.     the itemDelimiter = ":"
  18.     iconRef = chnk.item[2]
  19.     chnk = chnk.item[1]
  20.     the itemDelimiter = TAB
  21.     numItems = chnk.item.count
  22.     repeat with j = 1 to numItems
  23.       n = chnk.item[j]
  24.       if n <> EMPTY then
  25.         iconList.addProp(n, iconRef)
  26.         if j > (currentParent.count + 1) then
  27.           alert("Error parsing descriptor - cannot locate parent node for " & n)
  28.           exit repeat
  29.         else
  30.           currentParent[j] = n
  31.         end if
  32.         if j = 1 then
  33.           nodeTree.addProp(n, [#children: [:], #Icon: iconRef])
  34.         else
  35.           currentParentNode = nodeTree
  36.           parentNum = j - 1
  37.           repeat with k = 1 to parentNum
  38.             if k > currentParent.count then
  39.               alert("Error parsing descriptor - cannot locate parent node for " & n)
  40.               exit repeat
  41.               next repeat
  42.             end if
  43.             currentParentNode = currentParentNode.getaProp(currentParent[k]).children
  44.           end repeat
  45.           currentParentNode.addProp(n, [#children: [:], #Icon: iconRef])
  46.         end if
  47.         exit repeat
  48.       end if
  49.     end repeat
  50.   end repeat
  51.   return nodeTree
  52. end
  53.  
  54. on mCreateDescriptor me, aNodeTree
  55.   return me._WriteNodeTree(aNodeTree, EMPTY, EMPTY)
  56. end
  57.  
  58. on _WriteNodeTree me, aParentNode, aStr, indent
  59.   repeat with i = 1 to aParentNode.count
  60.     id = aParentNode.getPropAt(i)
  61.     thisNode = aParentNode[i]
  62.     aStr = aStr & indent & id & RETURN
  63.     aStr = me._WriteNodeTree(thisNode, aStr, indent & TAB)
  64.   end repeat
  65.   return aStr
  66. end
  67.  
  68. on _Debug me, Msg
  69.   global gDebugMode
  70.   if ((the environment).runMode = "Author") or gDebugMode then
  71.     if member("Debugger").type = #script then
  72.       script("Debugger").mLog(me.script, Msg)
  73.     else
  74.       put me.script && "---> " && Msg
  75.     end if
  76.   end if
  77. end
  78.