pest-parser / pest

The Elegant Parser
https://pest.rs
Apache License 2.0
4.67k stars 262 forks source link

Using declarations from other Pest files. #843

Closed Azoraqua closed 1 year ago

Azoraqua commented 1 year ago

As the title states, I'd like to be able to use pre-existing declarations in other Pest files, for example:

base.pest

STRING = _{ "\"" ~ ANY+ "\"" }

some-other.pest

@use "base" // Or implicitly imported when it's found in the same directory.
SCHEMA = { SOI ~ "[" ~ base::STRING ~ "]" ~ EOI }

@use { STRING } from "base" // Or implicitly imported when it's found in Pest files in the same directory.
SCHEMA = { SOI ~ "[" ~ STRING ~ "]" ~ EOI }
Azoraqua commented 1 year ago

In additionally, perhaps it would be an option to create namespaces, for example like:

namespace "base" {
  STRING = _{ "\"" ~ ANY+ "\"" }
}

@use "base"
@use { STRING } from "base"