syntax: enable a generalized for with iterate
[nit.git] / tests / base_for_custom.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import kernel
16
17 class A
18 var v: Int
19 fun iterate #!alt1#
20 #alt1# fun foo
21 !each(i: Int) #!alt2# #!alt5#
22 #alt5#!each(i: Int): Int
23 do
24 each(v)
25 end
26 end
27
28 class B
29 var v: Int
30 fun iterate
31 !each(i: Int, j: Bool)
32 do
33 each(v, v != 0)
34 end
35 end
36
37 var a = new A(5)
38 for i in a do #!alt3#
39 #alt3#for i, j in a do
40 i.output
41 end
42
43 var b = new B(5)
44 for i, j in b do #!alt4#
45 #alt4#for i in b do
46 i.output
47 j.output #!alt4#
48 end