From a1e6e87df50aaef1dce280405b59ba2bfa93c0f3 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Fri, 1 Dec 2023 16:22:30 +0100 Subject: compiler: require nested flags to be at the end of the list This commit adds the requirement that nested flags must be at the end of the list of values. For example, flags1 = 1, 2, 3, 4, flags2 flags2 cannot be moved to another position in the list. The goal is to simplify parsing of the list by humans. Enforcing that the nested flags be at the end (vs. the beginning) makes things a bit easier for the parser. If we enforced that they should be at the beginning, then the parser would need to look further forward to determine if a flags definition is an integer flags or a string flags. flags1 = flags2, flags3, flags4, 5, 6 In this example, the parser would need to look to the 4th value in the list to tell that it's an integer flags. Suggested-by: Aleksandr Nogikh Signed-off-by: Paul Chaignon --- pkg/ast/ast.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'pkg/ast/ast.go') diff --git a/pkg/ast/ast.go b/pkg/ast/ast.go index 2e8a7a015..2458c1245 100644 --- a/pkg/ast/ast.go +++ b/pkg/ast/ast.go @@ -30,6 +30,7 @@ type Node interface { type Flags[T FlagValue] interface { SetValues(values []T) GetValues() []T + GetPos() Pos } type FlagValue interface { @@ -152,6 +153,10 @@ func (n *IntFlags) GetValues() []*Int { return n.Values } +func (n *IntFlags) GetPos() Pos { + return n.Pos +} + type StrFlags struct { Pos Pos Name *Ident @@ -170,6 +175,10 @@ func (n *StrFlags) GetValues() []*String { return n.Values } +func (n *StrFlags) GetPos() Pos { + return n.Pos +} + type TypeDef struct { Pos Pos Name *Ident -- cgit mrf-deployment