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