]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/parser/CParser.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / parser / CParser.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 import java.io.IOException;
19 import java.io.Reader;
20 import java.util.Vector;
21 /**
22 * A parser that extracts #include statements from a Reader.
23 *
24 * @author Adam Murdoch
25 * @author Curt Arnold
26 */
27 public final class CParser extends AbstractParser implements Parser {
28 private final Vector includes = new Vector();
29 private AbstractParserState newLineState;
30 /**
31 *
32 *
33 */
34 public CParser() {
35 AbstractParserState quote = new FilenameState(this, new char[]{'"'});
36 AbstractParserState bracket = new FilenameState(this, new char[]{'>'});
37 AbstractParserState postE = new PostE(this, bracket, quote);
38 //
39 // nclude
40 //
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);
47 //
48 // mport is equivalent to nclude
49 //
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);
55 //
56 // switch between
57 //
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);
62 }
63 public void addFilename(String include) {
64 includes.addElement(include);
65 }
66 public String[] getIncludes() {
67 String[] retval = new String[includes.size()];
68 includes.copyInto(retval);
69 return retval;
70 }
71 public AbstractParserState getNewLineState() {
72 return newLineState;
73 }
74 public void parse(Reader reader) throws IOException {
75 includes.setSize(0);
76 super.parse(reader);
77 }
78 }