This project extends Starkark in Go with first class YAML support.
SmallStmt = YamlStmt | ...
YamlStmt = identifier ':' YAMLTail
| string ':' YAMLTail
| '-' YAMLTail
YAMLTail is a lexical element corresponding to all lines with the same or greater indendation level as YamlStmt
def func1():
name: max
cities:
- SF
- LA
print(func1()) # print a dictionary
def func():
- SF city
- LA city
print(func1()) # print a sequence
The dot expression can be used to get the dictionary value corresponding to the dot expression attribute
def func1():
name: max
cities:
- SF
- LA
print(func1().name) # print max
Builtin dictionary methods take precedence over attribute selection.
For instance, access the attribute values
by using either get
or an index.
def func1():
values: ['1', '2']
print(func1()['values'][0]) # print 1
YAML text enclosed in curly braces { ... }
is interpreted as Starlark expression
def func1(d):
text: the city name is { d.name }
print(func1({'name': 'NY'}).text) # print the city name is NY
In YAML, flow mappings are denoted by surrounding '{' and '}' characters.
def func1(d):
text: { d.name } is big
print(func1({'name': 'NY'}).text) # print an error!
You can change this behavior by prefixing {
with s
.
def func1(d):
text: s{ d.name } is big
print(func1({'name': 'NY'}).text) # print NY is big