Skip to content

Commit

Permalink
Capture - support positional in addition to current named capturing
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyash-b committed Jul 6, 2024
1 parent 7158da8 commit 25d7aa9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/stdlib.ngs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,8 @@ section "=~ Matching" {
throw Error("=~ is expected to either set result or return a boolean").set(given=result)
}
# TODO: Review MatchSuccess / MatchFailure construction (conversion from MatchContext)
result returns MatchSuccess([x], pattern)
# TODO: Review Success / Failure inheritance
result returns MatchSuccess(mc.positional, pattern).set('named', mc.named)
MatchFailure(x, pattern)
}

Expand Down Expand Up @@ -1089,12 +1090,20 @@ section "=~ Matching" {

section "Capture" {
type Capture
F init(c:Capture, pattern=Any) {
init(args())
c.name = null
}
F init(c:Capture, name:Str, pattern=Any) init(args())

F =~(x, c:Capture, mc:MatchContext) {
(=~)(x, c.pattern, mc)::{
if A {
mc.named[c.name] = x
if c.name is not Null {
mc.named[c.name] = x
} else {
mc.positional.push(x)
}
}
}
}
Expand Down

0 comments on commit 25d7aa9

Please sign in to comment.