Open aomader opened 10 years ago
You might be able to do that by importing the internal parse_empty
from the self:parser
module. I am not sure though.
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.
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?
I would love for the peg DSL to make it easier to automatically export the generated grammar for use in a library. Don't assume that people only write executables.
As a workaround, I am writing a pub fn
in my lib.rs
that invokes the pub fn
within the parser!
block. Annoying to have to repeat myself, but that's what I'm doing meanwhile.
@mcandre that sounds like a different issue than what this feature request is about (sharing rules between multiple PEG grammars). Can you open a new issue with more details and ideally a code example of what's not working?
Probably the way to do that is to introduce another macro, say, parser_fragment!
, which will define functions which can be used in a regular parser!
macro, but without boilerplate that is needed for stand-alone parser.
Assume I define a few parsers within a module and export the parsing functions, similar like the following:
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?