Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing rules between grammars? #197

Closed
waywardmonkeys opened this issue Feb 19, 2018 · 3 comments · Fixed by #758
Closed

Sharing rules between grammars? #197

waywardmonkeys opened this issue Feb 19, 2018 · 3 comments · Fixed by #758

Comments

@waywardmonkeys
Copy link
Contributor

I have a few grammars for related formats / languages that share some common rules. Is there a way to readily share rules between separate grammar files?

It wouldn't make sense to just have a single big grammar file.

In nom, I would be able to define new combinators that I'd use for things like basic types and such.

@dragostis
Copy link
Contributor

Good point. There should be an import command in .pest files. This could be added in 1.1. Let me know if you want to tackle it.

@dragostis dragostis added this to the v1.1 milestone Feb 19, 2018
@waywardmonkeys
Copy link
Contributor Author

Could you provide a couple of getting started pointers and I will see if I can tackle it?

@dragostis
Copy link
Contributor

Of course. The necessary grammar should be added to meta. Probably something like use generic.pest would do well.

Then this should be somehow integrated into the parser and validator in the meta crate. I'm not completely sure what the best approach would be in this case. My current hunch is to do the actual importing in parser::convert_rules, where one could call parse and validate recursively, but this might not work and a change in architecture may be needed.

This was referenced Jun 1, 2018
@dragostis dragostis removed this from the v2.0 milestone Aug 12, 2018
@tomtau tomtau added this to the v3.0 milestone Jul 23, 2022
huacnlee added a commit to huacnlee/pest that referenced this issue Jan 4, 2023
Resolve pest-parser#197

Example:

```rust
#[derive(Parser)]
#[grammar = "_base.pest"]
#[grammar = "json.pest"]
pub struct JSONParser;
``
huacnlee added a commit to huacnlee/pest that referenced this issue Jan 4, 2023
Resolve pest-parser#197

Example:

```rust
#[derive(Parser)]
#[grammar = "_base.pest"]
#[grammar = "json.pest"]
pub struct JSONParser;
```

For supports sharing rules between grammars.
huacnlee added a commit to huacnlee/pest that referenced this issue Jan 4, 2023
Resolve pest-parser#197

Example:

```rust
#[derive(Parser)]
#[grammar = "_base.pest"]
#[grammar = "json.pest"]
pub struct JSONParser;
```

For supports sharing rules between grammars.
huacnlee added a commit to huacnlee/pest that referenced this issue Jan 4, 2023
Resolve pest-parser#197

Example:

```rust
#[derive(Parser)]
#[grammar = "base.pest"]
#[grammar = "json.pest"]
pub struct JSONParser;
```

For supports sharing rules between grammars.
tomtau pushed a commit that referenced this issue Jan 5, 2023
Resolve #197

Example:

```rust
#[derive(Parser)]
#[grammar = "base.pest"]
#[grammar = "json.pest"]
pub struct JSONParser;
```

For supports sharing rules between grammars.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment