7a883f7931f8c2a99f84907c830e7bce935d14ca
[nit.git] / src / parser / xss / tokens.xss
1 $ // This file is part of NIT ( http://www.nitlanguage.org ).
2 $ //
3 $ // Copyright 2008 Jean Privat <jean@pryen.org>
4 $ // Based on algorithms developped for ( http://www.sablecc.org/ ).
5 $ //
6 $ // Licensed under the Apache License, Version 2.0 (the "License");
7 $ // you may not use this file except in compliance with the License.
8 $ // You may obtain a copy of the License at
9 $ //
10 $ //     http://www.apache.org/licenses/LICENSE-2.0
11 $ //
12 $ // Unless required by applicable law or agreed to in writing, software
13 $ // distributed under the License is distributed on an "AS IS" BASIS,
14 $ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 $ // See the License for the specific language governing permissions and
16 $ // limitations under the License.
17
18 $ template make_abs_tokens()
19 $ foreach {//token}
20 $ if {@parser_index}    
21 class @ename
22         super Token
23 end
24 $ end
25 $ end
26 class EOF
27         super Token
28 private init noinit do end
29 end
30 class PError
31         super EOF
32 private init noinit do end
33 end
34 $ end template
35
36 $ template make_tokens()
37
38 redef class Token
39     var _text: nullable String
40
41     redef fun text
42     do
43         var res = _text
44         if res != null then return res
45         res = location.text
46         _text = res
47         return res
48     end
49
50     fun parser_index: Int is abstract
51 end
52
53 $ foreach {//token}
54 $ if {@parser_index}
55 redef class @ename
56     redef fun parser_index: Int
57     do
58         return @parser_index
59     end
60
61     init init_tk(loc: Location)
62     do
63                 _location = loc
64     end
65 end
66
67 $ end if
68 $ end foreach
69
70 redef class EOF
71     redef fun parser_index: Int
72     do
73         return ${tokens/eof/@parser_index}
74     end
75
76     init(loc: Location)
77     do
78         _text = ""
79                 _location = loc
80     end
81 end
82
83 redef class PError
84     readable var _message: String
85
86     init init_error(message: String, loc: Location)
87     do
88                 init(loc)
89                 _message = message
90     end
91 end
92
93 $ end template