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
- Host: GitHub
- URL: https://github.com/shnarazk/tree-sitter-tonel
- Owner: shnarazk
- License: mpl-2.0
- Created: 2025-12-21T01:39:21.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-12-21T02:36:07.000Z (6 months ago)
- Last Synced: 2025-12-29T23:55:13.281Z (6 months ago)
- Topics: pharo, smalltalk, tree-sitter
- Language: JavaScript
- Homepage:
- Size: 71.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tree-sitter-tonel
[](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.