Skip to content
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

possible bug in tag syntax #249

Open
marco-m opened this issue Jun 26, 2022 · 3 comments
Open

possible bug in tag syntax #249

marco-m opened this issue Jun 26, 2022 · 3 comments

Comments

@marco-m
Copy link
Contributor

marco-m commented Jun 26, 2022

Hello,

it seems there is a difference between the "raw" and "parse" tag syntax? The following repro shows what I stumbled upon.

package tagsyntax

import (
	"testing"

	"github.com/alecthomas/assert/v2"
	"github.com/alecthomas/participle/v2"
)

type GoodAST struct {
	Key        string   `parser:"@Ident '='"`
	BlankLines []string `"\n"`
}

type BadAST struct {
	Key string `parser:"@Ident '='"`
	// Same as field in GoodAST, as explained in https://github.com/alecthomas/participle#tag-syntax
	BlankLines []string `parser:"'\n'"`
}

func TestLiteralNotTerminatedGood(t *testing.T) {
	_, err := participle.Build(&GoodAST{})

	assert.NoError(t, err)
}

func TestLiteralNotTerminatedBad(t *testing.T) {
	_, err := participle.Build(&BadAST{})

	// The error is:
	//
	//     Key: <input>:1:2: literal not terminated
	//
	// which is confusing because it refers to the previous field in the struct (Key)
	// and unclear?
	assert.NoError(t, err)
}
@alecthomas
Copy link
Owner

It's a bit unclear, what's the bug? That it's not correctly decoding an escaped \n?

@svex99
Copy link

svex99 commented Sep 11, 2022

I receive the same error. When is declared the field tag with parser:"'\n'" raises the error literal not terminated. Change it to '\n' works.

@alecthomas
Copy link
Owner

I think this is because '\n' is currently lexed by text/scanner, which does not support single escape sequences in single quotes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants