alecthomas/participle

Adding a custom lexer rule without overriding current rules.

kafkiansky opened this issue · 0 comments

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"