Issue caputuring a single char quoted by quotation marks
bearbattle opened this issue · 0 comments
bearbattle commented
Hello,
I am trying to parse a char sequence where all quted by quitaion marks:
["a", "b", "c"]
// Or
['a', 'b', 'c']
I am using this struct to do the job:
type Char struct {
Val *byte `("\""|"'")@Char("\""|"'")`
}
However, when I am parse example, I got 1:1: unexpected token "'a'"
.
Here is the testcase:
func TestParseSingleChar(t *testing.T) {
parser := participle.MustBuild[Char]()
tests := []struct {
name string
input string
want byte
}{
{
"BackWithDoubleQuota",
`"a"`,
'0',
},
{
"BackWithNoQuote",
`a`,
'0',
},
{
"BackWithSingleQuota",
`'a'`,
'0',
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := parser.ParseString("", tt.input)
assert.NoError(t, err)
})
}
}
}
Result:
Error: Received unexpected error:
1:1: unexpected token "\"a\""
Test: TestChar_getValue/BackWithDoubleQuota
How do I get the job done with correct definition for Char
structure ?