yhirose / cpp-peglib

A single file C++ header-only PEG (Parsing Expression Grammars) library
MIT License
880 stars 112 forks source link

Dictionary bug ? #209

Closed mingodad closed 2 years ago

mingodad commented 2 years ago

I'm trying to use the Dicitionary functionality but it doesn't seem to work properly, I mean only matching whole words.

Grammar:

START <- 'This is ' anyword ' ' MONTH '.'
MONTH <- 'Jan' | 'January' | 'Feb' | 'February' | '...'
anyword <- !MONTH [a-zA-z]+

Input ok:

This is when Jan.

Input not ok but I expected to be ok:

This is Febuo Jan.

Output error:

1:9 syntax error, unexpected 'Febuo', expecting <anyword>.
yhirose commented 2 years ago

Here is the correct grammer.

START <- 'This is ' anyword ' ' MONTH '.'
MONTH <- ('Jan' | 'January' | 'Feb' | 'February' | '...') ![a-zA-Z]
anyword <- !MONTH [a-zA-z]+
mingodad commented 2 years ago

Could you add that to the README ?

yhirose commented 2 years ago

This is not a problem of Dictionary in particular, since it happens with any literal rules...

image
mingodad commented 2 years ago

Thank you ! But I still think that having an example with ![a-zA-Z] or !IdChar on the README would help newcomers and probably less issues will be opened by then (like me).

yhirose commented 2 years ago

Yes, the current README is like a feature reference document... I agree that it would be very helpful for new users to have something like a practical user guild.

mingodad commented 2 years ago

Probably on the playground, a dropdown of examples with inputs, that can grow as new issues/questions arise. Like here https://go.dev/play/