-
Notifications
You must be signed in to change notification settings - Fork 2
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
allow colon before target rule names #18
Comments
My feeling is that the presence or absence of the : tells you whether the type is built-in (like 'string') or is user-defined (like arin_string). So I think we should keep it as is. Essentially the user can look at it as macro substitution, and the colon is pulled in from where 'arin_string' is defined. If you think of it that way, then after user-defined type substitution you'd end up with:
which is clearly wrong. I think this is something someone has to learn about JCR. Maybe we could make it clearer in the draft. |
But haven't we already bent to the "be more JSON like" by allowing colon before objects and arrays? That's what has caused the issue. Looking at the base cause of the confusion, it's the hunting for the missing
Here target rules are easy to spot as they are preceeded by |
I'm afraid I'm still not feeling the love for it! Allowing : before objects and arrays allows us to start out with a JSON message (mostly) and work from there with minimal editing. Once we're into defining named rules, we're moving well away from pure JSON so it seems reasonable to me that it no longer looks like JSON. If we did introduce a marker, presumably we'd enable something like:
To me "syntactic sugar" allows me to do something in a more concise way that I can already do in a more formal way. To me, the additional characters just add noise and extra typing. |
We seem to be retreading this ground. :) I agree the
|
Between the two, I think |
Hmm... since this issue arose from the confusion of a programmer, perhaps I should run the variations by him and a couple of other programmers to see which works. By variations, I mean the current syntax, and the various proposals here. I'll attempt to see if others are confused by the current syntax first. |
Thinking over night, the following might work:
The colon would signal the start of a type (rather than it's JSON purpose of separating name and type), but it could be omitted in situations where it was obvious what followed was a type, such as the start of an object / array, or within an array. So you'd have the following kinds of rule:
For arrays you'd have:
That looks like it might work. The idea that the colon is to mark the start of a type definition as opposed to being a separator is quite subtle and might confuse some people. That would come into play when defining something like $a_fixed_string_type. Would it lead to more confusion than we already have? Putting all those $ in would be a lot of work to update the test code! Tweaking the ABNF to allow colon in some contexts but not others might be a tough mental challenge! |
Ok. I just presented these ideas (except my idea with periods) to a room full of programmers, and got some valuable feedback. The primary thing they said was "valid JSON should be valid JCR". The liked the idea of '$' over '->', except they weren't wild about it on the left hand side. So:
Getting back to the primitive of the rules, maybe we should do this:
In other words, we remove the colon from value rules and it appears as require only in member rules. Of course, that brings us back to this conflict:
|
BTW, there was universal support for adding the equal sign. |
Thinking about this some more, regardless of the
In other words, our root cause is definition of named values. So perhaps we borrow from Perl and Ruby and use
The It makes the definitions of values different from other types of rules, but it is better to define an inconsistency with this rule definition than the placement of colons. |
I think if we go with $ in names, then we should have $ both where it's used and where it is defined. If we have:
then it raises the question, "are foo and $foo the same? Are they related in some special way?" Whereas, if you have:
there's no doubt that the 2 relate to the same thing. The equals sign makes it clear which role is which as well. It can be argued that the second one is a bit uglier, but I think clarity is more important. |
I think we should make colon the secret ingredient for defining stand-alone string values. So:
At least you don't have to remember a special random character for what might be quite a rare case. Once you've remembered that the special character is the same as the separator you're good to go. This topic looks like being JCR's Stack Overflow question! |
Maybe we should just accept that we have to put a bit of smarts into the parser to do the right thing for the user? If a string in a definition is followed by a : then it's a member rule, if not it's a regular value:
Parslet maybe able to give you that functionality out-the-box. In my C++ code I think I can assume that it's a type until I seem a following : and then move the string value into the member name field. |
Conceivably we could even allow:
But I think that would be quite a lot of grief for the code, which may reduce the number of implementations that get out there. |
Thanks for suffering through this, Pete. I think we do have to be considerate of what parsers can and cannot do. A lot of the ABNF parsers generate gobs of code, and good luck figuring out which part of that to contort. Therefore I think your idea of the colon before the string is our best option:
I don't know if we should allow a space between the colon and the quote or slash characters. My sense is no. As for the dollar sign, I think you are right. If it is to be required in one place, it is to be required everywhere. To be honest, I've never liked the bash approach. |
I hadn't connected that bash did it that way. One detail to check is what happens when we include aliases. We really need to do (so the $ sign indicates where the parsing is about to go):
That might suggest that $ is a marker, as opposed to part of the name, which could favor As for space after the colon in |
I agree on both of these issues. |
I've branched master and I'm working on putting in the dollar signs. I'll let you know how far I get. |
Based on my previous attempt, and in the hope it saves you going down the detour I did, you'll need something like:
i.e. |
Yes, I think I did just that. The branch is now there. Let me know what you think. |
The The tests tell us the Parslet rules are working. I can't see why the matching ABNF wouuldn't. |
Now in the checklist in #22. |
A colleague who has started using JCR for a server testing framework found this issue. Our new relaxed syntax rules allow a colon (':') character before objects and arrays, but not before target rule names. This caused a bit of confusion.
This looks like it should work, but doesn't.
This is what works:
The text was updated successfully, but these errors were encountered: