Class StructureReader

StructureReader is an object that can read some structured-text config or data files.

Here is a short example of structure. This is format is more human readable than CSV, and is used by Harmony Assistant for some config files, so it follows the same syntax.

DebutFruits
   DebutFruit
     Name Apple
     Url https://en.wikipedia.org/wiki/Apple
     Color Green Yellow Red
   FinFruit
   DebutFruit
     Name Banana
     Color Yellow
   FinFruit
FinFruits

Example


 Include "SMStructureReader"
 local sr = StructureReader.loadFile("/path/to/fruits.txt")
 local fruit = sr:next("Fruit")
 local cpt = 0
 while fruit do
   print(fruit:get("Name"))
   fruit = sr:next("Fruit")
 end
 print("Fruits found:" .. cpt)
 sr:rewind() -- go back to begining (top of the file)
 local vegetable = sr:next("Vegetable")
 if vegetable == nil then print("No vegetable found."); end

Summary

Return typeFunction and summary
stringget(string key)
Get the value of a property of the structure.
StructureReadernext(string structName)
Locate the next structure between Debut[structName] and Fin[structName] The returned value is a StructureReader as structures may be organized in tree.
 rewind()
Go back to the beginning of the structure, if a search reached the end.

Methods

StructureReader:next(string structName)

Locate the next structure between Debut[structName] and Fin[structName] The returned value is a StructureReader as structures may be organized in tree.

ParameterTypeDefaultDescription
structNamestring structName
Return
StructureReader: StructureReader

StructureReader:get(string key)

Get the value of a property of the structure.

ParameterTypeDefaultDescription
keystring key
Return
string: string

StructureReader:rewind()

Go back to the beginning of the structure, if a search reached the end.