yhirose / cpp-peglib

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

Error parsing valid charset class #195

Closed mingodad closed 2 years ago

mingodad commented 2 years ago

Trying to parse a valid peg grammar with cpp-peglib I found that it doesn't accept the charset class shown bellow:

plusorless  <-  [+-]

Playgound output:

1:21 syntax error

Changing Range to the one shown bellow fix the issue:

Range <-  (Char  '-'  ! ']' Char) /  Char

Hardcoded fix in peglib.h:

g["Range"] <= cho(seq(g["Char"], chr('-'), npd(chr(']')), g["Char"]), g["Char"]);
yhirose commented 2 years ago

@mingodad, thank you for the feedback. I tried to make the cpp-httplib PEG parser syntax as faithful as the one described on the 2nd page in the original Bryan Ford paper, but the enhancement that you suggests looks reasonable. I'll consider to take the suggestion. Thank you.

image
mingodad commented 2 years ago

Another missing feature are some escape sequences like \v, \f, ...

Char        <- '\\' [abefnrtv'"[\]\\^]
yhirose commented 2 years ago

\v, \f are same as #87.