create fail pass flag
This commit is contained in:
parent
3a843b21dc
commit
57f1fcd5f1
@ -230,7 +230,8 @@ func (p *choiceParser) parse(c *context) {
|
|||||||
c.failingParser = failingParser
|
c.failingParser = failingParser
|
||||||
if c.failingParser == nil &&
|
if c.failingParser == nil &&
|
||||||
p.commitType()&userDefined != 0 &&
|
p.commitType()&userDefined != 0 &&
|
||||||
p.commitType()&Whitespace == 0 {
|
p.commitType()&Whitespace == 0 &&
|
||||||
|
p.commitType()&FailPass == 0 {
|
||||||
c.failingParser = p
|
c.failingParser = p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package treerack
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -128,6 +129,11 @@ func findLine(tokens []rune, offset int) (line, column int) {
|
|||||||
|
|
||||||
func (c *context) parseError(p parser) error {
|
func (c *context) parseError(p parser) error {
|
||||||
definition := p.nodeName()
|
definition := p.nodeName()
|
||||||
|
flagIndex := strings.Index(definition, ":")
|
||||||
|
if flagIndex > 0 {
|
||||||
|
definition = definition[:flagIndex]
|
||||||
|
}
|
||||||
|
|
||||||
if c.failingParser == nil {
|
if c.failingParser == nil {
|
||||||
c.failOffset = c.consumed
|
c.failOffset = c.consumed
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ func flagsToCommitType(n []*Node) CommitType {
|
|||||||
ct |= Whitespace
|
ct |= Whitespace
|
||||||
case "nows":
|
case "nows":
|
||||||
ct |= NoWhitespace
|
ct |= NoWhitespace
|
||||||
|
case "failpass":
|
||||||
|
ct |= FailPass
|
||||||
case "root":
|
case "root":
|
||||||
ct |= Root
|
ct |= Root
|
||||||
}
|
}
|
||||||
|
@ -305,9 +305,34 @@ func TestLongestFail(t *testing.T) {
|
|||||||
doc:root = (expression (statement-separator+ expression)*)?
|
doc:root = (expression (statement-separator+ expression)*)?
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const doc = `f(a b c)`
|
||||||
|
|
||||||
testParseError(t, syntax, []errorTestItem{{
|
testParseError(t, syntax, []errorTestItem{{
|
||||||
title: "choice",
|
title: "fail on longest failing parser",
|
||||||
doc: "f(a b c)",
|
doc: doc,
|
||||||
|
perr: ParseError{
|
||||||
|
Offset: 4,
|
||||||
|
Line: 0,
|
||||||
|
Column: 4,
|
||||||
|
Definition: "function-application",
|
||||||
|
},
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFailPass(t *testing.T) {
|
||||||
|
const syntax = `
|
||||||
|
space:ws = " ";
|
||||||
|
symbol:nows = [a-z]+;
|
||||||
|
list-separator:failpass = ",";
|
||||||
|
argument-list:failpass = (symbol (list-separator+ symbol)*);
|
||||||
|
function-application = symbol "(" argument-list? ")";
|
||||||
|
`
|
||||||
|
|
||||||
|
const doc = `f(a b c)`
|
||||||
|
|
||||||
|
testParseError(t, syntax, []errorTestItem{{
|
||||||
|
title: "fail in outer definition",
|
||||||
|
doc: doc,
|
||||||
perr: ParseError{
|
perr: ParseError{
|
||||||
Offset: 4,
|
Offset: 4,
|
||||||
Line: 0,
|
Line: 0,
|
||||||
|
@ -314,7 +314,8 @@ func (p *sequenceParser) parse(c *context) {
|
|||||||
if currentCount < p.ranges[itemIndex][0] {
|
if currentCount < p.ranges[itemIndex][0] {
|
||||||
if c.failingParser == nil &&
|
if c.failingParser == nil &&
|
||||||
p.commitType()&userDefined != 0 &&
|
p.commitType()&userDefined != 0 &&
|
||||||
p.commitType()&Whitespace == 0 {
|
p.commitType()&Whitespace == 0 &&
|
||||||
|
p.commitType()&FailPass == 0 {
|
||||||
c.failingParser = p
|
c.failingParser = p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user