diff --git a/grammar.go b/grammar.go index 789167c..d6f2fd0 100644 --- a/grammar.go +++ b/grammar.go @@ -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) } } @@ -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)])) } diff --git a/grammar_test.go b/grammar_test.go index 6242c21..debb208 100644 --- a/grammar_test.go +++ b/grammar_test.go @@ -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 @@ -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. diff --git a/testdata/aftn.abnf b/testdata/aftn.abnf new file mode 100644 index 0000000..c5fc587 --- /dev/null +++ b/testdata/aftn.abnf @@ -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