Skip to content

Commit

Permalink
sistana: widen prefix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyElaina committed Sep 25, 2024
1 parent aaa614c commit a76ec63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/arclet/alconna/sistana/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,17 @@ def loopflow(self, snapshot: AnalyzeSnapshot[T], buffer: Buffer[T]) -> LoopflowE
return LoopflowExitReason.unsatisfied

if pointer_type is PointerRole.PREFIX:
if not isinstance(token.val, str):
return LoopflowExitReason.header_expect_str

if context.prefixes is not None:
prefix = context.prefixes.get_closest_prefix(buffer.first()) # type: ignore
if prefix == "":
return LoopflowExitReason.prefix_mismatch
if not isinstance(token.val, str):
return LoopflowExitReason.header_expect_str

if context.prefixes is not None:
prefix = context.prefixes.get_closest_prefix(buffer.first()) # type: ignore
if prefix == "":
return LoopflowExitReason.prefix_mismatch

token.apply()
buffer.pushleft(token.val[len(prefix) :])
token.apply()
buffer.pushleft(token.val[len(prefix) :])

traverse.ref = traverse.ref.parent.header() # 直接进 header.
elif pointer_type is PointerRole.HEADER:
Expand Down
4 changes: 3 additions & 1 deletion src/arclet/alconna/sistana/model/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def build(
subcommand = cls(
header=header,
preset=Preset(),
prefixes=TrieHard(list(prefixes)),
compact_header=compact_header,
satisfy_previous=satisfy_previous,
separators=separators,
Expand All @@ -60,6 +59,9 @@ def build(
)
subcommand.add_track(header, fragments, header=header_fragment)

if prefixes:
subcommand.prefixes = TrieHard(list(prefixes))

return subcommand

@property
Expand Down

0 comments on commit a76ec63

Please sign in to comment.