diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-05-12 16:12:09 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:23:21 +0000 |
| commit | d6e1decfb1791913ff6b11eb6cb69129ceb1a7e9 (patch) | |
| tree | eadd79f8edd960b9d0f8c03a0d1dee8c38188648 | |
| parent | fix alv-lib (diff) | |
| download | alive-d6e1decfb1791913ff6b11eb6cb69129ceb1a7e9.tar.gz alive-d6e1decfb1791913ff6b11eb6cb69129ceb1a7e9.zip | |
base.match: never recall by default
| -rw-r--r-- | alv/base/match.moon | 7 | ||||
| -rw-r--r-- | spec/match_spec.moon | 6 |
2 files changed, 6 insertions, 7 deletions
diff --git a/alv/base/match.moon b/alv/base/match.moon index 74046f2..37d2fad 100644 --- a/alv/base/match.moon +++ b/alv/base/match.moon @@ -33,8 +33,7 @@ -- pattern = arg + arg -- -- ...will match either two numbers or two strings, but not one number and one --- string. Recalling works on `Choice` and `Type` patterns. `Type` patterns --- without a type (`val!` and `evt!`) always behave like this. +-- string. Recalling works on `Choice` and `Type` patterns. -- -- On `Sequence` patterns, a special method `:named` exists. It takes a -- sequence of keys that are used instead of integers when constructing the @@ -99,8 +98,7 @@ class Pattern -- @tparam string metatype `'~', '!' or '=' -- @tparam ?string type type name class Type extends Pattern - new: (@metatype, @type) => - @recall = not @type + new: (@metatype, @type, @recall=false) => casts = { '!!': true, '==': true, '~~': true, '~=': true } capture: (seq, i) => @@ -114,6 +112,7 @@ class Type extends Pattern if match 1, seq[i] + __call: => @@ @metatype, @type, true __tostring: => "#{@type or 'any'}#{@metatype}" --- Repeat a pattern. diff --git a/spec/match_spec.moon b/spec/match_spec.moon index bb4a42b..9764d5d 100644 --- a/spec/match_spec.moon +++ b/spec/match_spec.moon @@ -48,9 +48,9 @@ describe 'val and evt', -> assert.has.error -> evt!\match { str } assert.has.error -> evt!\match { num } - it 'is in recall mode', -> - value = val! - event = evt! + it 'can recall the type', -> + value = val!! + event = evt!! two_equal_values = value + value two_equal_events = event + event |
