aboutsummaryrefslogtreecommitdiffstats
path: root/core/pattern.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-03-02 11:41:33 +0000
committers-ol <s-ol@users.noreply.github.com>2020-03-02 11:41:33 +0000
commit03853b35a473161f377fb74a05723cacc5cbf36b (patch)
tree2e3df044cc0ff3ed24a07d6b5ee31682f077e5fa /core/pattern.moon
parentnew op interface part one (diff)
downloadalive-03853b35a473161f377fb74a05723cacc5cbf36b.tar.gz
alive-03853b35a473161f377fb74a05723cacc5cbf36b.zip
IO system
Diffstat (limited to 'core/pattern.moon')
-rw-r--r--core/pattern.moon11
1 files changed, 9 insertions, 2 deletions
diff --git a/core/pattern.moon b/core/pattern.moon
index 64b53b8..13497af 100644
--- a/core/pattern.moon
+++ b/core/pattern.moon
@@ -35,13 +35,20 @@ class Pattern
matched = while @matches results[1]
table.remove results, 1
- assert @opt or #matched > 0, "expected at least one argument for spread!"
+ assert @opt or #matched > 0, "expected at least one argument for spread"
matched
else
matches = @matches results[1]
- assert @opt or matches, "couldn't match argument #{results[1]} as type #{@type}!"
+ assert @opt or matches, "couldn't match argument #{results[1]} as #{@}"
if matches then table.remove results, 1
+ __tostring: =>
+ str = @type
+ str = '*' .. str if @splat
+ str = '=' .. str if @const
+ str = str .. '?' if @opt
+ str
+
match = (pattern, results) ->
patterns = while pattern
pat, rest = pattern\match '^([^ ]+) (.*)$'