colm icon indicating copy to clipboard operation
colm copied to clipboard

[colm] regex subexpression capture

Open adrian-thurston opened this issue 5 years ago • 2 comments

This may be finished. Need to investigate.

adrian-thurston avatar Oct 19 '19 17:10 adrian-thurston

Experimented with a solution once, but certainly not complete in latest.

adrian-thurston avatar Nov 10 '19 14:11 adrian-thurston

Would be great to have this when parsing Go. There we are using a regex to decide when to insert semi colons. Looks like:

    token insert_semi /
        ( 
            ( id - 'if' - 'then' - 'else' - 'end' )
        )
        [ \t]*
        ( line_comment | '\n' )
    /
    {
        parse BA: break_apart[$match_text]

        Prefix: str = input->pull( BA.pre_semi.data.length )
        input->push( ";" )
        input->push( Prefix )
    }

Note that we need to parse the match text again just to learn where to insert the semi. If we had subexpression match we could use the length of that match to decide how much to pull off before pushing the semi.

adrian-thurston avatar Dec 12 '19 11:12 adrian-thurston