Error message for 'break closures' was changed and reused for 'do'.
Signed-off-by: Jean Privat <jean@pryen.org>
###############################################################################
# A escapable block correspond to a block statement where break and/or continue can by used
-# For and while use this class. closures uses the EscapableClosure subclass.
+# 'for' and 'while' use this class
+# 'do' uses the BreakOnlyEscapableBlock subclass
+# closures uses the EscapableClosure subclass
class EscapableBlock
# The syntax node of the block
readable var _node: ANode
end
end
+# specific EscapableBlock where only break can be used
+class BreakOnlyEscapableBlock
+special EscapableBlock
+ redef fun is_break_block: Bool do return true
+
+ init(node: ANode) do super
+end
+
# specific EscapableBlock for closures
class EscapableClosure
special EscapableBlock
redef class ADoExpr
redef fun generate_icode(v)
do
+ var seq_old = v.seq
+ var seq = new ISeq
+ v.stmt(seq)
+ escapable.break_seq = seq
+ v.seq = seq
+
v.generate_stmt(n_block)
+
+ v.seq = seq_old
return null
end
end
if esc == null then return
if esc.is_break_block then
- v.error(self, "Error: 'continue' forbiden in break blocks.")
+ v.error(self, "Error: cannot 'continue', only 'break'.")
return
end
end
end
+redef class ADoExpr
+ # The corresponding escapable block
+ readable var _escapable: nullable EscapableBlock
+
+ redef fun accept_typing(v)
+ do
+ var escapable = new BreakOnlyEscapableBlock(self)
+ _escapable = escapable
+ v.escapable_ctx.push(escapable, n_label)
+
+ super
+
+ v.escapable_ctx.pop
+ _is_typed = true
+ end
+end
+
redef class AIfExpr
redef fun accept_typing(v)
do
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2009 Jean Privat <jean@pryen.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import kernel
+
+1.output
+do
+ 2.output
+ do
+ 3.output
+ do end label l3
+ #alt1#break label l2
+ #alt2#break label l3
+ #alt3#break label l4
+ #alt4#break
+ #alt5#continue label l1
+ break label l1
+ 4.output
+ end label l2#!alt6#
+ #alt6#end label l1
+ 5.output
+end label l1
+6.output
+
+#alt7#do end label l1
-alt/base_closure_break_alt6.nit:40,3--10: Error: 'continue' forbiden in break blocks.
+alt/base_closure_break_alt6.nit:40,3--10: Error: cannot 'continue', only 'break'.
-alt/base_closure_break_alt7.nit:41,3--14: Error: 'continue' forbiden in break blocks.
+alt/base_closure_break_alt7.nit:41,3--14: Error: cannot 'continue', only 'break'.
--- /dev/null
+1
+2
+3
+6
--- /dev/null
+1
+2
+3
+5
+6
--- /dev/null
+alt/base_label_do_alt2.nit:26,9--16: Syntax error: invalid label l3.
--- /dev/null
+alt/base_label_do_alt3.nit:27,9--16: Syntax error: invalid label l4.
--- /dev/null
+1
+2
+3
+5
+6
--- /dev/null
+alt/base_label_do_alt5.nit:29,3--19: Error: cannot 'continue', only 'break'.
--- /dev/null
+alt/base_label_do_alt6.nit:32,6--13: Syntax error: label l1 already defined at 34,5--12.
--- /dev/null
+alt/base_label_do_alt7.nit:38,8--15: Syntax error: label l1 already defined at 35,5--12.