From a480026f2a5cfab112f7e029a1a533dc3f7c9d2e Mon Sep 17 00:00:00 2001 From: Fabien Fleutot Date: Mon, 2 Feb 2009 21:03:15 +0100 Subject: [PATCH] fixed trycatch --- src/lib/metalua/extension/match.mlua | 17 ++++++++++------- src/lib/metalua/extension/trycatch.mlua | 4 +--- src/samples/trycatch_test.mlua | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/lib/metalua/extension/match.mlua b/src/lib/metalua/extension/match.mlua index 2e747ef..3581b0c 100644 --- a/src/lib/metalua/extension/match.mlua +++ b/src/lib/metalua/extension/match.mlua @@ -174,13 +174,16 @@ function regexp_pattern_element_builder (pattern, term, cfg) assert (regexp.tag=="String", "Left hand side operand for '/' in a pattern must be ".. "a literal string representing a regular expression") - assert (sub_pattern.tag=="Table", - "Right hand side operand for '/' in a pattern must be ".. - "an identifier or a list of identifiers") - for x in ivalues(sub_pattern) do - assert (x.tag=="Id" or x.tag=='Dots', - "Right hand side operand for '/' in a pattern must be ".. - "a list of identifiers") + if sub_pattern.tag=="Table" then + for x in ivalues(sub_pattern) do + assert (x.tag=="Id" or x.tag=='Dots', + "Right hand side operand for '/' in a pattern must be ".. + "a list of identifiers") + end + else + assert (sub_pattern.tag=="Id", + "Right hand side operand for '/' in a pattern must be ".. + "an identifier or a list of identifiers") end -- Regexp patterns can only match strings diff --git a/src/lib/metalua/extension/trycatch.mlua b/src/lib/metalua/extension/trycatch.mlua index 7c7e4d8..5466a07 100644 --- a/src/lib/metalua/extension/trycatch.mlua +++ b/src/lib/metalua/extension/trycatch.mlua @@ -11,10 +11,8 @@ -{ extension 'H' } -{ extension 'log' } -require 'metalua.extension.match' - -- Get match parsers and builder, for catch cases handling: -local match_alpha = require 'extension.match' +local match_alpha = require 'metalua.extension.match' local H = H:new{side='inside', alpha = match_alpha } -- We'll need to track rogue return statements: diff --git a/src/samples/trycatch_test.mlua b/src/samples/trycatch_test.mlua index aff10c4..fa4f671 100644 --- a/src/samples/trycatch_test.mlua +++ b/src/samples/trycatch_test.mlua @@ -32,7 +32,7 @@ print "4) error, with a finally" try print " Hi" error "bang" -catch "bang"/_ then +catch "bang"/{_} then print " Bang caught" finally print " Finally OK" @@ -47,7 +47,7 @@ try catch "some_other_error" then assert (false, "mismatch, this must not happen") end -catch "some_error"/x then + catch "some_error"/{x} then printf(" Successfully caught %q across a try that didn't catch", x) catch x then assert (false, "We shouldn't reach this catch-all") -- 2.44.0