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

Rule redeclaration causes segmentation fault #123

Open romshark opened 3 years ago

romshark commented 3 years ago

Expected behavior

In case of rule redeclaration the generator should return an error:

package main

type parser Peg {
}

main <- (a)+
a <- 'a'
a <- 'a'

Actual behavior

The invalid grammar crashes the generator due to a segmentation fault:

romanscharkov@RomMac pegbug % peg grammar.peg
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1164e55]

goroutine 1 [running]:
github.com/pointlander/peg/tree.(*Tree).Compile(0xc000074000, 0xc00001a0e0, 0xe, 0xc00000c060, 0x2, 0x2, 0x1200e60, 0xc00000e030, 0x0, 0x0)
        /Users/romanscharkov/go/src/github.com/pointlander/peg/tree/peg.go:1506 +0x1475
main.main()
        /Users/romanscharkov/go/src/github.com/pointlander/peg/main.go:87 +0x575