1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # Sample program that scan and load things.
17 # It shows the difference betwenn the various services of the `loader`.
22 # Display current loaded/known things.
23 fun stats
(mb
: ModelBuilder)
26 print
" model: mpackages={m.mpackages.length} mmodules={m.mmodules.length}"
27 print
" mb: identified modules={mb.identified_modules.length}; parsed modules={mb.parsed_modules.length}"
31 # Create a tool context to handle options and paths
32 var toolcontext
= new ToolContext
33 toolcontext
.keep_going
= true
35 # We do not add other options, so process them now!
36 toolcontext
.process_options
(args
)
37 var arguments
= toolcontext
.option_context
.rest
39 # We need a model to collect stuff
41 # And a model builder to parse files
42 var modelbuilder
= new ModelBuilder(model
, toolcontext
)
44 # Identify each argument independently
49 x
= modelbuilder
.identify_module
(a
)
51 print
"\tmodule {x.full_name} at {x.filepath or else "?"}"
53 var le
= modelbuilder
.last_loader_error
62 x
= modelbuilder
.identify_group
(a
)
64 print
"\tgroup {x.full_name} at {x.filepath or else "?"}"
66 var le
= modelbuilder
.last_loader_error
73 toolcontext
.check_errors
77 # Scan everything (including subdirectories)
78 var mm
= modelbuilder
.scan_full
(arguments
)
79 print
"scan_full found {mm.length} modules"
82 # Parse specific modules only
83 mm
= modelbuilder
.parse
(arguments
)
84 print
"parse found {mm.length} modules"
87 # Parse everything (including modules in subdirectories)
88 mm
= modelbuilder
.parse_full
(arguments
)
89 print
"parse_full found {mm.length} modules"