]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*\r |
2 | * \r | |
3 | * Copyright 2002-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 | import java.util.Vector;\r | |
21 | /**\r | |
22 | * A parser that extracts #include statements from a Reader.\r | |
23 | * \r | |
24 | * @author Adam Murdoch\r | |
25 | * @author Curt Arnold\r | |
26 | */\r | |
27 | public final class CParser extends AbstractParser implements Parser {\r | |
28 | private final Vector includes = new Vector();\r | |
29 | private AbstractParserState newLineState;\r | |
30 | /**\r | |
31 | * \r | |
32 | * \r | |
33 | */\r | |
34 | public CParser() {\r | |
35 | AbstractParserState quote = new FilenameState(this, new char[]{'"'});\r | |
36 | AbstractParserState bracket = new FilenameState(this, new char[]{'>'});\r | |
37 | AbstractParserState postE = new PostE(this, bracket, quote);\r | |
38 | //\r | |
39 | // nclude\r | |
40 | //\r | |
41 | AbstractParserState e = new LetterState(this, 'e', postE, null);\r | |
42 | AbstractParserState d = new LetterState(this, 'd', e, null);\r | |
43 | AbstractParserState u = new LetterState(this, 'u', d, null);\r | |
44 | AbstractParserState l = new LetterState(this, 'l', u, null);\r | |
45 | AbstractParserState c = new LetterState(this, 'c', l, null);\r | |
46 | AbstractParserState n = new LetterState(this, 'n', c, null);\r | |
47 | //\r | |
48 | // mport is equivalent to nclude\r | |
49 | //\r | |
50 | AbstractParserState t = new LetterState(this, 't', postE, null);\r | |
51 | AbstractParserState r = new LetterState(this, 'r', t, null);\r | |
52 | AbstractParserState o = new LetterState(this, 'o', r, null);\r | |
53 | AbstractParserState p = new LetterState(this, 'p', o, null);\r | |
54 | AbstractParserState m = new LetterState(this, 'm', p, null);\r | |
55 | //\r | |
56 | // switch between\r | |
57 | //\r | |
58 | AbstractParserState n_m = new BranchState(this, new char[]{'n', 'm'},\r | |
59 | new AbstractParserState[]{n, m}, null);\r | |
60 | AbstractParserState i = new WhitespaceOrLetterState(this, 'i', n_m);\r | |
61 | newLineState = new LetterState(this, '#', i, null);\r | |
62 | }\r | |
63 | public void addFilename(String include) {\r | |
64 | includes.addElement(include);\r | |
65 | }\r | |
66 | public String[] getIncludes() {\r | |
67 | String[] retval = new String[includes.size()];\r | |
68 | includes.copyInto(retval);\r | |
69 | return retval;\r | |
70 | }\r | |
71 | public AbstractParserState getNewLineState() {\r | |
72 | return newLineState;\r | |
73 | }\r | |
74 | public void parse(Reader reader) throws IOException {\r | |
75 | includes.setSize(0);\r | |
76 | super.parse(reader);\r | |
77 | }\r | |
78 | }\r |