diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-04-13 16:02:48 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-04-13 16:09:32 +0000 |
| commit | 56f99b5cd9152d37b6b14fa10f4ad0622665fbf6 (patch) | |
| tree | 55de010d0ab89141a63c2a8015bdca274c652b60 | |
| parent | lib/sc: docs, *sock* for socket arg (diff) | |
| download | alive-56f99b5cd9152d37b6b14fa10f4ad0622665fbf6.tar.gz alive-56f99b5cd9152d37b6b14fa10f4ad0622665fbf6.zip | |
core.base.match: better error reporting
| -rw-r--r-- | core/base/match.moon | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/core/base/match.moon b/core/base/match.moon index b0f81e9..700b50d 100644 --- a/core/base/match.moon +++ b/core/base/match.moon @@ -49,12 +49,19 @@ import ValueStream, EventStream from require 'core.stream' local Repeat, Sequence, Choice, Optional +typestr = (result) -> + str = result\type! + str ..= '!' if result\metatype! == 'event' + str + class Pattern match: (seq) => @reset! num, cap = @capture seq, 1 - assert num == #seq, do - Error 'argument', "couldn't match arguments against pattern #{@}" + if num != #seq + args = table.concat [typestr arg for arg in *seq], ' ' + msg = "couldn't match arguments (#{args}) against pattern #{@}" + error Error 'argument', msg cap remember: (key) => @@ -68,8 +75,8 @@ class Pattern reset: => @recalled = nil __call: => @ - __mul: (num) => Repeat @, 1, if num ~= 0 then num - __pow: (num) => Repeat @, 0, if num ~= 0 then num + __mul: (num) => Repeat @, 1, if num != 0 then num + __pow: (num) => Repeat @, 0, if num != 0 then num __add: (other) => Sequence { @, other } __div: (other) => Choice { @, other } __unm: => Optional @ @@ -106,7 +113,7 @@ class Type extends Pattern 1, seq[i] __tostring: => - str = tostring @type + str = @type or @metatype str ..= '!' if @metatype == 'event' str |
