mna / pigeon

Command pigeon generates parsers in Go from a PEG grammar.
BSD 3-Clause "New" or "Revised" License
835 stars 66 forks source link

Parse (and ignore) comments in code blocks #80

Closed ear7h closed 5 years ago

ear7h commented 5 years ago

The following block of in a .peg file was yielding a parse error, presumably from the braces in the comments. My change adds a Comment clause (not sure if right word here) in the Code definition so they can be handled appropriately.

Value = "("_ val:Expr _ ")" {
    return val, nil
} / val:(ImLit / RealLit / IntLit) {
    fmt.Printf("Value: %T %v \n", val, val)
    return val, nil
// } / name:(Ident / "struct" / "class") "{" fields:{
// composite literal
} / val:Ident {
    return &Value{val.(string), Ident}, nil
}

the errror:

parse error(s):
 grammar.peg:384:53 (7488): no match found, expected: "!", "#", "&", "'", "(", ".", "/*", "//", "[", "\"", "\n", "`", [ \t\r] or [\pL_]
breml commented 5 years ago

Hi @ear7h Thanks for your fix. In order to get this into pegeon in a controlled way, I would like you to provide a minimal test case for the problem (see test/issue_18 for an example), which can be executed before applying your change and after to verify your solution. Additionally I updated pigeon to pass the tests at travisci again, so the tests in this PR should become green, once you have rebased it onto the master branch.

ear7h commented 5 years ago

@breml Thanks for pointing me to an example test, lmk if you'd like any more changes to the PR

ear7h commented 5 years ago

@breml I've pushed the fixes, could you please review it again?

breml commented 5 years ago

@ear7h Thanks for the updated PR. I will try to have a look at this soon.

breml commented 5 years ago

LGTM

@ear7h Thanks for your PR.