First NIT release and new clean mercurial repository
[nit.git] / src / syntax / syntax.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2008 Jean Privat <jean@pryen.org>
4 #
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
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16
17 # Full syntax analysis of NIT AST.
18 # Detect syntax and some metamodel errors.
19 package syntax
20
21 import mmloader
22 import mmbuilder
23 import control_flow
24 import typing
25
26 # Loader of nit source files
27 class SrcModuleLoader
28 special ModuleLoader
29 redef type MODULE: MMSrcModule
30
31 redef meth file_type do return "nit"
32
33 redef meth parse_file(context, file, filename, name, dir)
34 do
35 var lexer = new Lexer(file, filename)
36 var parser = new Parser(lexer)
37 var node_tree = parser.parse
38 if node_tree.n_base == null then
39 var err = node_tree.n_eof
40 assert err isa PError
41 context.error("{err.locate}: {err.message}")
42 exit(1)
43 end
44 var node_module = node_tree.n_base
45 assert node_module isa AModule
46 var module = new MMSrcModule(context, node_module, dir, name)
47 #module.filename = fname
48 #module.mtime = fname.file_stat.mtime
49 return module
50 end
51
52 redef meth process_metamodel(context, module)
53 do
54 module.process_supermodules(context)
55 module.process_syntax(context)
56 end
57
58 init do end
59 end
60
61 redef class MMContext
62 # The current configuration/status of the tool
63 readable writable attr _tc: ToolContext
64 end
65
66 redef class MMSrcModule
67 # Loading and syntax analysis of super modules
68 private meth process_supermodules(tc: ToolContext)
69 do
70 node.import_super_modules(tc, self)
71
72 end
73
74 # Syntax analysis and MM construction for the module
75 # Require than supermodules are processed
76 private meth process_syntax(tc: ToolContext)
77 do
78 do_mmbuilder(tc)
79 if tc.error_count > 0 then exit(1)
80
81 do_control_flow(tc)
82 if tc.error_count > 0 then exit(1)
83
84 do_typing(tc)
85 if tc.error_count > 0 then exit(1)
86 end
87
88 end
89