From 4d365c6abf8e49dc8292dd29e6908b4f33bde88f Mon Sep 17 00:00:00 2001 From: Elaina Date: Wed, 25 Sep 2024 08:30:14 +0800 Subject: [PATCH] sistana: ok we have var pos for fragments --- src/arclet/alconna/sistana/model/pattern.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/arclet/alconna/sistana/model/pattern.py b/src/arclet/alconna/sistana/model/pattern.py index fd5d62c4..13aeaf9e 100644 --- a/src/arclet/alconna/sistana/model/pattern.py +++ b/src/arclet/alconna/sistana/model/pattern.py @@ -101,9 +101,13 @@ def prefix_entrypoint(self): def header_entrypoint(self): return self.create_snapshot(self.root_ref.header()) + def add_track(self, name: str, fragments: Iterable[_Fragment]): + self.preset.tracks[name] = Track(deque(fragments)) + def subcommand( self, header: str, + *fragments: _Fragment, aliases: Iterable[str] = (), soft_keyword: bool = False, separators: str = SEPARATORS, @@ -121,15 +125,19 @@ def subcommand( self.subcommands[header] = pattern for alias in aliases: self.subcommands[alias] = pattern + + if fragments: + pattern.add_track(header, fragments) if compact_header: self.compact_keywords = TrieHard([header, *aliases, *(self.compact_keywords or [])]) - return self + return pattern def option( self, keyword: str, + *fragments: _Fragment, aliases: Iterable[str] = (), soft_keyword: bool = False, allow_duplicate: bool = False, @@ -144,6 +152,9 @@ def option( self.options[keyword] = pattern for alias in aliases: self.options[alias] = pattern + + if fragments: + self.add_track(keyword, fragments) if compact_header: self.compact_keywords = TrieHard([keyword, *aliases, *(self.compact_keywords or [])])