]> git.proxmox.com Git - mirror_edk2.git/blobdiff - 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
diff --git a/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/parser/CParser.java b/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/parser/CParser.java
new file mode 100644 (file)
index 0000000..07f8eba
--- /dev/null
@@ -0,0 +1,78 @@
+/*\r
+ * \r
+ * Copyright 2002-2004 The Ant-Contrib project\r
+ *\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+package net.sf.antcontrib.cpptasks.parser;\r
+import java.io.IOException;\r
+import java.io.Reader;\r
+import java.util.Vector;\r
+/**\r
+ * A parser that extracts #include statements from a Reader.\r
+ * \r
+ * @author Adam Murdoch\r
+ * @author Curt Arnold\r
+ */\r
+public final class CParser extends AbstractParser implements Parser {\r
+    private final Vector includes = new Vector();\r
+    private AbstractParserState newLineState;\r
+    /**\r
+     * \r
+     *  \r
+     */\r
+    public CParser() {\r
+        AbstractParserState quote = new FilenameState(this, new char[]{'"'});\r
+        AbstractParserState bracket = new FilenameState(this, new char[]{'>'});\r
+        AbstractParserState postE = new PostE(this, bracket, quote);\r
+        //\r
+        //    nclude\r
+        //\r
+        AbstractParserState e = new LetterState(this, 'e', postE, null);\r
+        AbstractParserState d = new LetterState(this, 'd', e, null);\r
+        AbstractParserState u = new LetterState(this, 'u', d, null);\r
+        AbstractParserState l = new LetterState(this, 'l', u, null);\r
+        AbstractParserState c = new LetterState(this, 'c', l, null);\r
+        AbstractParserState n = new LetterState(this, 'n', c, null);\r
+        //\r
+        //   mport is equivalent to nclude\r
+        //\r
+        AbstractParserState t = new LetterState(this, 't', postE, null);\r
+        AbstractParserState r = new LetterState(this, 'r', t, null);\r
+        AbstractParserState o = new LetterState(this, 'o', r, null);\r
+        AbstractParserState p = new LetterState(this, 'p', o, null);\r
+        AbstractParserState m = new LetterState(this, 'm', p, null);\r
+        //\r
+        //   switch between\r
+        //\r
+        AbstractParserState n_m = new BranchState(this, new char[]{'n', 'm'},\r
+                new AbstractParserState[]{n, m}, null);\r
+        AbstractParserState i = new WhitespaceOrLetterState(this, 'i', n_m);\r
+        newLineState = new LetterState(this, '#', i, null);\r
+    }\r
+    public void addFilename(String include) {\r
+        includes.addElement(include);\r
+    }\r
+    public String[] getIncludes() {\r
+        String[] retval = new String[includes.size()];\r
+        includes.copyInto(retval);\r
+        return retval;\r
+    }\r
+    public AbstractParserState getNewLineState() {\r
+        return newLineState;\r
+    }\r
+    public void parse(Reader reader) throws IOException {\r
+        includes.setSize(0);\r
+        super.parse(reader);\r
+    }\r
+}\r