parser: remove spaces errors in generated files
[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
19 $ template make_abs_tokens()
20 $ foreach {//token}
21 $ if {@parser_index}    
22 class @ename
23 special Token
24 end
25 $ end
26 $ end
27 class EOF
28 special Token
29 private init noinit do end
30 end
31 class PError
32 special EOF
33 private init noinit do end
34 end
35 $ end template
36
37 $ template make_tokens()
38
39 redef class Token
40     readable writable var _text: String
41
42     fun parser_index: Int is abstract
43
44     redef fun to_s: String do
45         return "'{_text}'"
46     end
47 end
48
49 $ foreach {//token}
50 $ if {@parser_index}
51 redef class @ename
52     redef fun parser_index: Int
53     do
54         return @parser_index
55     end
56
57 $ if {not(@text)}
58     init init_tk(text: String, loc: Location)
59     do
60         _text = text
61 $ else
62     init init_tk(loc: Location)
63     do
64         _text = once "${sablecc:string2escaped_unicode(@text)}"
65 $ end
66                 _location = loc
67     end
68 end
69
70 $ end if
71 $ end foreach
72
73 redef class EOF
74     redef fun parser_index: Int
75     do
76         return ${tokens/eof/@parser_index}
77     end
78
79     init(loc: Location)
80     do
81         _text = ""
82                 _location = loc
83     end
84 end
85
86 redef class PError
87     readable writable var _message: String
88
89     init init_error(message: String, loc: Location)
90     do
91                 init(loc)
92                 _message = message
93     end
94 end
95
96 $ end template