Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/target
/.vscode
/contrib
/site
__pycache__
/.claude
121 changes: 121 additions & 0 deletions contrib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Gold editor tooling

This directory contains editor integrations for the Gold language.

## Directory layout

| Path | Description |
|------|-------------|
| `tree-sitter-gold/` | Tree-sitter grammar (C parser + external scanner) |
| `vscode-gold/` | VS Code extension |

---

## tree-sitter-gold

A tree-sitter grammar for Gold. The grammar handles the full language including
multi-line strings (`key:: ...`), which are indentation-sensitive and require the
external C scanner in `src/scanner.c`.

### Building

```sh
cd contrib/tree-sitter-gold
npm install
make generate # runs tree-sitter generate → produces src/parser.c
make wasm # runs tree-sitter build --wasm → produces gold.wasm
make test # run the corpus tests (requires tests/corpus/*.txt)
```

Requirements: [tree-sitter CLI](https://github.com/tree-sitter/tree-sitter/blob/master/cli/README.md)

```sh
npm install -g tree-sitter-cli
# or with cargo:
cargo install tree-sitter-cli
```

### How multi-line strings work

Gold supports a long-form string value in maps:

```gold
{
description:: This is the first line
and this is a continuation
other-key: "normal value"
}
```

The string continues on every subsequent line whose **indentation is strictly
greater than the column of the key** (`description` is at column 4, so only
lines indented by 5+ spaces are included).

Pure tree-sitter grammars cannot express this because the termination condition
is dynamic (depends on the column of a previously seen token). The external
scanner (`src/scanner.c`) handles it with **three external tokens**:

1. `_map_key_ident` — regular map key (not followed by `::`).
2. `_multistring_key` — map key **plus** the `::` consumed together as one
token. The scanner records the key's start column in persistent state.
Combining key + `::` into a single token is crucial: it eliminates the GLR
ambiguity that would otherwise arise because both `map_entry` alternatives
(regular and multistring) used to start with the same external token.
3. `_multistring_content` — consumed after `_multistring_key`; reads the stored
column as the indentation threshold and consumes lines until one is found
whose first non-whitespace character is at or before that threshold.

The scanner handles `_map_key_ident` and `_multistring_key` in a single code
path: it scans the key chars, calls `mark_end` (just past the key), then peeks
ahead for `::`. If found, it updates `mark_end` to include `::` and emits
`_multistring_key`; otherwise it emits `_map_key_ident` using the earlier
`mark_end`. This design avoids advancing past characters and then returning
false (which would leave the lexer at the wrong position for the fallback).

---

## vscode-gold

A VS Code extension that provides:

- **Syntax highlighting** via a TextMate grammar (`syntaxes/gold.tmLanguage.json`)
— works immediately with no compilation step.
- **Tree-sitter integration** via `web-tree-sitter` — enables the *Gold: Show
Syntax Tree* command and richer language features. Requires `gold.wasm` to be
built and placed in the extension directory.

### Quick start (TextMate highlighting only)

```sh
cd contrib/vscode-gold
npm install
npm run compile
# In VS Code: F5 to open the Extension Development Host
```

### Full setup (with tree-sitter)

```sh
# 1. Build the WASM parser
cd contrib/tree-sitter-gold
npm install && make wasm # produces gold.wasm in this directory AND copies it to ../vscode-gold/

# 2. Build and launch the extension
cd ../vscode-gold
npm install
npm run compile
# In VS Code: F5
```

### Commands

| Command | Description |
|---------|-------------|
| `Gold: Show Syntax Tree` | Open a side panel showing the tree-sitter parse tree for the current file |

### Settings

| Setting | Default | Description |
|---------|---------|-------------|
| `gold.treeSitter.enabled` | `true` | Enable tree-sitter features |
| `gold.treeSitter.wasmPath` | `""` | Override path to `gold.wasm` |
46 changes: 46 additions & 0 deletions contrib/tree-sitter-gold/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
root = true

[*]
charset = utf-8

[*.{json,toml,yml,gyp}]
indent_style = space
indent_size = 2

[*.js]
indent_style = space
indent_size = 2

[*.scm]
indent_style = space
indent_size = 2

[*.{c,cc,h}]
indent_style = space
indent_size = 4

[*.rs]
indent_style = space
indent_size = 4

[*.{py,pyi}]
indent_style = space
indent_size = 4

[*.swift]
indent_style = space
indent_size = 4

[*.go]
indent_style = tab
indent_size = 8

[Makefile]
indent_style = tab
indent_size = 8

[parser.c]
indent_size = 2

[{alloc,array,parser}.h]
indent_size = 2
37 changes: 37 additions & 0 deletions contrib/tree-sitter-gold/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
* text=auto eol=lf

# Generated source files
src/*.json linguist-generated
src/parser.c linguist-generated
src/tree_sitter/* linguist-generated

# C bindings
bindings/c/* linguist-generated
CMakeLists.txt linguist-generated
Makefile linguist-generated

# Rust bindings
bindings/rust/* linguist-generated
Cargo.toml linguist-generated
Cargo.lock linguist-generated

# Node.js bindings
bindings/node/* linguist-generated
binding.gyp linguist-generated
package.json linguist-generated
package-lock.json linguist-generated

# Python bindings
bindings/python/** linguist-generated
setup.py linguist-generated
pyproject.toml linguist-generated

# Go bindings
bindings/go/* linguist-generated
go.mod linguist-generated
go.sum linguist-generated

# Swift bindings
bindings/swift/** linguist-generated
Package.swift linguist-generated
Package.resolved linguist-generated
8 changes: 8 additions & 0 deletions contrib/tree-sitter-gold/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
build/
src/parser.c
src/grammar.json
src/node-types.json
src/tree_sitter/
*.so
*.wasm
58 changes: 58 additions & 0 deletions contrib/tree-sitter-gold/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions contrib/tree-sitter-gold/Cargo.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions contrib/tree-sitter-gold/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions contrib/tree-sitter-gold/Package.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions contrib/tree-sitter-gold/binding.gyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading