-
Notifications
You must be signed in to change notification settings - Fork 28
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
Import support #50
Comments
PackCC does not have a functionality like "import". I understand its usability, but currently I'm reluctant to realize it since it brings some complexity in PackCC's simpleness. |
I believe import functionality should be quite easily implemented by custom I don't think support for this should be directly in PackCC, as it only works with stream of characters. It doesn't know anything about files. At best, there could be some function to help with the stack keeping and/or some examples how to implement this. |
@dolik-rce This isn't a suggestion to import data being parsed. It's a suggestion to import specs into the parser itself while the parser is being generated. For example, imagine that we're parsing a query language that must handle standard keywords like AND, OR, and NOT, but must also have special handling for different languages like French or Arabic. In that case it would be really helpful to create a separate .peg file for every language, but then import a standard, common .peg file that recognizes keywords. It would save a lot of copying and pasting. |
@ccleve Oh, I see. My bad, I guess I wasn't paying enough attention when I read the issue 🙄 |
Please please implement this. I'm writing a parser for a language that is case-insensitive and needs UCD categories. I've generated both the categories and permutations for keywords but this creates an unwieldy grammar file that's more than 15K LOC. (I'm uncertain how packcc is going to handle this but we'll see....) Also it might be a good idea to add a way of telling ackcc "Hey this string literal should be matched case-insensitively" because I don't like generating thousands of word permutations even if it is fast.) |
@ethindp: This is slightly off-topic, but do you know, you can use character classes to match keywords case-insensitively? E.g.: |
I... Stupidly didn't think about that, thank you for the reminder! |
@ccleve , @ethindp , I have introduced the import functionality. Please check it.
|
I have just quickly tested the imports. It's very intuitive and seems to work very well. If I understand correctly, there is slight difference in the behavior: Unused rules in the imported files are ignored, while in the main parsed files they result in error. This is totally understandable and good if you wish to use a prepared library (as is the case with the bundled ascii and unicode classes), but it might be surprising if someone uses import just to break single grammar to multiple smaller files for better readability. It should probably be documented in the README. It might also make sense to let user choose if he wants to check for unused rules in imported files (e.g. by using different directive) or not. Not sure if that is possible to implement easily. I didn't study the new code enough to understand it yet 🙂 EDIT: Oh, now I see. The warning for unused rules has been removed in 7b4aa25 for all rules, nut just those from imported files. That is a bit surprising, I liked that feature - it usually made me realized that I did some stupid error in my grammar 🙂 |
Thank you for your immediate feedback! |
Antlr supports "import" statements, where you can import an external file and treat its contents as if they were part of the current file. I use this a lot to create multiple parsers with different capabilities that share common functionality.
See https://github.com/antlr/antlr4/blob/master/doc/grammars.md#grammar-imports
Does Packcc have similar functionality?
The text was updated successfully, but these errors were encountered: