alecthomas / alecthomas/participle

bug: lexer codegen should validate token identifiers are valid

Aberta
#202 6 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Go
Estrelas
3.9k
Forks
213
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

Hi,

I've been playing with Participle and I wanted to try to codegen feature, however the generated code seems to not escape some characters, leading to uncompilable source.

See the following example :

```golang
// ...
} else if match := match:(l.s, l.p); match[1] != 0 {
sym = -47
groups = match[:]
} else if match := match;(l.s, l.p); match[1] != 0 {
sym = -48
groups = match[:]
} else if match := match|(l.s, l.p); match[1] != 0 {
sym = -49
groups = match[:]
} else if match := match,(l.s, l.p); match[1] != 0 {
sym = -50
groups = match[:]
} else if match := match@(l.s, l.p); match[1] != 0 {
sym = -51
groups = match[:]
}
// ...
```

My rules used :

```golang
{
// ...
{":", `:`, nil},
{";", `;`, nil},
{"|", `\|`, nil},
{",", `,`, nil},
{"@", `@`, nil},
// ...
}
```

As far as I can tell it comes from https://github.com/alecthomas/participle/blob/master/lexer/codegen.go#L251

While I do agree that I could rename my Rule name to make the whole thing works, I think it might be a good idea to come up with some strategy in order to avoid this when generating code.

I'm fine with writting a PR if you have a idea for this.

Cheers !

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.