$APPTYPE CONSOLE: $TYPECHECK ON
$INCLUDE "yaml.inc"
type COLLECTIONDATA
collected_by as string
collected_date as string
end type
type MINERALS
name as string*64
var as string*64
colors as string*64
color_var as string*64
matrix as string*64
end type
type IMAGE
mugshot as string
end type
type SPECIES
minerals as MINERALS
end type
type LOCATION
address as string
grid as string
gps as string
end type
type ACQUISITION
date as string
from as string
fieldref_no as string
tempref_no as string
end type
type DBINFO
rec_type as string
last_save as string
previous_save as string
end type
type record
dummy as string
title as string
entry as string
species as SPECIES
location as LOCATION
collection as COLLECTIONDATA
aquisition as ACQUISITION
dbinfo as DBINFO
end type
defstr yamlFile,tk,key,token
deflng parser,ret, indent, child,state=0
dim conf as record
yamlFile.loadfromfile("testI.yml")
ret = yaml_parser_initialize(@parser)
yaml_parser_set_input_string(@parser, yamlFile, yamlFile.len)
do
yaml_parser_scan(@parser, @token)
select case byref(@token)
' case YAML_BLOCK_SEQUENCE_START_TOKEN,YAML_BLOCK_MAPPING_START_TOKEN
' if child > 0 then
' inc indent,2
' else
' inc child
' ' print "#" + string$(78,"=")
' end if
' case YAML_BLOCK_END_TOKEN
' dec indent,2
' dec child
case YAML_KEY_TOKEN
state = 0
case YAML_VALUE_TOKEN
state = 1
case YAML_SCALAR_TOKEN
tk = byref$(byref(@token+4))
if state = 0 then
key = tk
end if
if state = 1 then
select case key
' ## HEADER INFO ##
case "RecordTitle"
conf.title = tk
case "Entry No"
conf.entry = tk
' ## LOCATION INFO ##
case "Address"
conf.location.address = tk
case "Grid Reference"
conf.location.grid = tk
case "GPS Coordinates"
conf.location.gps = tk
' ## COLLECTION INFO ##
case "collected by"
conf.collection.collected_by = tk
case "Collection Date"
conf.collection.collected_date = tk
' ## ACQUISITION INFO ##
case "Acquired Date"
conf.aquisition.date = tk
case "From"
conf.aquisition.from = tk
case "Field Ref No"
conf.aquisition.fieldref_no = tk
case "Temp Ref No"
conf.aquisition.tempref_no = tk
' ## DB SYSTEM INFO ##
case "RecordType"
conf.dbinfo.rec_type = tk
case "LastSavedTime"
conf.dbinfo.last_save = tk
case "Previous Version"
conf.dbinfo.previous_save = tk
' case else
' ' print "Unknown key = " + key
end select
' print space$(indent) + key + " = " + tk
' if indent = 0 then
' end if
end if
case else
state = 1
end select
loop until byref(@token) = YAML_STREAM_END_TOKEN
'PAUSE
gosub cleanup
gosub print_data
END
cleanup:
yaml_token_delete(@token)
yaml_parser_delete(@parser)
return
print_data:
cls
print "Title = "; conf.title
print "Entry# = "; conf.entry
print "Address = "; conf.location.address
print "Grid = ";conf.location.grid
print "GPS = ";conf.location.gps
print "Collected By = ";conf.collection.collected_by
print "Collected Date = ";conf.collection.collected_date
print "Aquisition Date = ";conf.aquisition.date
print "Aquired From = ";conf.aquisition.from
print "Field Ref No = ";conf.aquisition.fieldref_no
print "Temp Ref No = ";conf.aquisition.tempref_no
print "DB Rec Type = ";conf.dbinfo.rec_type
print "Last Saved = ";conf.dbinfo.last_save
print "Previous Save = ";conf.dbinfo.previous_save
return