1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2008 Jean Privat <jean@pryen.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Full syntax analysis of NIT AST.
18 # Detect syntax and some metamodel errors.
25 # Loader of nit source files
28 redef type MODULE: MMSrcModule
30 redef fun file_type
do return "nit"
32 redef fun parse_file
(context
, file
, filename
, name
, dir
)
34 var lexer
= new Lexer(file
, filename
)
35 var parser
= new Parser(lexer
)
36 var node_tree
= parser
.parse
37 if node_tree
.n_base
== null then
38 var err
= node_tree
.n_eof
40 context
.error
("{err.locate}: {err.message}")
43 var node_module
= node_tree
.n_base
44 assert node_module
isa AModule
45 var module = new MMSrcModule(context
, node_module
, dir
, name
, filename
)
49 redef fun process_metamodel
(context
, module)
51 module.process_supermodules
(context
)
52 module.process_syntax
(context
)
58 redef class MMSrcModule
59 # Loading and syntax analysis of super modules
60 private fun process_supermodules
(tc
: ToolContext)
62 node
.import_super_modules
(tc
, self)
65 # Syntax analysis and MM construction for the module
66 # Require than supermodules are processed
67 private fun process_syntax
(tc
: ToolContext)
70 if tc
.error_count
> 0 then exit
(1)
73 if tc
.error_count
> 0 then exit
(1)