pointlander / peg

Peg, Parsing Expression Grammar, is an implementation of a Packrat parser generator.
BSD 3-Clause "New" or "Revised" License
1.02k stars 121 forks source link

Weird behavior with alternivies. #108

Open lolbinarycat opened 4 years ago

lolbinarycat commented 4 years ago

I have the following files: main.go:

package main

func main() {
    p := &Parser{Buffer:"test"}
    p.Init()
    err := p.Parse()
    if err != nil {panic(err)}
}

grammer.peg

package main

type Parser Peg {}

Rule <- ( "t"  / "test" ) !. 

running peg grammar.go && go run . results in the following error:

panic: 
parse error near Unknown (line 1 symbol 1 - line 1 symbol 1):
""

goroutine 1 [running]:
main.main()
        /home/binarycat/go/src/github.com/lolbinarycat/peg-bug/main.go:7 +0xb4
exit status 2

This doesn't seem intended, as it makes lots of things much harder to do. If it was intended, then this behavior should be clarified on the readme.

pointlander commented 4 years ago

More specific rules need to be first in alternates.

lolbinarycat commented 4 years ago

Yeah, obviously I know that know, but it would have been nice to know that 2 failed projects ago. The only thing in the readme that's remotely close to an explanation of this, is the line "rules are attempted in order". This should be updated to make this more clear. The readme needs to be updated in general, actually.