diff options
| author | s-ol <s+removethis@s-ol.nu> | 2021-05-01 22:32:33 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:24:49 +0000 |
| commit | 74b877c6a007fe032d47e11a31693149c9924102 (patch) | |
| tree | b8b7e042ed68dd1d2ed5c0dd38896af79cc60172 | |
| parent | fix (~ evt initial) bug (diff) | |
| download | alive-74b877c6a007fe032d47e11a31693149c9924102.tar.gz alive-74b877c6a007fe032d47e11a31693149c9924102.zip | |
add base.match.any shorthand
| -rw-r--r-- | alv/base/init.moon | 4 | ||||
| -rw-r--r-- | alv/base/match.moon | 28 |
2 files changed, 25 insertions, 7 deletions
diff --git a/alv/base/init.moon b/alv/base/init.moon index 69979a5..bfe9123 100644 --- a/alv/base/init.moon +++ b/alv/base/init.moon @@ -28,7 +28,7 @@ import PureOp from require 'alv.base.pureop' import Builtin from require 'alv.base.builtin' import FnDef from require 'alv.base.fndef' import Input from require 'alv.base.input' -import const, sig, evt from require 'alv.base.match' +import const, sig, evt, any from require 'alv.base.match' import Constant, SigStream, EvtStream from require 'alv.result' import T, Primitive, Array, Struct from require 'alv.type' import RTNode from require 'alv.rtnode' @@ -39,7 +39,7 @@ import Error from require 'alv.error' :Builtin :FnDef :Input - :const, :sig, :evt + :const, :sig, :evt, :any -- redundant exports, to keep anything an extension might need in one import diff --git a/alv/base/match.moon b/alv/base/match.moon index f362f80..8ee3e16 100644 --- a/alv/base/match.moon +++ b/alv/base/match.moon @@ -105,7 +105,7 @@ class Type extends Pattern return unless seq[i] type, mt = seq[i]\type!, seq[i]\metatype! - if not casts[@metatype .. mt] + if @metatype and not casts[@metatype .. mt] return match = if @type then type == @type else @remember type @@ -113,7 +113,7 @@ class Type extends Pattern 1, seq[i] __call: => @@ @metatype, @type, true - __tostring: => "#{@type or 'any'}#{@metatype}" + __tostring: => "#{@type or 'any'}#{@metatype or ''}" --- Repeat a pattern. -- @@ -279,7 +279,7 @@ const = setmetatable {}, { --- `Type` shorthands for matching `ValueStream`s and `Constant`s. -- --- Call or index with a string to obtain a `Type` instance. +-- Call or index with a type or string to obtain a `Type` instance. -- Call to obtain a wildcard pattern. -- -- sig.str, sig.num @@ -297,7 +297,7 @@ sig = setmetatable {}, { --- `Type` shorthands for matching `EvtStream`s. -- --- Call or index with a string to obtain an `Type` instance. +-- Call or index with a type or string to obtain an `Type` instance. -- Call to obtain a wildcard pattern. -- -- evt.bang, evt.str, evt.num @@ -313,7 +313,25 @@ evt = setmetatable {}, { __call: (...) => Type '!', ... } +--- `Type` shorthands for matching any `Result`s. +-- +-- Call or index with a type or string to obtain an `Type` instance. +-- Call to obtain a wildcard pattern. +-- +-- any.bang, any.str, any.num +-- any['midi/message'], any(Primitive 'midi/message') +-- any() +-- +-- @table evt +any = setmetatable {}, { + __index: (key) => + with v = Type nil, T[key] + @[key] = v + + __call: (...) => Type nil, ... +} + { :Type, :Repeat, :Sequence, :Choice, :Optional - :const, :sig, :evt + :const, :sig, :evt, :any } |
