3 * Copyright 2002-2004 The Ant-Contrib project
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package net
.sf
.antcontrib
.cpptasks
.parser
;
18 import java
.io
.IOException
;
19 import java
.io
.Reader
;
20 import java
.util
.Vector
;
22 * A parser that extracts #include statements from a Reader.
24 * @author Adam Murdoch
27 public final class CParser
extends AbstractParser
implements Parser
{
28 private final Vector includes
= new Vector();
29 private AbstractParserState newLineState
;
35 AbstractParserState quote
= new FilenameState(this, new char[]{'"'});
36 AbstractParserState bracket
= new FilenameState(this, new char[]{'>'});
37 AbstractParserState postE
= new PostE(this, bracket
, quote
);
41 AbstractParserState e
= new LetterState(this, 'e', postE
, null);
42 AbstractParserState d
= new LetterState(this, 'd', e
, null);
43 AbstractParserState u
= new LetterState(this, 'u', d
, null);
44 AbstractParserState l
= new LetterState(this, 'l', u
, null);
45 AbstractParserState c
= new LetterState(this, 'c', l
, null);
46 AbstractParserState n
= new LetterState(this, 'n', c
, null);
48 // mport is equivalent to nclude
50 AbstractParserState t
= new LetterState(this, 't', postE
, null);
51 AbstractParserState r
= new LetterState(this, 'r', t
, null);
52 AbstractParserState o
= new LetterState(this, 'o', r
, null);
53 AbstractParserState p
= new LetterState(this, 'p', o
, null);
54 AbstractParserState m
= new LetterState(this, 'm', p
, null);
58 AbstractParserState n_m
= new BranchState(this, new char[]{'n', 'm'},
59 new AbstractParserState
[]{n
, m
}, null);
60 AbstractParserState i
= new WhitespaceOrLetterState(this, 'i', n_m
);
61 newLineState
= new LetterState(this, '#', i
, null);
63 public void addFilename(String include
) {
64 includes
.addElement(include
);
66 public String
[] getIncludes() {
67 String
[] retval
= new String
[includes
.size()];
68 includes
.copyInto(retval
);
71 public AbstractParserState
getNewLineState() {
74 public void parse(Reader reader
) throws IOException
{