Skip to content

Commit

Permalink
fix(#27): resolve possibilities on their root path rather than first …
Browse files Browse the repository at this point in the history
…subpath
  • Loading branch information
pandatix committed Jul 15, 2024
1 parent a518de1 commit 02f12e8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion grammar.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func Parse(input []byte, grammar *Grammar, rootRulename string) ([]*Path, error)
if poss.End == len(input) {
pth := poss.Subpaths[0]
pth.MatchRule = rootRulename
outPoss = append(outPoss, pth)
outPoss = append(outPoss, poss)
}
}

Expand Down Expand Up @@ -764,6 +764,9 @@ func lexABNF(input []byte, path *Path) (any, error) {
}, nil
}

if len(path.Subpaths) == 1 {
return lexABNF(input, path.Subpaths[0])
}
panic(fmt.Sprintf("unhandlable path from %d to %d: \"%s\" ; sneek peak around \"%s\"", path.Start, path.End, input[path.Start:path.End], input[max(path.Start-10, 0):min(path.End+10, 0)]))
}

Expand Down
8 changes: 8 additions & 0 deletions grammar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ var fixedAbnfAbnf []byte
//go:embed testdata/fixed-abnf-raw.abnf
var fixedAbnfRawAbnf []byte

//go:embed testdata/aftn.abnf
var aftnAbnf []byte

//go:embed testdata/fuzz_regex_eaa469604868c87f.abnf
var fuzzRegex_eaa469604868c87fAbnf []byte

Expand Down Expand Up @@ -109,6 +112,11 @@ var testsParseAbnf = map[string]struct {
Validate: false,
ExpectErr: false,
},
"aftn": {
Input: aftnAbnf,
Validate: false,
ExpectErr: false,
},
"Fuzz_9de7f1cac25b4c59": {
// This fuzz crasher enabled detecting invalid repetition's repeat
// min/max values extraction.
Expand Down
6 changes: 6 additions & 0 deletions testdata/aftn.abnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
header = heading address originator
heading = ("0" / "1") 3ALPHAUPPER 4DIGIT SP 1*10DIGIT
address = CRLF ("AA" / "BB" / "CC") SP 8ALPHAUPPER CRLF
originator = 6DIGIT SP 8ALPHAUPPER CRLF ("0" / "2")

ALPHAUPPER = %x41-5a

0 comments on commit 02f12e8

Please sign in to comment.