metamodel: rename 'universal' to 'enum'
[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     readable var _text: String
40
41     fun parser_index: Int is abstract
42
43     redef fun to_s: String do
44         return "'{_text}'"
45     end
46 end
47
48 $ foreach {//token}
49 $ if {@parser_index}
50 redef class @ename
51     redef fun parser_index: Int
52     do
53         return @parser_index
54     end
55
56 $ if {not(@text)}
57     init init_tk(text: String, loc: Location)
58     do
59         _text = text
60 $ else
61     init init_tk(loc: Location)
62     do
63         _text = once "${sablecc:string2escaped_unicode(@text)}"
64 $ end
65                 _location = loc
66     end
67 end
68
69 $ end if
70 $ end foreach
71
72 redef class EOF
73     redef fun parser_index: Int
74     do
75         return ${tokens/eof/@parser_index}
76     end
77
78     init(loc: Location)
79     do
80         _text = ""
81                 _location = loc
82     end
83 end
84
85 redef class PError
86     readable var _message: String
87
88     init init_error(message: String, loc: Location)
89     do
90                 init(loc)
91                 _message = message
92     end
93 end
94
95 $ end template