1 $ // This file is part of NIT ( http://www.nitlanguage.org ).
3 $ // Copyright 2008 Jean Privat <jean@pryen.org>
4 $ // Based on algorithms developped for ( http://www.sablecc.org/ ).
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
10 $ // http://www.apache.org/licenses/LICENSE-2.0
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.
18 $ template make_lexer()
20 redef fun make_token(accept_token, location)
24 if accept_token == ${position()-1} then
25 $ if {count(transition[@from!=@to])!=0}
27 $ foreach transition in {transition[@from!=@to]}
28 if state_id == ${/parser/lexer_data/state[@name=$transition/@from]/@id} then
29 _state = state_${translate(@to,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")}
33 return new @ename.init_tk(location)
37 abort # unknown token index `accept_token`
45 $ template make_lexer_table()
46 $ foreach {lexer_data/goto_table/state}
49 static const int lexer_goto_row${position()}[] = {
52 @low, @high, @state[-sep ','-]
57 static const int lexer_goto_row_null[] = {0};
58 const int* const lexer_goto_table[] = {
61 lexer_goto_row${position()}[-sep ','-]
63 lexer_goto_row_null[-sep ','-]
69 $ foreach {lexer_data/accept_table/state}
70 const int lexer_accept_table[] = {
71 [-foreach {i}-]${.}[-sep ','-][-end foreach-]