skvadrik / re2c

Lexer generator for C, C++, Go and Rust.
https://re2c.org
Other
1.06k stars 169 forks source link

add support for V lang #469

Closed felipensp closed 1 month ago

felipensp commented 6 months ago

This PR aims to add support for V lang on re2c.

Example

fn lex(str string) {
    mut cursor := 0
    /*!re2c
        re2c:define:YYCTYPE = u8(0);
        re2c:define:YYPEEK = "str[cursor]";
        re2c:define:YYSKIP = "cursor += 1";
        re2c:yyfill:enable = 0;

        number = [1-9][0-9]*;

        number { return }
        *      { panic("error!") }
    */
}

fn main() {
    lex("1234\x00")
}

Running

re2v ../v_example_01.v | v run -

skvadrik commented 6 months ago

Hi @felipensp, thanks a lot for your work on this!

It would be great to add V backend, but it needs to be done in a different way. Recently there have been quite a few requests to add other languages (D, Js, OCaml, Zig... now V). The problem with the current approach is, it does not scale well: the code becomes polluted with special cases for each language. Most importantly, in order to test all re2c features with the new code, it is necessary to implement all examples and update docs, including https://re2c.org. Understandably, contributors don't have time for all this work.

So, I'm working on a different approach that will make implementing new backends as easy as writing a single config file that describes element of the syntax of the target language. See https://github.com/skvadrik/re2c/issues/450 for details. The work is being done on syntax-files branch. I already made good progress on this, and I even have OCaml support locally (which is much more different from C/C++ than V). So I think it will be an easy job to add V after this work is done.

With the new approach, we can have second-tier language support (just add a syntax file, but don't add any tests/docs). It won't affect re2c code.

Unfortunately, I have not much free time at the moment. I'm working on it, but but it's a matter of months, not weeks/days. I should not rush this work anyway, because the moment it gets released it will become stable user interface for the foreseeable future. So I cannot promise I will add V support soon.

Parts of your work can still be reused (those related to options and build systems).

skvadrik commented 4 months ago

Vlang support was added in experimental branch syntax-files in https://github.com/skvadrik/re2c/commit/73853c5ea7a98d19c174f508bb226876c61a024f.

skvadrik commented 4 months ago

In particular, see examples here: https://github.com/skvadrik/re2c/tree/73853c5ea7a98d19c174f508bb226876c61a024f/examples/v

skvadrik commented 1 month ago

Closing as obsolete - Vlang support has been merged into master.

felipensp commented 1 month ago

Many thanks @skvadrik