From: handa Date: Wed, 28 Oct 2009 11:21:46 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eefa0b9efaf141df3fbfadb8bc31b09e6d55adc3;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/XmlExpr.cs b/XmlExpr.cs index 9952974..53c7641 100644 --- a/XmlExpr.cs +++ b/XmlExpr.cs @@ -169,7 +169,7 @@ namespace System.Xml for (int i = 0; i < args.Length; i++) { args[i] = args[i].Eval (domain); - if (domain.Thrown) + if (domain.Thrown ()) return args[i]; } } @@ -279,27 +279,31 @@ namespace System.Xml { Bindings current = domain.bindings; Term result = Zero; + int rest_idx = max_idx < 0 ? - max_idx : args.Length; - try { - for (int i = 0; i < min_arg; i++) - domain.Bind (this.args[i], args[i]); - if (body != null) - { - try { - domain.Catch (CatchTag.Return); - foreach (Term term in body) - { - result = term.Eval (domain); - if (domain.Thrown) - return result; - } - } finally { - domain.Uncatch (); + for (int i = 0; i < rest_idx; i++) + domain.Bind (this.args[i], args[i]); + if (i < args.Length) + { + List rest = new List (); + + for (; i < args.Length; i++) + rest.Add (args[i]); + domain.Bind (this.args[rest_idx], rest); + } + + if (body != null) + { + domain.Catch (CatchTag.Return); + foreach (Term term in body) + { + result = term.Eval (domain); + if (domain.Thrown ()) + break; } - } - } finally { - domain.UnboundTo (current); - } + domain.Uncatch (); + } + domain.UnboundTo (current); return result; } } @@ -388,7 +392,7 @@ namespace System.Xml foreach (Term term in body) { result = term.Eval (domain); - if (domain.Thrown) + if (domain.Thrown ()) return result; } } finally { @@ -743,7 +747,18 @@ namespace System.Xml catch_count--; } - public bool Thrown { get { return catch_count < catch_stack.Count; } } + public bool Thrown () { return catch_count < catch_stack.Count; } + + public bool Thrown (out bool caught) + { + if (catch_count < catch_stack.Count) + { + caught = catch_count == catch_stack.Count - 1; + return true; + } + caught = false; + return false; + } internal void ThrowReturn () { @@ -1583,11 +1598,11 @@ namespace System.Xml Term result = Zero; try { domain.Catch (CatchTag.Break); - while (! domain.Thrown) + while (! domain.Thrown ()) foreach (Term arg in args) { result = arg.Eval (domain); - if (domain.Thrown) + if (domain.Thrown ()) return result; } } finally { @@ -1601,11 +1616,11 @@ namespace System.Xml Term result = Zero; try { domain.Catch (CatchTag.Break); - while (! domain.Thrown && args[0].Eval (domain).IsTrue) + while (! domain.Thrown () && args[0].Eval (domain).IsTrue) for (int i = 1; i < args.Length; i++) { result = args[i].Eval (domain); - if (domain.Thrown) + if (domain.Thrown ()) return result; } } finally { @@ -1628,7 +1643,7 @@ namespace System.Xml domain.depth++; result = list[i].Eval (domain); domain.depth--; - if (domain.Thrown) + if (domain.Thrown ()) return result; } return result; @@ -1640,7 +1655,7 @@ namespace System.Xml private static Term Fforeach (Domain domain, Variable vari, Term[] args) { Term result = args[0].Eval (domain); - if (domain.Thrown) + if (domain.Thrown ()) return result; List list = result.Listval; Bindings current = domain.bindings; @@ -1654,7 +1669,7 @@ namespace System.Xml for (int i = 1; i < args.Length; i++) { result = args[i].Eval (domain); - if (domain.Thrown) + if (domain.Thrown ()) return result; } } finally { @@ -1688,19 +1703,28 @@ namespace System.Xml public static Term Fcatch (Domain domain, Variable vari, Term[] args) { Term result = Zero; + bool caught; - try { - domain.Catch (new CatchTag (args[0].Symval)); - for (int i = 1; i < args.Length; i++) - { - result = args[i].Eval (domain); - if (domain.Thrown) + domain.Catch (new CatchTag (args[0].Symval)); + for (int i = 1; i < args.Length; i++) + { + result = args[i].Eval (domain); + if (domain.Thrown (out caught)) + { + domain.Uncatch (); + if (caught) + { + if (vari != null) + vari.Value = result; + return One; + } return result; - } - } finally { - domain.Uncatch (); - } - return result; + } + } + domain.Uncatch (); + if (vari != null) + vari.Value = result; + return Zero; } public static Term Fthrow (Domain domain, Variable vari, Term[] args) @@ -2333,7 +2357,7 @@ namespace System.Xml foreach (Term term in terms) { result = term.Eval (domain); - if (domain.Thrown) + if (domain.Thrown ()) return result; } } finally {