An open API service indexing awesome lists of open source software.

https://github.com/shnarazk/tree-sitter-tonel


https://github.com/shnarazk/tree-sitter-tonel

pharo smalltalk tree-sitter

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

          

# tree-sitter-tonel

[![npm](https://img.shields.io/npm/v/tree-sitter-tonel.svg)](https://www.npmjs.com/package/tree-sitter-tonel)

Tonel grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).

Tonel is a file format for storing Pharo/Smalltalk source code in a VCS-friendly way. It's designed to be human-readable and easy to diff. This parser supports the full Tonel specification as described at [pharo-vcs/tonel](https://github.com/pharo-vcs/tonel).

## Features

- Parse Tonel class definitions with STON metadata
- Support for trait and extension definitions
- Parse method definitions with metadata
- Support for class-side and instance-side methods
- Full Smalltalk expression syntax support
- Syntax highlighting queries included

## Installation

### npm

```bash
npm install tree-sitter-tonel
```

### Cargo

Add this to your `Cargo.toml`:

```toml
[dependencies]
tree-sitter-tonel = "0.1.0"
```

## Usage

### Node.js

```javascript
const Parser = require('tree-sitter');
const Tonel = require('tree-sitter-tonel');

const parser = new Parser();
parser.setLanguage(Tonel);

const sourceCode = `
Class {
#name : #MyClass,
#superclass : #Object,
#category : #'MyPackage'
}

{ #category : #accessing }
MyClass >> myMethod [
^ 42
]
`;

const tree = parser.parse(sourceCode);
console.log(tree.rootNode.toString());
```

### Rust

```rust
use tree_sitter::Parser;

fn main() {
let mut parser = Parser::new();
parser.set_language(&tree_sitter_tonel::language()).unwrap();

let source_code = r#"
Class {
#name : #MyClass,
#superclass : #Object
}
"#;

let tree = parser.parse(source_code, None).unwrap();
println!("{}", tree.root_node().to_sexp());
}
```

## Editor Integration

This grammar is designed to work with:

- [Zed](https://zed.dev/) - Modern code editor with tree-sitter support
- [Helix](https://helix-editor.com/) - Post-modern modal text editor
- [Neovim](https://neovim.io/) - Hyperextensible Vim-based text editor
- Any editor with tree-sitter support

## Syntax

Tonel files consist of:

### Class Definitions

```smalltalk
Class {
#name : #Point,
#superclass : #Object,
#instVars : [
'x',
'y'
],
#category : #'Kernel-BasicObjects'
}
```

### Method Definitions

Instance methods:
```smalltalk
{ #category : #accessing }
Point >> x [
^ x
]
```

Class methods:
```smalltalk
{ #category : #'instance creation' }
Point class >> x: xValue y: yValue [
^ self new x: xValue; y: yValue
]
```

### Traits and Extensions

```smalltalk
Trait {
#name : #TComparable,
#category : #'Kernel-Traits'
}

Extension { #name : #Object }
```

## Development

### Building

```bash
npm install
npx tree-sitter generate
```

### Testing

```bash
npm test
```

### Parsing Examples

```bash
npx tree-sitter parse examples/Point.tonel
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## References

- [Tonel Specification](https://github.com/pharo-vcs/tonel)
- [Pharo](https://pharo.org/)
- [Tree-sitter Documentation](https://tree-sitter.github.io/)

## License

This project is licensed under the Mozilla Public License 2.0 - see the [LICENSE](LICENSE) file for details.