Coder Social home page Coder Social logo

Comments (4)

jon-hanson avatar jon-hanson commented on May 23, 2024

It's difficult to diagnose without seeing the definition of quotedSegment et al. If you can post a minimal complete example (i.e. one that compiles) that exhibits the problem, then I can take a look.

Also, can you elaborate on what you mean when you say it doesn't work. Do you get an error?

from funcj.

kpadmasola avatar kpadmasola commented on May 23, 2024

Hi Jon,

Thank you for your response. I have created a sample at https://github.com/kpadmasola/funcj-sample/tree/master

Yes, I get an error when I run the program. I'm not sure if I am making any mistake when defining the grammar.

The App.java has example paths that need to be parsed. It contains both single segment and multi segment paths.
When I use the singleSegmentPath parser (https://github.com/kpadmasola/funcj-sample/blob/master/src/main/java/org/example/Grammar.java#L102), the single segment paths get parsed correctly and multi segment paths fail as expected.

I defined multi segment path parser here https://github.com/kpadmasola/funcj-sample/blob/master/src/main/java/org/example/Grammar.java#L110, which is supposed to handle both single and multi segment paths, but it is now failing right on the first single segment path test in App.java.

I'd like the grammar to be able to handle both single and multi segment paths. The only complexity is in the last segment -- it can be just a *(wildcard segment) or "abc"* (wildcard suffix segment) or xyz (normal segment) or "pqr" (quoted segment). I can manually handle the complexity of last segment in my application and simplify the grammar to include only normal segment and quoted segment. But before I take that route, I just want to understand why I am not able to handle it it the grammar.

Please let me know if you need any more details. Appreciate your help with this.

thanks,
Krishna
PS: for quoted segment, I used your code from json parser grammar for json string parsing.

from funcj.

jon-hanson avatar jon-hanson commented on May 23, 2024

I think the first issue is this:

      choice(normalSegment, quotedSegment)
         .andL(period).many()

This rule is saying that it will accept zero or more of a segment followed by a period. So these all parse:

Segment Period
Segment Period Segment Period

etc. However a Segment on its own does not parse because it's not followed by a period. So the first test in app ("a") fails for this reason.

from funcj.

kpadmasola avatar kpadmasola commented on May 23, 2024

thanks, that makes sense.

from funcj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.