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
;
19 import java
.io
.IOException
;
20 import java
.io
.Reader
;
21 import java
.util
.Vector
;
24 * A parser that extracts INCLUDE statements from a Reader.
28 public final class FortranParser
29 extends AbstractParser
32 * List of included filenames.
34 private final Vector includes
= new Vector();
37 * State that starts consuming content at the beginning of a line.
39 private final AbstractParserState newLineState
;
42 * Default constructor.
45 public FortranParser() {
46 AbstractParserState filename
= new FilenameState(this, new char[] {'\'',
48 AbstractParserState apos
= new WhitespaceOrLetterState(this, '\'',
50 AbstractParserState blank
= new LetterState(this, ' ', apos
, null);
51 AbstractParserState e
= new CaseInsensitiveLetterState(this, 'E',
53 AbstractParserState d
= new CaseInsensitiveLetterState(this, 'D', e
,
55 AbstractParserState u
= new CaseInsensitiveLetterState(this, 'U', d
,
57 AbstractParserState l
= new CaseInsensitiveLetterState(this, 'L', u
,
59 AbstractParserState c
= new CaseInsensitiveLetterState(this, 'C', l
,
61 AbstractParserState n
= new CaseInsensitiveLetterState(this, 'N', c
,
63 newLineState
= new WhitespaceOrCaseInsensitiveLetterState(this, 'I', n
);
67 * Called by FilenameState at completion of file name production.
72 public void addFilename(final String include
) {
73 includes
.addElement(include
);
77 * Gets collection of include file names encountered in parse.
78 * @return include file names
80 public String
[] getIncludes() {
81 String
[] retval
= new String
[includes
.size()];
82 includes
.copyInto(retval
);
87 * Get the state for the beginning of a new line.
88 * @return start of line state
90 public AbstractParserState
getNewLineState() {
95 * Collects all included files from the content of the reader.
98 * character reader containing a FORTRAN source module
100 * throw if I/O error during parse
102 public void parse(final Reader reader
) throws IOException
{