syntax: 'meth' -> 'fun', 'attr' -> 'var'
[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     readable var _filename: String 
42     readable var _line: Int 
43     readable var _pos: Int 
44     
45     fun parser_index: Int is abstract
46
47     redef fun to_s: String do
48         return "'{_text}'"
49     end
50 end
51
52 $ foreach {//token}
53 $ if {@parser_index}    
54 redef class @ename
55     redef fun parser_index: Int
56     do
57         return @parser_index
58     end
59
60 $ if {not(@text)}
61     init init_tk(text: String, fname: String, line: Int, pos: Int)
62     do
63         _text = text
64 $ else
65     init init_tk(fname: String, line: Int, pos: Int)
66     do
67         _text = once "${sablecc:string2escaped_unicode(@text)}"
68 $ end
69         _filename = fname
70         _line = line
71         _pos = pos
72     end
73 end
74
75 $ end if 
76 $ end foreach
77
78 redef class EOF 
79     redef fun parser_index: Int
80     do
81         return ${tokens/eof/@parser_index}
82     end
83     
84     init(fname: String, line: Int, pos: Int)
85     do
86         _filename = fname
87         _text = ""
88         _line = line
89         _pos = pos
90     end
91 end
92
93 redef class PError
94     readable writable var _message: String 
95     
96     init init_error(fname: String, line: Int, pos: Int, message: String)
97     do
98         init(fname, line, pos)
99         _message = message
100     end
101 end
102
103 $ end template