Crates.io | tangibl |
lib.rs | tangibl |
version | 0.1.0 |
source | src |
created_at | 2023-06-03 07:44:12.671988 |
updated_at | 2023-06-03 07:44:12.671988 |
description | A parser for generating an AST from a set of predefined TopCodes |
homepage | |
repository | https://github.com/tangibl/tangibl-rs |
max_upload_size | |
id | 881419 |
size | 69,025 |
This project is still in development, things are likely to be broken.
This is the core Tangibl library. This source was originally written in Java, but has been rewritten in Rust to allow the generation of a dynamic C library, WASM etc.
use topcodes::TopCode;
use tangibl::JsonPrinter;
// Scan or generate your TopCodes.
let topcodes: Vec<TopCode> = ...;
// Parse codes in Tangibl abstract syntax tree.
let ast: Option<Start> = tangibl::parse(&topcodes);
// Create a visitor for printing JSON.
let mut json_printer = JsonPrinter::new();
println!("{}", json_printer.print(&ast));
The library additionally contains a JSON printer and a visitor abstraction for performing actions based on the shape of the AST. Click here for an overview of the Tangibl grammar.
The visitor uses enum based matching instead of the more commonly used accept/visit method pattern used in OOP languages. There are two reasons for this:
Separate interfaces will need to be made to consume the dynamic C library for each language in which Tangibl is consumed. This should be minimal effort as the frontend simply needs to parse the final JSON representation into a usable tree of nodes. Rust implementations, however, can skip this step and use the AST directly from this source.