]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*\r |
2 | * \r | |
3 | * Copyright 2001-2004 The Ant-Contrib project\r | |
4 | *\r | |
5 | * Licensed under the Apache License, Version 2.0 (the "License");\r | |
6 | * you may not use this file except in compliance with the License.\r | |
7 | * You may obtain a copy of the License at\r | |
8 | *\r | |
9 | * http://www.apache.org/licenses/LICENSE-2.0\r | |
10 | *\r | |
11 | * Unless required by applicable law or agreed to in writing, software\r | |
12 | * distributed under the License is distributed on an "AS IS" BASIS,\r | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r | |
14 | * See the License for the specific language governing permissions and\r | |
15 | * limitations under the License.\r | |
16 | */\r | |
17 | package net.sf.antcontrib.cpptasks.parser;\r | |
18 | import java.io.IOException;\r | |
19 | import java.io.Reader;\r | |
20 | /**\r | |
21 | * An abstract base class for simple parsers\r | |
22 | * \r | |
23 | * @author Curt Arnold\r | |
24 | */\r | |
25 | public abstract class AbstractParser {\r | |
26 | /**\r | |
27 | * \r | |
28 | * \r | |
29 | */\r | |
30 | protected AbstractParser() {\r | |
31 | }\r | |
32 | protected abstract void addFilename(String filename);\r | |
33 | public abstract AbstractParserState getNewLineState();\r | |
34 | protected void parse(Reader reader) throws IOException {\r | |
35 | char[] buf = new char[4096];\r | |
36 | AbstractParserState newLineState = getNewLineState();\r | |
37 | AbstractParserState state = newLineState;\r | |
38 | int charsRead = -1;\r | |
39 | do {\r | |
40 | charsRead = reader.read(buf, 0, buf.length);\r | |
41 | if (state == null) {\r | |
42 | for (int i = 0; i < charsRead; i++) {\r | |
43 | if (buf[i] == '\n') {\r | |
44 | state = newLineState;\r | |
45 | break;\r | |
46 | }\r | |
47 | }\r | |
48 | }\r | |
49 | if (state != null) {\r | |
50 | for (int i = 0; i < charsRead; i++) {\r | |
51 | state = state.consume(buf[i]);\r | |
52 | //\r | |
53 | // didn't match a production, skip to a new line\r | |
54 | //\r | |
55 | if (state == null) {\r | |
56 | for (; i < charsRead; i++) {\r | |
57 | if (buf[i] == '\n') {\r | |
58 | state = newLineState;\r | |
59 | break;\r | |
60 | }\r | |
61 | }\r | |
62 | }\r | |
63 | }\r | |
64 | }\r | |
65 | } while (charsRead >= 0);\r | |
66 | }\r | |
67 | }\r |