Skip to content

Commit

Permalink
sistana: ok we have var pos for fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyElaina committed Sep 25, 2024
1 parent ecd3b53 commit 4d365c6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/arclet/alconna/sistana/model/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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 [])])
Expand Down

0 comments on commit 4d365c6

Please sign in to comment.