Merge: introduce nit_env.sh to setup the shell environement
[nit.git] / lib / niti_runtime.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
9 # another product.
10
11 # Runtime library to loop around the main program for each line in file-name arguments
12 #
13 # Used by the interpreter when `-n` is used
14 module niti_runtime
15
16 redef class Sys
17 redef fun run do
18 if not args.is_empty then
19 open_next_stream
20 end
21 loop
22 read_next_line
23 main
24 end
25 end
26
27 # Read the next useful line from file-name arguments
28 private fun read_next_line
29 do
30 while stdin.eof do
31 open_next_stream
32 end
33 self.line = stdin.read_line
34 end
35
36 # Open the next file until there is no more arguments
37 private fun open_next_stream
38 do
39 if args.is_empty then exit(0)
40 stdin.close
41 stdin = new FileReader.open(args.shift)
42 end
43
44 # The next line to process by the main program
45 var line: String is noautoinit
46 end