diff options
| author | 2026-03-09 23:05:42 +0300 | |
|---|---|---|
| committer | 2026-03-09 23:05:42 +0300 | |
| commit | 00394a80501960ad26787b5c44435ed5ed67ad84 (patch) | |
| tree | 672eb918c552c858f32e9533dc3799af6b75769f /model/model.go | |
| parent | '-' sign in words accepted (diff) | |
| download | conf-00394a80501960ad26787b5c44435ed5ed67ad84.tar.gz conf-00394a80501960ad26787b5c44435ed5ed67ad84.tar.bz2 conf-00394a80501960ad26787b5c44435ed5ed67ad84.tar.xz conf-00394a80501960ad26787b5c44435ed5ed67ad84.zip | |
Полностью переписал библиотеку. Перевёл с EBNF на PEG.v0.1.0
Diffstat (limited to '')
| -rw-r--r-- | model/model.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/model/model.go b/model/model.go new file mode 100644 index 0000000..2bc6dfb --- /dev/null +++ b/model/model.go @@ -0,0 +1,44 @@ +package model + +import ( + "iter" +) + +type Ident string + +type Command struct { + Name Ident + Args []any + Group Group +} + +// Value returns first argument of command. +func (c *Command) Value() any { + if len(c.Args) > 0 { + return c.Args[0] + } + return nil +} + +type Group []Command + +// Get returns first command with given name. +func (g Group) Get(name Ident) *Command { + for _, c := range g { + if c.Name == name { + return &c + } + } + return nil +} + +// Filter commands by predicate and returns iterator over filtered commands. +func (g Group) Filter(predicate func(c *Command) bool) iter.Seq[*Command] { + return func(yield func(*Command) bool) { + for _, c := range g { + if predicate(&c) && !yield(&c) { + return + } + } + } +} |
