Skip to content

Commit

Permalink
Adds Pest Grammar to Ion Conversion (#38)
Browse files Browse the repository at this point in the history
The purpose of this commit is the start of a tool to generate Ion
formatted ASTs from Pest grammars, particularly that of PartiQL.
We could then easily process the grammar outside of Rust in scripts that
could be used to generate things like TextMate grammars for IDE support
or LaTeX fragments for the specification document.

Adds the `pest-ion` crate to provide a simple trait `TryPestToElement`
and implementations over `&str` syntax definitions to parse Pest grammars
and create their Ion `Element` serialized forms.  Also adds `PestToElement`
which is the infallible version of the trait (used mostly for Pest AST elements).

Resolves #35.
  • Loading branch information
almann authored Jun 8, 2021
1 parent 6db9a81 commit fb2628f
Show file tree
Hide file tree
Showing 5 changed files with 533 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ members = [
"partiql-irgen",
"partiql-parser",
"partiql-rewriter",
"pest-ion",
]
30 changes: 30 additions & 0 deletions pest-ion/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "pest-ion"
authors = ["PartiQL Team <[email protected]>"]
description = "A simple Pest grammar to Ion converter"
homepage = "https://github.com/partiql/partiql-lang-rust/pest-ion"
repository = "https://github.com/partiql/partiql-lang-rust/pest-ion"
license = "Apache-2.0"
readme = "README.md"
keywords = ["parser", "peg", "pest", "ion", "cli"]
categories = ["parser-implementations", "command-line-utilities"]
exclude = [
"**/.git/**",
"**/.github/**",
"**/.travis.yml",
"**/.appveyor.yml",
]
edition = "2018"
version = "0.0.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
thiserror = "~1.0.25"
pest = "~2.1.3"
pest_meta = "~2.1.3"
ion-rs = "~0.6.0"
smallvec = "~1.6.1"

[dev-dependencies]
rstest = "~0.10.0"
9 changes: 9 additions & 0 deletions pest-ion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Pest to Ion

This is a simple tool and library for converting [Pest] grammars to [Ion] data format.

The motivation for this is to make a portable way to introspect [Pest] grammars in other tools
as a data format versus having to provide bespoke parsers for the Pest syntax in other platforms.

[Pest]: https://pest.rs/
[Ion]: https://amzn.github.io/ion-docs/
Loading

0 comments on commit fb2628f

Please sign in to comment.