contrib: bring in the pep8 analysis framework
[nit.git] / contrib / pep8analysis / 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 end
29 class PError
30         super EOF
31 end
32 class PLexerError
33         super PError
34 end
35 class PParserError
36         super PError
37 end
38 $ end template
39
40 $ template make_tokens()
41
42 redef class Token
43     var _text: nullable String
44
45     redef fun text
46     do
47         var res = _text
48         if res != null then return res
49         res = location.text
50         _text = res
51         return res
52     end
53
54     redef fun text=(text)
55     do
56         _text = text
57     end
58
59     fun parser_index: Int is abstract
60 end
61
62 $ foreach {//token}
63 $ if {@parser_index}
64 redef class @ename
65     redef fun parser_index: Int
66     do
67         return @parser_index
68     end
69
70     init init_tk(loc: Location)
71     do
72                 _location = loc
73     end
74 end
75
76 $ end if
77 $ end foreach
78
79 redef class EOF
80     redef fun parser_index: Int
81     do
82         return ${tokens/eof/@parser_index}
83     end
84
85     init init_tk(loc: Location)
86     do
87         _text = ""
88                 _location = loc
89     end
90 end
91
92 redef class PError
93     readable var _message: String
94
95     init init_error(message: String, loc: Location)
96     do
97                 init_tk(loc)
98                 _message = message
99     end
100 end
101
102 redef class PLexerError
103     readable var _string: String
104
105     init init_lexer_error(message: String, loc: Location, string: String)
106     do
107                 init_error(message, loc)
108                 _string = string
109     end
110 end
111
112 redef class PParserError
113     readable var _token: Token
114
115     init init_parser_error(message: String, loc: Location, token: Token)
116     do
117                 init_error(message, loc)
118                 _token = token
119     end
120 end
121 $ end template