GithubHelp home page GithubHelp logo

Comments (6)

alecthomas avatar alecthomas commented on May 18, 2024

The lack of context does make some things a bit more difficult, that’s for sure. In the specific example of the SQL parser I’d probably just not make SELECT a keyword.

But generally, I’m not sure. I have solved this in one parser by pushing the statefulness down into the lexer. This was a parser for a nested string interpolation language eg. ”hello ${who “nested ${other}”}”. A similar approach can be used for indentation aware languages like Python. I don’t think this approach would be very applicable to the SQL example though as too much logic would have to be pushed down into the lexer.

I’m not against non-CFG but I don’t know if there’s an elegant way to express the grammar like EBNF?

from participle.

beebeeep avatar beebeeep commented on May 18, 2024

just not make SELECT a keyword.

Well, it's still nice to have separate keyword type, in particular case - for case-insensitive keyword matching (btw, I've seen that pointlander/peg is using 'token' for case-sensitive matching and "token" for case-insensitive - a bit unobvious but quite elegant)

Regarding how this type ambiguity can be expressed in grammar, for me it seems like no changes here needed - if parser failed to parse current token with given type, it could ask lexer for other options. Or else lexer can have Token.Type as []rune, with standard parser return 1-element slice with option to create custom lexer with multiple choices.

from participle.

alecthomas avatar alecthomas commented on May 18, 2024

Regarding how this type ambiguity can be expressed in grammar, for me it seems like no changes here needed - if parser failed to parse current token with given type, it could ask lexer for other options. Or else lexer can have Token.Type as []rune, with standard parser return 1-element slice with option to create custom lexer with multiple choices.

I don't think that's a general solution to contextual-grammars, it just solves one specific example. For example that would not work for the example of the nested interpolation grammar I gave.

from participle.

alecthomas avatar alecthomas commented on May 18, 2024

btw, I've seen that pointlander/peg is using 'token' for case-sensitive matching and "token" for case-insensitive - a bit unobvious but quite elegant

I think this is a good idea; the current approach of case case normalisation isn't really a good one. I think I'll add a parser option to do this, eg. participle.CaseInsensitive("Keyword").

from participle.

beebeeep avatar beebeeep commented on May 18, 2024

I've been thinking about this for a while - yeah, looks like subj has too narrow scope; also have no other ideas, unfortunately, so I'd rather close issue.

from participle.

alecthomas avatar alecthomas commented on May 18, 2024

I've added the CaseInsensitive() option.

from participle.

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.