refactor - build phase
This commit is contained in:
parent
60172b2f9f
commit
1a27c52e7c
21
choice.go
21
choice.go
@ -206,14 +206,17 @@ func (b *choiceBuilder) build(c *context) ([]*Node, bool) {
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.buildPending(c.offset, b.id, to) {
|
from := c.offset
|
||||||
return nil, false
|
parsed := to > from
|
||||||
}
|
|
||||||
|
|
||||||
c.markBuildPending(c.offset, b.id, to)
|
if parsed {
|
||||||
|
|
||||||
if to-c.offset > 0 {
|
|
||||||
c.results.dropMatchTo(c.offset, b.id, to)
|
c.results.dropMatchTo(c.offset, b.id, to)
|
||||||
|
} else {
|
||||||
|
if c.buildPending(c.offset, b.id, to) {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
c.markBuildPending(c.offset, b.id, to)
|
||||||
}
|
}
|
||||||
|
|
||||||
var option builder
|
var option builder
|
||||||
@ -228,14 +231,14 @@ func (b *choiceBuilder) build(c *context) ([]*Node, bool) {
|
|||||||
panic("damaged parse result")
|
panic("damaged parse result")
|
||||||
}
|
}
|
||||||
|
|
||||||
from := c.offset
|
|
||||||
|
|
||||||
n, ok := option.build(c)
|
n, ok := option.build(c)
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("damaged parse result")
|
panic("damaged parse result")
|
||||||
}
|
}
|
||||||
|
|
||||||
c.unmarkBuildPending(from, b.id, to)
|
if !parsed {
|
||||||
|
c.unmarkBuildPending(from, b.id, to)
|
||||||
|
}
|
||||||
|
|
||||||
if b.commit&Alias != 0 {
|
if b.commit&Alias != 0 {
|
||||||
return n, true
|
return n, true
|
||||||
|
50
sequence.go
50
sequence.go
@ -239,22 +239,11 @@ func (b *sequenceBuilder) build(c *context) ([]*Node, bool) {
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.buildPending(c.offset, b.id, to) {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
c.markBuildPending(c.offset, b.id, to)
|
|
||||||
|
|
||||||
if to-c.offset > 0 {
|
|
||||||
c.results.dropMatchTo(c.offset, b.id, to)
|
|
||||||
}
|
|
||||||
|
|
||||||
from := c.offset
|
from := c.offset
|
||||||
|
parsed := to > from
|
||||||
|
|
||||||
if b.allChars {
|
if b.allChars {
|
||||||
c.offset = to
|
c.offset = to
|
||||||
c.unmarkBuildPending(from, b.id, to)
|
|
||||||
|
|
||||||
if b.commit&Alias != 0 {
|
if b.commit&Alias != 0 {
|
||||||
return nil, true
|
return nil, true
|
||||||
}
|
}
|
||||||
@ -265,6 +254,14 @@ func (b *sequenceBuilder) build(c *context) ([]*Node, bool) {
|
|||||||
To: to,
|
To: to,
|
||||||
tokens: c.tokens,
|
tokens: c.tokens,
|
||||||
}}, true
|
}}, true
|
||||||
|
} else if parsed {
|
||||||
|
c.results.dropMatchTo(c.offset, b.id, to)
|
||||||
|
} else {
|
||||||
|
if c.buildPending(c.offset, b.id, to) {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
c.markBuildPending(c.offset, b.id, to)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -286,32 +283,31 @@ func (b *sequenceBuilder) build(c *context) ([]*Node, bool) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed := c.offset > itemFrom
|
if c.offset > itemFrom {
|
||||||
|
|
||||||
if parsed {
|
|
||||||
nodes = append(nodes, n...)
|
nodes = append(nodes, n...)
|
||||||
currentCount++
|
currentCount++
|
||||||
}
|
|
||||||
|
|
||||||
if !parsed {
|
if b.ranges[itemIndex][1] >= 0 && currentCount == b.ranges[itemIndex][1] {
|
||||||
if currentCount < b.ranges[itemIndex][0] {
|
itemIndex++
|
||||||
for i := 0; i < b.ranges[itemIndex][0]-currentCount; i++ {
|
currentCount = 0
|
||||||
nodes = append(nodes, n...)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
itemIndex++
|
|
||||||
currentCount = 0
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.ranges[itemIndex][1] >= 0 && currentCount == b.ranges[itemIndex][1] {
|
if currentCount < b.ranges[itemIndex][0] {
|
||||||
itemIndex++
|
for i := 0; i < b.ranges[itemIndex][0]-currentCount; i++ {
|
||||||
currentCount = 0
|
nodes = append(nodes, n...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemIndex++
|
||||||
|
currentCount = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
c.unmarkBuildPending(from, b.id, to)
|
if !parsed {
|
||||||
|
c.unmarkBuildPending(from, b.id, to)
|
||||||
|
}
|
||||||
|
|
||||||
if b.commit&Alias != 0 {
|
if b.commit&Alias != 0 {
|
||||||
return nodes, true
|
return nodes, true
|
||||||
|
Loading…
Reference in New Issue
Block a user