blynn / nex

Lexer for Go
http://cs.stanford.edu/~blynn/nex/
GNU General Public License v3.0
416 stars 47 forks source link

Unpaired curly inside string confuses nex #48

Open purpleidea opened 6 years ago

purpleidea commented 6 years ago

Quite hilariously, an unpaired curly brace inside nex golang code causes lex/parse errors with nex itself!

Example:

/\$[a-z][a-z0-9]*{[0-9]+}/
        {
            yylex.pos(lval) // our pos
            s := yylex.Text()
            a := strings.Split(s, "{") // XXX: close match here: }
            lval.str = a[0]
            return IDENTIFIER
        }

Note the comment I added with a close brace. I added that as a workaround so that this works. Remove it and you'll see nex errors:

panic: unmatched '{'

goroutine 16 [running]:
runtime.gopanic
    ../../../libgo/go/runtime/panic.go:493
main.$nested34
    /builddir/build/BUILD/nex-5344f151fd3251726650dffd30a531d3f1bddc17/nex.go:1027
main.$nested35
    /builddir/build/BUILD/nex-5344f151fd3251726650dffd30a531d3f1bddc17/nex.go:1094
main.process
    /builddir/build/BUILD/nex-5344f151fd3251726650dffd30a531d3f1bddc17/nex.go:1099
main.main
    /builddir/build/BUILD/nex-5344f151fd3251726650dffd30a531d3f1bddc17/main.go:81
runtime_main
    ../../../libgo/runtime/proc.c:606

HTH

purpleidea commented 6 years ago

Interestingly enough as discovered in the source today it seems this is a known issue:

https://github.com/blynn/nex/blob/542279eaf3d8a7f5cc0eb94780323acb490e51c4/test/nex_test.go#L367

=D