KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > percederberg > grammatica > test > RegexpTokenizer


1 /*
2  * RegexpTokenizer.java
3  *
4  * THIS FILE HAS BEEN GENERATED AUTOMATICALLY. DO NOT EDIT!
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2.1
9  * of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307, USA.
20  *
21  * Copyright (c) 2003 Per Cederberg. All rights reserved.
22  */

23
24 package net.percederberg.grammatica.test;
25
26 import java.io.Reader JavaDoc;
27
28 import net.percederberg.grammatica.parser.ParserCreationException;
29 import net.percederberg.grammatica.parser.TokenPattern;
30 import net.percederberg.grammatica.parser.Tokenizer;
31
32 /**
33  * A character stream tokenizer.
34  *
35  * @author Per Cederberg, <per at percederberg dot net>
36  * @version 1.0
37  */

38 class RegexpTokenizer extends Tokenizer {
39
40     /**
41      * Creates a new tokenizer for the specified input stream.
42      *
43      * @param input the input stream to read
44      *
45      * @throws ParserCreationException if the tokenizer couldn't be
46      * initialized correctly
47      */

48     public RegexpTokenizer(Reader JavaDoc input)
49         throws ParserCreationException {
50
51         super(input, false);
52         createPatterns();
53     }
54
55     /**
56      * Initializes the tokenizer by creating all the token patterns.
57      *
58      * @throws ParserCreationException if the tokenizer couldn't be
59      * initialized correctly
60      */

61     private void createPatterns() throws ParserCreationException {
62         TokenPattern pattern;
63
64         pattern = new TokenPattern(RegexpConstants.LEFT_PAREN,
65                                    "LEFT_PAREN",
66                                    TokenPattern.STRING_TYPE,
67                                    "(");
68         addPattern(pattern);
69
70         pattern = new TokenPattern(RegexpConstants.RIGHT_PAREN,
71                                    "RIGHT_PAREN",
72                                    TokenPattern.STRING_TYPE,
73                                    ")");
74         addPattern(pattern);
75
76         pattern = new TokenPattern(RegexpConstants.LEFT_BRACKET,
77                                    "LEFT_BRACKET",
78                                    TokenPattern.STRING_TYPE,
79                                    "[");
80         addPattern(pattern);
81
82         pattern = new TokenPattern(RegexpConstants.RIGHT_BRACKET,
83                                    "RIGHT_BRACKET",
84                                    TokenPattern.STRING_TYPE,
85                                    "]");
86         addPattern(pattern);
87
88         pattern = new TokenPattern(RegexpConstants.LEFT_BRACE,
89                                    "LEFT_BRACE",
90                                    TokenPattern.STRING_TYPE,
91                                    "{");
92         addPattern(pattern);
93
94         pattern = new TokenPattern(RegexpConstants.RIGHT_BRACE,
95                                    "RIGHT_BRACE",
96                                    TokenPattern.STRING_TYPE,
97                                    "}");
98         addPattern(pattern);
99
100         pattern = new TokenPattern(RegexpConstants.QUESTION,
101                                    "QUESTION",
102                                    TokenPattern.STRING_TYPE,
103                                    "?");
104         addPattern(pattern);
105
106         pattern = new TokenPattern(RegexpConstants.ASTERISK,
107                                    "ASTERISK",
108                                    TokenPattern.STRING_TYPE,
109                                    "*");
110         addPattern(pattern);
111
112         pattern = new TokenPattern(RegexpConstants.PLUS,
113                                    "PLUS",
114                                    TokenPattern.STRING_TYPE,
115                                    "+");
116         addPattern(pattern);
117
118         pattern = new TokenPattern(RegexpConstants.VERTICAL_BAR,
119                                    "VERTICAL_BAR",
120                                    TokenPattern.STRING_TYPE,
121                                    "|");
122         addPattern(pattern);
123
124         pattern = new TokenPattern(RegexpConstants.DOT,
125                                    "DOT",
126                                    TokenPattern.STRING_TYPE,
127                                    ".");
128         addPattern(pattern);
129
130         pattern = new TokenPattern(RegexpConstants.COMMA,
131                                    "COMMA",
132                                    TokenPattern.STRING_TYPE,
133                                    ",");
134         addPattern(pattern);
135
136         pattern = new TokenPattern(RegexpConstants.NUMBER,
137                                    "NUMBER",
138                                    TokenPattern.REGEXP_TYPE,
139                                    "[0-9]+");
140         addPattern(pattern);
141
142         pattern = new TokenPattern(RegexpConstants.CHAR,
143                                    "CHAR",
144                                    TokenPattern.REGEXP_TYPE,
145                                    "(\\\\.)|.");
146         addPattern(pattern);
147     }
148 }
149
Popular Tags