A tree-sitter grammar for the Formaggio geospatial data pipeline language.
Expression blocks ({ ... }) are parsed as opaque nodes and delegated to tree-sitter-maparoni via language injection. YAML front matter is similarly injected as YAML.
- YAML front matter between
---delimiters - Pipelines with
|>operator - Variable assignments (
$name = pipeline) and concatenation ($a + $b) - Sections (
### View: Name,### Data Pipeline) - Directives (
@default,@view-id: identifier) - Operations in four forms:
- bare:
all,parse_geojson,input_data - with expression block:
fetch { "url" },filter { expr } - with parameters:
parse_json(path: "$.items", location: [...]) - with parameters and block:
sort(order: .descending) { expr }
- bare:
- Map with lambda:
map { item -> item |> set(.title) { expr } } - If/then/else:
if { condition } then { l -> pipeline } else { l -> pipeline } - Comments:
# line comment
---
name: "Major Earthquakes"
category: "Global"
---
fetch { "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/significant_month.geojson" }
|> parse_geojson
|> sort(order: .descending) { `mag` }
|> map { l ->
l
|> set(.title) { value('place') }
|> set(.style) { fillColor(circle(`mag` * 5), gradient(`mag`, 'traffic', 5, 8)) }
}
### View: Nearby
@default
all
|> filter { distance(coordinate, currentLocation) <= 5000km }
|> sort { distance(coordinate, currentLocation) }
# Install dependencies
npm install
# Generate the parser
npx tree-sitter generate
# Run tests
npx tree-sitter test
# Parse a file
npx tree-sitter parse example.formaggioTo add Formaggio syntax highlighting to Zed, create a local extension that references this grammar.
Create a directory for your extension (e.g., ~/zed-formaggio/) with this structure:
zed-formaggio/
├── extension.toml
└── languages/
└── formaggio/
├── config.toml
├── highlights.scm
├── injections.scm
├── indents.scm
└── brackets.scm
id = "formaggio"
name = "Formaggio"
version = "0.1.0"
schema_version = 1
authors = ["Your Name"]
description = "Formaggio language support"
[grammars.formaggio]
repository = "file:///Users/you/Development/tree-sitter-formaggio"
rev = ""Set repository to a file:// URL pointing at your local clone of this repo during development. For distribution, point it at the remote git URL and set rev to a commit hash.
name = "Formaggio"
grammar = "formaggio"
path_suffixes = ["formaggio"]
line_comments = ["# "]
tab_size = 2Copy the .scm files from this repo's queries/ directory into languages/formaggio/:
cp queries/highlights.scm languages/formaggio/
cp queries/injections.scm languages/formaggio/
cp queries/indents.scm languages/formaggio/
cp queries/brackets.scm languages/formaggio/In Zed, open the command palette and run zed: install dev extension, then select your zed-formaggio/ directory. Zed will build the grammar from source and load the extension.
After making changes, run zed: rebuild extensions to reload.
Expression blocks delegate to tree-sitter-maparoni for highlighting. For this to work, you also need the maparoni grammar registered. Add it to your extension.toml:
[grammars.maparoni]
repository = "file:///Users/you/Development/tree-sitter-maparoni"
rev = ""And create a minimal languages/maparoni/config.toml:
name = "Maparoni"
grammar = "maparoni"
path_suffixes = ["mpex"]With corresponding query files from the tree-sitter-maparoni repo.
source_file
├── yaml_front_matter → injected as YAML
└── body
├── section_header ### View: Name
├── directive @default, @view-id: value
├── variable_assignment $name = pipeline
└── pipeline
├── operation name / name { } / name(...) / name(...) { }
├── variable $name
├── map_operation map { param -> pipeline }
└── if_operation if { } then { } else { }
expression_block { ... } → injected as maparoni
.formaggio
MIT