starlark-go

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2019 License: BSD-3-Clause

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

Directories

Path Synopsis
cmd
starlark
The starlark command interprets a Starlark file.
The starlark command interprets a Starlark file.
internal
chunkedfile
Package chunkedfile provides utilities for testing that source code errors are reported in the appropriate places.
Package chunkedfile provides utilities for testing that source code errors are reported in the appropriate places.
compile
Package compile defines the Starlark bytecode compiler.
Package compile defines the Starlark bytecode compiler.
spell
Package spell file defines a simple spelling checker for use in attribute errors such as "no such field .foo; did you mean .food?".
Package spell file defines a simple spelling checker for use in attribute errors such as "no such field .foo; did you mean .food?".
Package repl provides a read/eval/print loop for Starlark.
Package repl provides a read/eval/print loop for Starlark.
Package resolve defines a name-resolution pass for Starlark abstract syntax trees.
Package resolve defines a name-resolution pass for Starlark abstract syntax trees.
Package starlark provides a Starlark interpreter.
Package starlark provides a Starlark interpreter.
Package starlarkstruct defines the Starlark types 'struct' and 'module', both optional language extensions.
Package starlarkstruct defines the Starlark types 'struct' and 'module', both optional language extensions.
Package starlarktest defines utilities for testing Starlark programs.
Package starlarktest defines utilities for testing Starlark programs.
Package syntax provides a Starlark parser and abstract syntax tree.
Package syntax provides a Starlark parser and abstract syntax tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL