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
|
||||
if c.failingParser == nil &&
|
||||
p.commitType()&userDefined != 0 &&
|
||||
p.commitType()&Whitespace == 0 {
|
||||
p.commitType()&Whitespace == 0 &&
|
||||
p.commitType()&FailPass == 0 {
|
||||
c.failingParser = p
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package treerack
|
||||
|
||||
import (
|
||||
"io"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
@ -128,6 +129,11 @@ func findLine(tokens []rune, offset int) (line, column int) {
|
||||
|
||||
func (c *context) parseError(p parser) error {
|
||||
definition := p.nodeName()
|
||||
flagIndex := strings.Index(definition, ":")
|
||||
if flagIndex > 0 {
|
||||
definition = definition[:flagIndex]
|
||||
}
|
||||
|
||||
if c.failingParser == nil {
|
||||
c.failOffset = c.consumed
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ func flagsToCommitType(n []*Node) CommitType {
|
||||
ct |= Whitespace
|
||||
case "nows":
|
||||
ct |= NoWhitespace
|
||||
case "failpass":
|
||||
ct |= FailPass
|
||||
case "root":
|
||||
ct |= Root
|
||||
}
|
||||
|
@ -305,9 +305,34 @@ func TestLongestFail(t *testing.T) {
|
||||
doc:root = (expression (statement-separator+ expression)*)?
|
||||
`
|
||||
|
||||
const doc = `f(a b c)`
|
||||
|
||||
testParseError(t, syntax, []errorTestItem{{
|
||||
title: "choice",
|
||||
doc: "f(a b c)",
|
||||
title: "fail on longest failing parser",
|
||||
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{
|
||||
Offset: 4,
|
||||
Line: 0,
|
||||
|
@ -314,7 +314,8 @@ func (p *sequenceParser) parse(c *context) {
|
||||
if currentCount < p.ranges[itemIndex][0] {
|
||||
if c.failingParser == nil &&
|
||||
p.commitType()&userDefined != 0 &&
|
||||
p.commitType()&Whitespace == 0 {
|
||||
p.commitType()&Whitespace == 0 &&
|
||||
p.commitType()&FailPass == 0 {
|
||||
c.failingParser = p
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user