obazl / sealark

Starlark parser and tooling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sealark - tools for Starlark parsing and editing

Sealark is a collection of tools for working with Starlark code, written in C (get it, C-lark?). libsealark is a Starlark parser; Sunlark is a Scheme binding; Moonlark is a Lua binding;

List of lark species. Sunlark is actually a species.

STATUS Beta-ish. Used by Sunlark; documentation is on the way.

libsealark

libsealark is a C11 library that contains routines to parse files and strings of Starlark code, producing a simple AST. It also contains some serialization routines to write the AST to a string. The result can be compared to the original input. (The goal is a 100% match, including whitespace and comments).

libsealark uses re2c for lexing, lemon for parsing, and uthash for C data structures. Experienced C programmers will notice there are no header (.h) files in the source tree. That's because it uses Makeheaders, which automatically generates one header for each source file, containing everything it needs (and nothing more). Each BUILD.bazel file contains a :mkhdrs target that runs makeheaders. In addition sealark/BUILD.bazel has a :mkhdrs-export that generates the sealark.h public API.

Currently libsealark does not contain a public API for manipulating the AST. A developer could easily implement such routines, however, since the AST is pretty simple, and it uses utarray and utstring from the UTHash library.

Instead, the parsing routines of libsealark are exposed in sunlark, a Scheme binding, which also exposes the parsed AST. AST manipulation and serialization can then be implemented in Scheme code. The idea is that this will make customization much easier, thus enabling tool makers to build a variety of tools on top of sunlark/sealark. Default implementations are provided, but the user can easily supply alternatives.

A Lua binding, Moonlark, is partially implemented.

testing

$ bazel run test:lex_file -- -f path/to/BUILD
$ bazel run test:parse_file -- -f path/to/BUILD

Unit tests are currently in Sunlark.

About

Starlark parser and tooling

License:MIT License


Languages

Language:C 68.8%Language:Yacc 14.8%Language:Starlark 8.7%Language:C++ 6.3%Language:Emacs Lisp 1.2%Language:Shell 0.3%