-
Notifications
You must be signed in to change notification settings - Fork 10
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
jsoniq parser #3
Comments
Glad you enjoy the package! |
|
I checked your example, and the issue seems Julia 1.5.0 related. Your example works in Julia 1.4.1 on my side. |
In that case, I guess I'll have to downgrade Julia. In regards to EBNF, defining the Grammar in Julia would be might be problematic due to recursive (and interdependent) definitions. Currently, I would solve those with an EDIT: actually, |
I worked around the compiler issue during sequence construction in order to support Julia 1.5 and be independent of the upstream fix - the performance dent will be negligible. Version 0.1.1 is pushed and registered :-). Recursive parsing is supported in CombinedParsers, and interdependent definitions can be added too with "push to Either": # Term expressions are sequences of subterms interleaved with operators.
# Sub terms are [`Either`](@ref) fast `TextParse.Numeric(Int)` integer numbers, converted to `Rational{Int}`,
@syntax subterm = Either{Rational{Int}}(Any[TextParse.Numeric(Int)]);
# A subterm can also be a nested term in parentheses
@syntax for parenthesis in subterm
mult = evaluate |> join(subterm, CharIn("*/"), infix=:prefix )
@syntax term = evaluate |> join(mult, CharIn("+-"), infix=:prefix )
Sequence(2,'(',adds,')')
end;
# This `CombinedParser` definition in 5,5 lines is sufficient for doing arithmetics:
# [`Base.join`](@ref)(x,infix; infix=:prefix) is shorthand for `x `[`*`](@ref)` `[`Repeat`](@ref)`( infix * x )`,
# and `f |> parser` is shorthand for [`map`](@ref)(f,parser)`.
@syntax term = adds;
# registers a `@term_string` macro for parsing and transforming.
term"(1+2)/5" I think it would be nice to have a string macro |
I've been poking around the library more, as well as learning more about julia macros. I hope that in a week maybe I'll have an EBNF parser and macro 🙂. |
I spent some time with it today and have added a few syntactic changes, so the EBNF parser syntax can be adapted very straightforwardly. I need to test a bit more, and will push the changes later tonight. I wonder: You plobably do not just want to parse jsoniq but transform into a query object with some business logic, right? |
Yes, sure. I am planning to attempt writing a jsoniq engine, and of course parsing is the first step 🙂.
You mean you are already integrating a jsoniq parser? |
cool!
Looking at the EBNF syntax, I found it convenient to define a whitespace separated sequence as Then I thought it would be most effective to provide a syntax scaffold to work from. The scaffold is a parser that results in nested tuples of the parsed parts. All you need to do then is mapping those to your engine's constructors. |
Hey, I updated CombinedParsers and wrote a gist for you with the scaffold. Note that I did not include parsers for NCName,D, _Char, etc. The gist is using Hope this helps! |
Thank you! I will study that code, and likely use it for my upcoming project 🙂. |
Hi, your package is really cool!
I'm trying to implement the JSONiq core grammar. This grammar uses the EBNF
except
symbol, to exclude otherwise valid matches (the specification itself uses it once, but it references the XML specification in places where it uses the except operator). However, it appears that this package does not support excluding otherwise valid matches.Would you be willing to add support for this? Or accept a PR (I don't know if I would manage it though 🙂, I'm new to Julia as well as parsing)?
The text was updated successfully, but these errors were encountered: