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

Adding a custom lexer rule without overriding current rules. #339

Closed
kafkiansky opened this issue May 6, 2023 · 0 comments
Closed

Adding a custom lexer rule without overriding current rules. #339

kafkiansky opened this issue May 6, 2023 · 0 comments

Comments

@kafkiansky
Copy link

I want to add a custom rule, but so that I don't have to specify all existing rules. Code example:

package main

import (
	"github.com/alecthomas/participle/v2"
	"github.com/alecthomas/participle/v2/lexer"
)

type Test struct {
	Name     string `"action" @String`
	Duration string `"duration" @Duration`
}

var (
	parser = participle.MustBuild[Action](
		participle.Unquote("String"),
		participle.Lexer(
			lexer.MustSimple([]lexer.SimpleRule{
				{`Duration`, `\d+.\d+.\d+`},
			}),
		),
	)
)

However, now I get an error: mapper:(participle.Mapper)(0x10e0240)} uses unknown token "String"

Repository owner locked and limited conversation to collaborators May 6, 2023
@alecthomas alecthomas converted this issue into discussion #340 May 6, 2023

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