alecthomas / participle

A parser library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Declaring field parse order

rmfitzpatrick opened this issue · comments

This (extremely helpful) library may be currently incompatible with projects enforcing fieldalignment in the likely chance their ast fields aren't defined in an already optimal order. Is there an existing option or feature that allows using something like reflect's Type.FieldByName()?

type AST struct {
  Two string `@Ident`
  One string `@Ident`
}

func (a AST) ParseOrder() []string {
  return []string{"One", "Two"}
}

There is no option for this, no.

While I appreciate the use case, it's pretty niche, and reordering the fields would make understanding the grammar extremely difficult.

I've not had immediate luck in finding how to disable the analyzer for a given package/file and understand the potentially poor experience with such a helper method. Another thought would be to allow defining a parser from an ebnf grammar where terminals are field names to not require struct tags at all, but that's probably much more complicated.

I use golangci-lint which I believe includes this. It supports a //nolint:XXX directive

Thanks, though I'm referring to its cmd invocation fieldalignment -fix and will just have to enumerate paths rather than ./....