Code Monkey home page Code Monkey logo

Comments (8)

tippfelher avatar tippfelher commented on June 11, 2024 1

"bnf-parser": "^3.1.1",

I will try to make a better report. (already deleted everything after it failed xD)

from bnf-parser.

AjaniBilby avatar AjaniBilby commented on June 11, 2024

What version of the package are you using?
Because both of those parse for me

from bnf-parser.

AjaniBilby avatar AjaniBilby commented on June 11, 2024

I'm adding this as a automated test case just in case for future builds, however NPM is down for me and I want to make sure the two syntaxes from the different BNFs should make identical output syntax trees

from bnf-parser.

AjaniBilby avatar AjaniBilby commented on June 11, 2024

I managed to replicate your error - I have no idea how I didn't run into this when I have an actual programming language running off this as the syntax parser 😅

from bnf-parser.

tippfelher avatar tippfelher commented on June 11, 2024

All good. I needed a bnf parser yesterday and started to built one. Then I realized that, what I reported above, won't be handled by my parser and so I started to look out for existing solutions. (yours is the first I checked)

from bnf-parser.

AjaniBilby avatar AjaniBilby commented on June 11, 2024

I thought it was a bug just like you, but I realized it's actually expected behavior - the library assumes not parsing the whole string is a failure. So in your second case it would match the "a", then the program ends, but there is still a remaining character so it fails.

For both cases to be valid you would need to write it like this:

case1 ::= ( "a" | "aa" )+
case2 ::= ( "aa" | "a" )+

Ideally you should order your selects so options are ordered with the most unique and complex elements first.
I have literally thought my parser was broken before, then realizing actually I was just telling it to do the wrong thing.

from bnf-parser.

AjaniBilby avatar AjaniBilby commented on June 11, 2024

All good. I needed a bnf parser yesterday and started to built one. Then I realized that, what I reported above, won't be handled by my parser and so I started to look out for existing solutions. (yours is the first I checked)

Yeh, that's basically why I started mine as well, plus why I adapted BNF syntax to have the ommit character for easy clean up and stuff - the only thing I'm really unhappy with atm is the fact that sometimes it gives the wrong reference range for a syntax error.

i.e. if you have a syntax error in a function, it complains it can't parse at the start of the function body, instead of at the statement in the function

from bnf-parser.

AjaniBilby avatar AjaniBilby commented on June 11, 2024

@tippfelher, this might be a bit late, but I was thinking there are probably other people like you who expect a more non-deterministic select statement.
I was wondering do you think it would be worth adding a variant of || form |, where if you use || it will match all cases then return the best (consumes the most tokens) result, and | always just returns the first match. Thoughts?

It wouldn't be that hard to implement, since I am already comparing 'best result' of errors on a switch, so it returns the error from the option that got the furthest in consuming

from bnf-parser.

Related Issues (11)

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.