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

Re-usable parsers #25

Open
aomader opened this issue Nov 7, 2014 · 5 comments
Open

Re-usable parsers #25

aomader opened this issue Nov 7, 2014 · 5 comments
Labels
feature Something not supported that perhaps should be

Comments

@aomader
Copy link

aomader commented Nov 7, 2014

Assume I define a few parsers within a module and export the parsing functions, similar like the following:

pub use self::parser::empty as empty;

peg! parser(r#"
#[pub]
empty -> ()
    = "" { () }
"#)

I'm wondering if it is possible to reuse the exporter parser in another module in another PEG macro call. In general, I'm interested in reusing parsers defined in different source files.

Any ideas?

@untitaker
Copy link
Contributor

You might be able to do that by importing the internal parse_empty from the self:parser module. I am not sure though.

@kevinmehall kevinmehall added the feature Something not supported that perhaps should be label Nov 8, 2014
@kevinmehall
Copy link
Owner

Yeah, @untitaker's correct; it would have to call the private parser::parse_empty rather than the public wrapper parser::empty, which would require some kind of flag to make those internal functions public, and syntax in the other grammar to use them into the generated module's scope.

Another potential issue is that I plan to add a facility for a grammar to have a state object threaded through all the parse rules, for things like string interners, filenames for source maps, etc. It would have to ensure both grammars have the same type of state object so they're compatible.

@aomader
Copy link
Author

aomader commented Nov 13, 2014

I thought it wouldn't be that easy, too bad. Are you planning on adding such functionality in the near future?

One more thing, it would be awesome to allow to import some stuff into the parser and making it available for the whole. Else I have to write long statements like super::super::... or I have to re-export them using pub use .... Any advice on this one?

@mcandre

This comment was marked as off-topic.

@kevinmehall

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Something not supported that perhaps should be
Projects
None yet
Development

No branches or pull requests

4 participants