-
Notifications
You must be signed in to change notification settings - Fork 149
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
EBNF exception symbol support #114
Comments
There are a few different versions of the EBNF standard floating around, and whatever version I originally consulted didn't have a reference to the exception symbol, so this is the first I'm hearing about it. I just looked it up, though, so I know what you're talking about. It is certainly a goal of instaparse to make it possible to just paste in standard EBNF grammars with little to no modification, so now that I know about it, I'd like to eventually investigate this and get it included. It appears that the standard severely restricts what can come after the - symbol. To avoid problematic recursion, it looks like the spec says the right-hand side needs to expand to something simple (like an alternation of plain symbols), so I'm not sure your example for NCName and CommentContents would even fall within the scope of the spec's definition of the exception symbol. In the meantime, it seems to me that negative lookahead should be a viable substitute for the exception symbol. Simply translate However, you'll get the best performance if you can translate these rules into regexes. |
Thanks for the quick reply! I will give negative lookaheads a go. Regarding character ranges, I've already translated them into regexps, although I'm not quite sure whether I've got the syntax 100% right. For example, I changed
|
A few things I noticed:
Here is my edited version, with those three points taken into consideration (assuming you want single backslash):
|
@aengelberg: Many thanks for the suggestions! Your version of I haven't yet quite managed to wrangle In the meantime, you can close this issue as far as I'm concerned, unless you want to keep it open for tracking the exception symbol issue. |
Glad to hear you're on the right track now. I'm going to keep the issue open for the exception symbol. |
I'd like to use Instaparse to parse XPath expressions. I have an EBNF grammar that works otherwise (well, I think so, at least), but there are two rules that don't work:
And:
Where
Char
is:The rule for
Name
is a bit longer so I won't copy-paste it here, but it's available here.When parsing my EBNF file, Instaparse throws this error:
If I understand correctly, Instaparse doesn't support the EBNF exception symbol. If so, are there any plans to support it, or is my best bet to try to rewrite those rules using regular expressions? I'm just asking because the rules for
Char
andName
are pretty hefty, so I'm not sure what the best approach here is.The text was updated successfully, but these errors were encountered: