yhirose / cpp-peglib

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

grammar mistake in the github home page #182

Closed asmwarrior closed 3 years ago

asmwarrior commented 3 years ago

In the home page of the github, I see this:

peg::parser parser(R"(
  ROOT  <-  _ ITEM (',' _ ITEM _)*
  ITEM  <-  ([a-z])+
  ~_    <-  [ \t]*
)");

parser["ROOT"] = [&](const SemanticValues& vs) {
  assert(vs.size() == 2); // should be 2 instead of 5.
};

auto ret = parser.parse(" item1, item2 ");

Please note that ([a-z])+ should be replaced by ([a-z0-9])+, otherwise, the test string " item1, item2 " will get failed to parse.

yhirose commented 3 years ago

@asmwarrior, oops... You are completely right! I'll fix it.

asmwarrior commented 3 years ago

Hi, there is still one issue in the next sample grammar after your fixed grammar.

peg::parser parser(R"(
  ROOT  <-  ~_ ITEM (',' ~_ ITEM ~_)*
  ITEM  <-  ([a-z])+
  _     <-  [ \t]*
)");

This should also be fixed.

yhirose commented 3 years ago

Thanks!