]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/parser/FortranParser.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / parser / FortranParser.java
1 /*
2 *
3 * Copyright 2002-2004 The Ant-Contrib project
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17 package net.sf.antcontrib.cpptasks.parser;
18
19 import java.io.IOException;
20 import java.io.Reader;
21 import java.util.Vector;
22
23 /**
24 * A parser that extracts INCLUDE statements from a Reader.
25 *
26 * @author Curt Arnold
27 */
28 public final class FortranParser
29 extends AbstractParser
30 implements Parser {
31 /**
32 * List of included filenames.
33 */
34 private final Vector includes = new Vector();
35
36 /**
37 * State that starts consuming content at the beginning of a line.
38 */
39 private final AbstractParserState newLineState;
40
41 /**
42 * Default constructor.
43 *
44 */
45 public FortranParser() {
46 AbstractParserState filename = new FilenameState(this, new char[] {'\'',
47 '/'});
48 AbstractParserState apos = new WhitespaceOrLetterState(this, '\'',
49 filename);
50 AbstractParserState blank = new LetterState(this, ' ', apos, null);
51 AbstractParserState e = new CaseInsensitiveLetterState(this, 'E',
52 blank, null);
53 AbstractParserState d = new CaseInsensitiveLetterState(this, 'D', e,
54 null);
55 AbstractParserState u = new CaseInsensitiveLetterState(this, 'U', d,
56 null);
57 AbstractParserState l = new CaseInsensitiveLetterState(this, 'L', u,
58 null);
59 AbstractParserState c = new CaseInsensitiveLetterState(this, 'C', l,
60 null);
61 AbstractParserState n = new CaseInsensitiveLetterState(this, 'N', c,
62 null);
63 newLineState = new WhitespaceOrCaseInsensitiveLetterState(this, 'I', n);
64 }
65
66 /**
67 * Called by FilenameState at completion of file name production.
68 *
69 * @param include
70 * include file name
71 */
72 public void addFilename(final String include) {
73 includes.addElement(include);
74 }
75
76 /**
77 * Gets collection of include file names encountered in parse.
78 * @return include file names
79 */
80 public String[] getIncludes() {
81 String[] retval = new String[includes.size()];
82 includes.copyInto(retval);
83 return retval;
84 }
85
86 /**
87 * Get the state for the beginning of a new line.
88 * @return start of line state
89 */
90 public AbstractParserState getNewLineState() {
91 return newLineState;
92 }
93
94 /**
95 * Collects all included files from the content of the reader.
96 *
97 * @param reader
98 * character reader containing a FORTRAN source module
99 * @throws IOException
100 * throw if I/O error during parse
101 */
102 public void parse(final Reader reader) throws IOException {
103 includes.setSize(0);
104 super.parse(reader);
105 }
106 }