use numeric ids during init
This commit is contained in:
parent
94a21ae755
commit
50592ed83f
8
char.go
8
char.go
@ -30,8 +30,8 @@ func (p *charParser) nodeName() string { return p.name }
|
||||
func (p *charParser) nodeID() int { return p.id }
|
||||
func (p *charParser) setID(id int) { p.id = p.id }
|
||||
|
||||
func (p *charParser) parser(r *registry, parsers []string) (parser, error) {
|
||||
if stringsContainDeprecated(parsers, p.name) {
|
||||
func (p *charParser) parser(r *registry, parsers *idSet) (parser, error) {
|
||||
if parsers.has(p.id) {
|
||||
panic(cannotIncludeParsers(p.name))
|
||||
}
|
||||
|
||||
@ -47,8 +47,8 @@ func (p *charParser) commitType() CommitType {
|
||||
return p.commit
|
||||
}
|
||||
|
||||
func (p *charParser) setIncludedBy(includedBy parser, parsers []string) {
|
||||
if stringsContainDeprecated(parsers, p.name) {
|
||||
func (p *charParser) setIncludedBy(includedBy parser, parsers *idSet) {
|
||||
if parsers.has(p.id) {
|
||||
panic(cannotIncludeParsers(p.name))
|
||||
}
|
||||
|
||||
|
13
choice.go
13
choice.go
@ -27,7 +27,7 @@ func (d *choiceDefinition) nodeName() string { return d.name }
|
||||
func (d *choiceDefinition) nodeID() int { return d.id }
|
||||
func (d *choiceDefinition) setID(id int) { d.id = id }
|
||||
|
||||
func (d *choiceDefinition) parser(r *registry, parsers []string) (parser, error) {
|
||||
func (d *choiceDefinition) parser(r *registry, parsers *idSet) (parser, error) {
|
||||
p, ok := r.parser(d.name)
|
||||
if ok {
|
||||
return p, nil
|
||||
@ -42,7 +42,8 @@ func (d *choiceDefinition) parser(r *registry, parsers []string) (parser, error)
|
||||
r.setParser(cp)
|
||||
|
||||
var elements []parser
|
||||
parsers = append(parsers, d.name)
|
||||
parsers.set(d.id)
|
||||
defer parsers.unset(d.id)
|
||||
for _, e := range d.elements {
|
||||
element, ok := r.parser(e)
|
||||
if ok {
|
||||
@ -76,8 +77,8 @@ func (d *choiceDefinition) commitType() CommitType {
|
||||
func (p *choiceParser) nodeName() string { return p.name }
|
||||
func (p *choiceParser) nodeID() int { return p.id }
|
||||
|
||||
func (p *choiceParser) setIncludedBy(includedBy parser, parsers []string) {
|
||||
if stringsContainDeprecated(parsers, p.name) {
|
||||
func (p *choiceParser) setIncludedBy(includedBy parser, parsers *idSet) {
|
||||
if parsers.has(p.id) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -120,7 +121,7 @@ func (p *choiceParser) parse(t Trace, c *context) {
|
||||
}
|
||||
|
||||
c.exclude(c.offset, p.id)
|
||||
defer c.include(c.offset, p.id) // TODO: test if can be optimized
|
||||
initialOffset := c.offset
|
||||
|
||||
node := newNode(p.name, p.id, c.offset, c.offset, p.commit)
|
||||
var match bool
|
||||
@ -157,10 +158,12 @@ func (p *choiceParser) parse(t Trace, c *context) {
|
||||
if match {
|
||||
// t.Out1("choice, success")
|
||||
c.success(node)
|
||||
c.include(initialOffset, p.id) // TODO: test if can be optimized
|
||||
return
|
||||
}
|
||||
|
||||
// t.Out1("fail")
|
||||
c.store.set(node.From, p.name, nil)
|
||||
c.fail(node.From)
|
||||
c.include(initialOffset, p.id) // TODO: test if can be optimized
|
||||
}
|
||||
|
4
parse.go
4
parse.go
@ -6,14 +6,14 @@ type definition interface {
|
||||
nodeName() string
|
||||
nodeID() int
|
||||
setID(int)
|
||||
parser(*registry, []string) (parser, error)
|
||||
parser(*registry, *idSet) (parser, error)
|
||||
commitType() CommitType
|
||||
}
|
||||
|
||||
type parser interface {
|
||||
nodeName() string
|
||||
nodeID() int
|
||||
setIncludedBy(parser, []string)
|
||||
setIncludedBy(parser, *idSet)
|
||||
storeIncluded(*context, *Node)
|
||||
parse(Trace, *context)
|
||||
}
|
||||
|
15
sequence.go
15
sequence.go
@ -28,8 +28,8 @@ func (d *sequenceDefinition) nodeName() string { return d.name }
|
||||
func (d *sequenceDefinition) nodeID() int { return d.id }
|
||||
func (d *sequenceDefinition) setID(id int) { d.id = id }
|
||||
|
||||
func (d *sequenceDefinition) parser(r *registry, parsers []string) (parser, error) {
|
||||
if stringsContainDeprecated(parsers, d.name) {
|
||||
func (d *sequenceDefinition) parser(r *registry, parsers *idSet) (parser, error) {
|
||||
if parsers.has(d.id) {
|
||||
panic(cannotIncludeParsers(d.name))
|
||||
}
|
||||
|
||||
@ -51,7 +51,8 @@ func (d *sequenceDefinition) parser(r *registry, parsers []string) (parser, erro
|
||||
ranges [][]int
|
||||
)
|
||||
|
||||
parsers = append(parsers, d.name)
|
||||
parsers.set(d.id)
|
||||
defer parsers.unset(d.id)
|
||||
for _, item := range d.items {
|
||||
if item.Min == 0 && item.Max == 0 {
|
||||
item.Min, item.Max = 1, 1
|
||||
@ -97,8 +98,8 @@ func (d *sequenceDefinition) commitType() CommitType {
|
||||
func (p *sequenceParser) nodeName() string { return p.name }
|
||||
func (p *sequenceParser) nodeID() int { return p.id }
|
||||
|
||||
func (p *sequenceParser) setIncludedBy(includedBy parser, parsers []string) {
|
||||
if stringsContainDeprecated(parsers, p.name) {
|
||||
func (p *sequenceParser) setIncludedBy(includedBy parser, parsers *idSet) {
|
||||
if parsers.has(p.id) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -136,7 +137,7 @@ func (p *sequenceParser) parse(t Trace, c *context) {
|
||||
}
|
||||
|
||||
c.exclude(c.offset, p.id)
|
||||
defer c.include(c.offset, p.id)
|
||||
initialOffset := c.offset
|
||||
|
||||
items := p.items
|
||||
ranges := p.ranges
|
||||
@ -157,6 +158,7 @@ func (p *sequenceParser) parse(t Trace, c *context) {
|
||||
// t.Out1("fail, item failed")
|
||||
c.store.set(node.From, p.name, nil)
|
||||
c.fail(node.From)
|
||||
c.include(initialOffset, p.id)
|
||||
return
|
||||
}
|
||||
|
||||
@ -186,4 +188,5 @@ func (p *sequenceParser) parse(t Trace, c *context) {
|
||||
}
|
||||
|
||||
c.success(node)
|
||||
c.include(initialOffset, p.id)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user