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

Grammar-based approach? #7

Open
domenic opened this issue Feb 25, 2014 · 3 comments
Open

Grammar-based approach? #7

domenic opened this issue Feb 25, 2014 · 3 comments
Labels

Comments

@domenic
Copy link

domenic commented Feb 25, 2014

I think it'd be interesting, at the very least, to have a formal grammar for the names. Once you had that, you could move from the current algorithmic-parsing to one that applies different semantics to each syntactic goal. Perhaps I am too brain-damaged from reading ES specs but to me that would be easier to parse than the algorithm, and probably has other benefits in terms of guaranteed unambiguity etc.

@darobin
Copy link
Owner

darobin commented Feb 25, 2014

I certainly won't deny that the algorithmic approach is painful to read (it's not pleasant to write either). But I'm unsure about switching. Traditionally, grammar-based approaches have not been very good at producing interoperability; though it could be that in this case we could make it work since we can describe the behaviour on failure rather simply. And the grammar is pretty simple:

^([^\[]+)(?:(\[\d+\])|(\[[^\]]+\]))*(\[\])?$

I need to mull this over. Do you have a clearer example of what you have in mind?

@darobin darobin added the json label Feb 25, 2014
@domenic
Copy link
Author

domenic commented Feb 25, 2014

Well, I am not really familiar with the formal language stuff myself (sadly), but my impression was it would be based on parsing goals. Things like

Simple := <token>
ArrayIndex := <token> "[" <number> "]"
Append := <token> "[]"
Terminator := Simple | ArrayIndex | Append
Intermediate := Simple | ArrayIndex
Beginning := "" | Intermediate | Beginning Intermediate
Full := Beginning Terminator

(this is not correct in any way but meant to illustrate what I meant.)

The parsing goal is then Full, but you would specify how to handle each piece of it in some way.

Most of what I know on this subject I learned in a 30-minute talk at JSConf EU so maybe somebody who can form the words better could step in here...

@Boldewyn
Copy link
Contributor

Boldewyn commented Jun 3, 2014

A bit off-topic, but we could piggy-back RFC 6901 (JSON Pointer), where a grammar comes delivered free.

The syntax would be a bit different. And I seem to remember, that I suggested this before, but can't find the issue, where I did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants