https://github.com/tomefile/lib-parser
Library to parse Tomefile code and output a node tree for use by another program
https://github.com/tomefile/lib-parser
ast parser tome tomefile
Last synced: 5 months ago
JSON representation
Library to parse Tomefile code and output a node tree for use by another program
- Host: GitHub
- URL: https://github.com/tomefile/lib-parser
- Owner: tomefile
- License: isc
- Created: 2025-11-01T16:24:24.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-12-18T18:13:12.000Z (6 months ago)
- Last Synced: 2025-12-20T08:50:01.643Z (6 months ago)
- Topics: ast, parser, tome, tomefile
- Language: Go
- Homepage:
- Size: 261 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tomefile Parser
Library to parse [Tomefile](https://github.com/tomefile) code and output a node tree for use by another program.
* [Features](#features)
* [Parsing](#parsing)
* [Hooks](#hooks)
* [Roadmap](#roadmap)
* [Usage](#usage)
## Features
### Parsing
Parses the input file into a `*libparser.NodeRoot{}` including string segments.
### Hooks
Allow to run custom `libparser.Hook()` functions on `libparser.Node` before it gets appended to the tree. Returns as soon as an error is encountered. Used to validate, discard or modify nodes.
## Roadmap
Things that need to be done before `v1`:
- [x] Save context to Nodes and allow for partial parsing.
- [ ] Partial parsing
- [ ] Improve runtime string modifier evaluation (currently it just fails silently)
- [ ] Multi-line arguments `(...)`
- [ ] Revisit all of the code and make sure it's well-made (it isn't)
- [ ] Better test coverage (Add more edge-cases where formatting isn't perfect)
## Usage
Parsing a file:
```go
// Close all files when all parsers have finished.
defer libparser.CloseAll()
file, err := libparser.OpenFile("example.tome")
if err != nil {
panic(err)
}
parser := libparser.New(file)
parser.Hooks = []libparser.Hook{
libparser.NoShebangHook, // remove UNIX shebang, e.g. #!/bin/tome
libparser.ExcludeHook[*libparser.NodeComment], // by default, the parser includes ALL file contents, you can discard what's not needed.
}
if derr := parser.Run(); derr != nil {
derr.Print(os.Stderr)
os.Exit(1)
}
// [parser.Result] is [*libparser.NodeTree]
return parser.Result
```