Categorygithub.com/lionelvillard/starlark-go
repository
0.1.0
Repository: https://github.com/lionelvillard/starlark-go.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Starlark in Go with YAML extensions

This project extends Starkark in Go with first class YAML support.

Additional statements

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

Examples

YAML Mapping to dictionary

def func1():
  name: max
  cities:
  - SF
  - LA

print(func1()) # print a dictionary

YAML Sequence to list

def func():
  - SF city
  - LA city

print(func1()) # print a sequence

Dot expression and dictionary

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

Enclosed Starlark expression in YAML

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

Mapping flow style disambiguation

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