alecthomas / alecthomas/participle

bug: lexer codegen should validate token identifiers are valid

Offen
#202 6 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Go
Sterne
3.9k
Forks
213
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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 !

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.