Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue caputuring a single char quoted by quotation marks #397

Closed
bearbattle opened this issue Apr 18, 2024 · 0 comments
Closed

Issue caputuring a single char quoted by quotation marks #397

bearbattle opened this issue Apr 18, 2024 · 0 comments

Comments

@bearbattle
Copy link

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 ?

Repository owner locked and limited conversation to collaborators Apr 18, 2024
@alecthomas alecthomas converted this issue into discussion #398 Apr 18, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant