osa1 / lexgen

A fully-featured lexer generator, implemented as a proc macro
MIT License
63 stars 7 forks source link

Implement Default for Loc #44

Closed MiSawa closed 2 years ago

MiSawa commented 2 years ago

Thank you for the amazing lexer!

The generated lexer seems to be 99% compatible with what lalrpop takes. The only incompatibility is the lack of Default implementation for lexgen_util::Loc, which lalrpop uses to initialize the location. If there's no reason not to implement it, it'd be great to have it implemented so that the following just works (with type Location = lexgen_util::Loc and type Error = lexgen_util::LexerError<MyError> defined in the extern section of the .lalrpop file).

let lexer = Lexer::new(query); // The lexgen-generated lexer
let query = QueryParser::new() // The lalrpop-generated parser
    .parse(query, lexer)
    .unwrap();
osa1 commented 2 years ago

Thanks for reporting this and the PR.

lalrpop compatibility has always been a goal since the early days, but I never got around using lexgen with lalrpop as I originally planned, instead I wrote my own parsers.

Btw, if you're interested in implementing a lexgen-lalrpop example or a test I would be happy to merge that as well :-)

MiSawa commented 2 years ago

Opened PR that adds an example! :) https://github.com/osa1/lexgen/pull/46

MiSawa commented 2 years ago

Hi, I'm wondering if this change can be published so we don't need to specify dependency via lexgen = { git = "..." } :)

osa1 commented 2 years ago

Hi, I'm wondering if this change can be published so we don't need to specify dependency via lexgen = { git = "..." } :)

Done :)

MiSawa commented 2 years ago

Awesome, thank you!!