Code Monkey home page Code Monkey logo

Comments (5)

peter-winter avatar peter-winter commented on May 22, 2024

There is no official standalone lexer feature. There is a way, but I'm not convinced it should be official in its current state.
If you want you can look under the hood and see how regex parser implements it's lexer.

from ctpg.

peter-winter avatar peter-winter commented on May 22, 2024

Or did I just completely misunderstood you and you want to just use the regex lexer without the actual parser?
In this case you are out of luck. You could theoretically create a huge regex with all lexical tokens (just separate them with | ) like this:
(token_1_regex)|(token_2_regex)
but unfortunately there is no support for grouping captures.
You won't know which sub-regex was actually matched.
I'm open implementing this feature, this would take some time though.

from ctpg.

BenHanson avatar BenHanson commented on May 22, 2024

Yes, I was hoping to be able to use the lexer without the parser.
If you have the ability for your regexes to have numeric ids you just include that in the end state for each regex. You resolve ambiguity by only setting the id in an end state if one has not already been set.
(As you hinted at your lexer generator should or all the regexes together)

from ctpg.

peter-winter avatar peter-winter commented on May 22, 2024

I guess I could do a standalone lexer feature, it shouldn't be too hard to expose some interface for that. Like you said I already am creating a DFA from all the terminal symbols.
It would be a lexer class that resemble a parser interface but simpler, just the terms(...) call is enough.
And then a 'match' method accepting same kinds of arguments (buffer, options, error stream) and returning an index and a string view of a matched text.

from ctpg.

BenHanson avatar BenHanson commented on May 22, 2024

There are a couple of conventions:

  • If there is no match for the lexer at the current position, you usually return a single character (I return an id of ~0 in this case too). This allows you to continue lexing.
  • It is customary to return 0 for End of Input.

from ctpg.

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.