toml: rename ast.Node -> ast.Value (#11974)

This commit is contained in:
Larpon 2021-09-25 19:31:02 +02:00 committed by GitHub
parent 80c15607da
commit 13b2aa701c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 111 additions and 103 deletions

View file

@ -102,13 +102,13 @@ pub fn (d Doc) to_json() string {
// value queries a value from the TOML document.
pub fn (d Doc) value(key string) Any {
values := d.ast.table as map[string]ast.Node
values := d.ast.table as map[string]ast.Value
// any_values := d.ast_to_any(values) as map[string]Any
return d.get_map_value_as_any(values, key)
}
// ast_to_any_value converts `from` ast.Node to toml.Any value.
fn (d Doc) ast_to_any(value ast.Node) Any {
// ast_to_any_value converts `from` ast.Value to toml.Any value.
fn (d Doc) ast_to_any(value ast.Value) Any {
// `match` isn't currently very suitable for further unwrapping sumtypes in the if's...
if value is ast.Date || value is ast.Time || value is ast.DateTime {
mut tim := time.Time{}
@ -162,8 +162,8 @@ fn (d Doc) ast_to_any(value ast.Node) Any {
}
return Any(false)
}
map[string]ast.Node {
m := (value as map[string]ast.Node)
map[string]ast.Value {
m := (value as map[string]ast.Value)
mut am := map[string]Any{}
for k, v in m {
am[k] = d.ast_to_any(v)
@ -171,8 +171,8 @@ fn (d Doc) ast_to_any(value ast.Node) Any {
return am
// return d.get_map_value(m, key_split[1..].join('.'))
}
[]ast.Node {
a := (value as []ast.Node)
[]ast.Value {
a := (value as []ast.Value)
mut aa := []Any{}
for val in a {
aa << d.ast_to_any(val)
@ -191,7 +191,7 @@ fn (d Doc) ast_to_any(value ast.Node) Any {
}
// get_map_value_as_any returns the value found at `key` in the map `values` as `Any` type.
fn (d Doc) get_map_value_as_any(values map[string]ast.Node, key string) Any {
fn (d Doc) get_map_value_as_any(values map[string]ast.Value, key string) Any {
key_split := key.split('.')
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, ' getting "${key_split[0]}"')
if key_split[0] in values.keys() {
@ -201,8 +201,8 @@ fn (d Doc) get_map_value_as_any(values map[string]ast.Node, key string) Any {
// panic(@MOD + '.' + @STRUCT + '.' + @FN + ' key "$key" does not exist')
}
// `match` isn't currently very suitable for these types of sum type constructs...
if value is map[string]ast.Node {
m := (value as map[string]ast.Node)
if value is map[string]ast.Value {
m := (value as map[string]ast.Value)
next_key := key_split[1..].join('.')
if next_key == '' {
return d.ast_to_any(value)