summaryrefslogtreecommitdiff
path: root/src/net/sf/antcontrib/cpptasks/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/sf/antcontrib/cpptasks/parser')
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/AbstractParser.java67
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/AbstractParserState.java41
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/BranchState.java46
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/CParser.java78
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/CVS/Entries14
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/CVS/Repository1
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/CVS/Root1
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/CaseInsensitiveLetterState.java87
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/FilenameState.java41
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/FortranParser.java106
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/LetterState.java80
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/Parser.java28
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/PostE.java41
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/WhitespaceOrCaseInsensitiveLetterState.java83
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/WhitespaceOrLetterState.java75
-rw-r--r--src/net/sf/antcontrib/cpptasks/parser/package.html28
16 files changed, 817 insertions, 0 deletions
diff --git a/src/net/sf/antcontrib/cpptasks/parser/AbstractParser.java b/src/net/sf/antcontrib/cpptasks/parser/AbstractParser.java
new file mode 100644
index 0000000..b9bca25
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/AbstractParser.java
@@ -0,0 +1,67 @@
+/*
+ *
+ * Copyright 2001-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.parser;
+import java.io.IOException;
+import java.io.Reader;
+/**
+ * An abstract base class for simple parsers
+ *
+ * @author Curt Arnold
+ */
+public abstract class AbstractParser {
+ /**
+ *
+ *
+ */
+ protected AbstractParser() {
+ }
+ protected abstract void addFilename(String filename);
+ public abstract AbstractParserState getNewLineState();
+ protected void parse(Reader reader) throws IOException {
+ char[] buf = new char[4096];
+ AbstractParserState newLineState = getNewLineState();
+ AbstractParserState state = newLineState;
+ int charsRead = -1;
+ do {
+ charsRead = reader.read(buf, 0, buf.length);
+ if (state == null) {
+ for (int i = 0; i < charsRead; i++) {
+ if (buf[i] == '\n') {
+ state = newLineState;
+ break;
+ }
+ }
+ }
+ if (state != null) {
+ for (int i = 0; i < charsRead; i++) {
+ state = state.consume(buf[i]);
+ //
+ // didn't match a production, skip to a new line
+ //
+ if (state == null) {
+ for (; i < charsRead; i++) {
+ if (buf[i] == '\n') {
+ state = newLineState;
+ break;
+ }
+ }
+ }
+ }
+ }
+ } while (charsRead >= 0);
+ }
+}
diff --git a/src/net/sf/antcontrib/cpptasks/parser/AbstractParserState.java b/src/net/sf/antcontrib/cpptasks/parser/AbstractParserState.java
new file mode 100644
index 0000000..b3e3307
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/AbstractParserState.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.parser;
+/**
+ * An base class for objects that represent the state of an AbstractParser.
+ *
+ * @author CurtArnold
+ * @see AbstractParser
+ */
+public abstract class AbstractParserState {
+ private AbstractParser parser;
+ protected AbstractParserState(AbstractParser parser) {
+ if (parser == null) {
+ throw new NullPointerException("parser");
+ }
+ this.parser = parser;
+ }
+ /**
+ * Consume a character
+ *
+ * @return new state, may be null to ignore the rest of the line
+ */
+ public abstract AbstractParserState consume(char ch);
+ protected AbstractParser getParser() {
+ return parser;
+ }
+}
diff --git a/src/net/sf/antcontrib/cpptasks/parser/BranchState.java b/src/net/sf/antcontrib/cpptasks/parser/BranchState.java
new file mode 100644
index 0000000..4b869e0
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/BranchState.java
@@ -0,0 +1,46 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.parser;
+public class BranchState extends AbstractParserState {
+ private char[] branchChars;
+ private AbstractParserState[] branchStates;
+ private AbstractParserState noMatchState;
+ public BranchState(AbstractParser parser, char[] branchChars,
+ AbstractParserState[] branchStates, AbstractParserState noMatchState) {
+ super(parser);
+ this.branchChars = (char[]) branchChars.clone();
+ this.branchStates = (AbstractParserState[]) branchStates.clone();
+ this.noMatchState = noMatchState;
+ }
+ public AbstractParserState consume(char ch) {
+ AbstractParserState state;
+ for (int i = 0; i < branchChars.length; i++) {
+ if (ch == branchChars[i]) {
+ state = branchStates[i];
+ return state.consume(ch);
+ }
+ }
+ state = getNoMatchState();
+ if (state != null) {
+ return state.consume(ch);
+ }
+ return state;
+ }
+ protected AbstractParserState getNoMatchState() {
+ return noMatchState;
+ }
+}
diff --git a/src/net/sf/antcontrib/cpptasks/parser/CParser.java b/src/net/sf/antcontrib/cpptasks/parser/CParser.java
new file mode 100644
index 0000000..d10d889
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/CParser.java
@@ -0,0 +1,78 @@
+/*
+ *
+ * Copyright 2002-2005 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.parser;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Vector;
+/**
+ * A parser that extracts #include statements from a Reader.
+ *
+ * @author Adam Murdoch
+ * @author Curt Arnold
+ */
+public final class CParser extends AbstractParser implements Parser {
+ private final Vector includes = new Vector();
+ private AbstractParserState newLineState;
+ /**
+ *
+ *
+ */
+ public CParser() {
+ AbstractParserState quote = new FilenameState(this, new char[]{'"'});
+ AbstractParserState bracket = new FilenameState(this, new char[]{'>'});
+ AbstractParserState postE = new PostE(this, bracket, quote);
+ //
+ // nclude
+ //
+ AbstractParserState e = new LetterState(this, 'e', postE, null);
+ AbstractParserState d = new LetterState(this, 'd', e, null);
+ AbstractParserState u = new LetterState(this, 'u', d, null);
+ AbstractParserState l = new LetterState(this, 'l', u, null);
+ AbstractParserState c = new LetterState(this, 'c', l, null);
+ AbstractParserState n = new LetterState(this, 'n', c, null);
+ //
+ // mport is equivalent to nclude
+ //
+ AbstractParserState t = new LetterState(this, 't', postE, null);
+ AbstractParserState r = new LetterState(this, 'r', t, null);
+ AbstractParserState o = new LetterState(this, 'o', r, null);
+ AbstractParserState p = new LetterState(this, 'p', o, null);
+ AbstractParserState m = new LetterState(this, 'm', p, null);
+ //
+ // switch between
+ //
+ AbstractParserState n_m = new BranchState(this, new char[]{'n', 'm'},
+ new AbstractParserState[]{n, m}, null);
+ AbstractParserState i = new WhitespaceOrLetterState(this, 'i', n_m);
+ newLineState = new WhitespaceOrLetterState(this, '#', i);
+ }
+ public void addFilename(String include) {
+ includes.addElement(include);
+ }
+ public String[] getIncludes() {
+ String[] retval = new String[includes.size()];
+ includes.copyInto(retval);
+ return retval;
+ }
+ public AbstractParserState getNewLineState() {
+ return newLineState;
+ }
+ public void parse(Reader reader) throws IOException {
+ includes.setSize(0);
+ super.parse(reader);
+ }
+}
diff --git a/src/net/sf/antcontrib/cpptasks/parser/CVS/Entries b/src/net/sf/antcontrib/cpptasks/parser/CVS/Entries
new file mode 100644
index 0000000..67699c9
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/CVS/Entries
@@ -0,0 +1,14 @@
+/AbstractParser.java/1.7/Sat Feb 28 19:02:48 2004//
+/AbstractParserState.java/1.6/Sat Feb 28 19:02:48 2004//
+/BranchState.java/1.7/Sat Feb 28 19:02:48 2004//
+/CParser.java/1.9/Mon Aug 15 13:58:27 2005//
+/CaseInsensitiveLetterState.java/1.1/Mon Mar 1 05:11:01 2004//
+/FilenameState.java/1.6/Sat Feb 28 19:02:48 2004//
+/FortranParser.java/1.7/Mon Mar 1 05:11:01 2004//
+/LetterState.java/1.7/Mon Mar 1 05:11:01 2004//
+/Parser.java/1.6/Sat Feb 28 19:02:48 2004//
+/PostE.java/1.6/Sat Feb 28 19:02:48 2004//
+/WhitespaceOrCaseInsensitiveLetterState.java/1.1/Mon Mar 1 05:11:01 2004//
+/WhitespaceOrLetterState.java/1.7/Mon Mar 1 05:11:01 2004//
+/package.html/1.1/Fri Apr 16 04:04:11 2004//
+D
diff --git a/src/net/sf/antcontrib/cpptasks/parser/CVS/Repository b/src/net/sf/antcontrib/cpptasks/parser/CVS/Repository
new file mode 100644
index 0000000..102547a
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/CVS/Repository
@@ -0,0 +1 @@
+cpptasks/src/net/sf/antcontrib/cpptasks/parser
diff --git a/src/net/sf/antcontrib/cpptasks/parser/CVS/Root b/src/net/sf/antcontrib/cpptasks/parser/CVS/Root
new file mode 100644
index 0000000..1ac95cd
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/CVS/Root
@@ -0,0 +1 @@
+:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ant-contrib
diff --git a/src/net/sf/antcontrib/cpptasks/parser/CaseInsensitiveLetterState.java b/src/net/sf/antcontrib/cpptasks/parser/CaseInsensitiveLetterState.java
new file mode 100644
index 0000000..edcfe83
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/CaseInsensitiveLetterState.java
@@ -0,0 +1,87 @@
+/*
+ *
+ * Copyright 2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.parser;
+
+/**
+ * This parser state checks consumed characters against a specific character
+ * (case insensitive).
+ *
+ * @author Curt Arnold
+ */
+public final class CaseInsensitiveLetterState
+ extends AbstractParserState {
+ /**
+ * Next state if a match is found.
+ */
+ private final AbstractParserState nextState;
+
+ /**
+ * Next state if not match is found.
+ */
+ private final AbstractParserState noMatchState;
+
+ /**
+ * Lower case version of character to match.
+ */
+ private final char lowerLetter;
+
+ /**
+ * Lower case version of character to match.
+ */
+ private final char upperLetter;
+
+ /**
+ * Constructor.
+ *
+ * @param parser
+ * parser
+ * @param matchLetter
+ * letter to match
+ * @param nextStateArg
+ * next state if a match on the letter
+ * @param noMatchStateArg
+ * state if no match on letter
+ */
+ public CaseInsensitiveLetterState(final AbstractParser parser,
+ final char matchLetter,
+ final AbstractParserState nextStateArg,
+ final AbstractParserState noMatchStateArg) {
+ super(parser);
+ this.lowerLetter = Character.toLowerCase(matchLetter);
+ this.upperLetter = Character.toUpperCase(matchLetter);
+ this.nextState = nextStateArg;
+ this.noMatchState = noMatchStateArg;
+ }
+
+ /**
+ * Consumes a character and returns the next state for the parser.
+ *
+ * @param ch
+ * next character
+ * @return the configured nextState if ch is the expected character or the
+ * configure noMatchState otherwise.
+ */
+ public AbstractParserState consume(final char ch) {
+ if (ch == lowerLetter || ch == upperLetter) {
+ return nextState;
+ }
+ if (ch == '\n') {
+ getParser().getNewLineState();
+ }
+ return noMatchState;
+ }
+}
diff --git a/src/net/sf/antcontrib/cpptasks/parser/FilenameState.java b/src/net/sf/antcontrib/cpptasks/parser/FilenameState.java
new file mode 100644
index 0000000..f3a6193
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/FilenameState.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.parser;
+public class FilenameState extends AbstractParserState {
+ private final StringBuffer buf = new StringBuffer();
+ private final char[] terminators;
+ public FilenameState(AbstractParser parser, char[] terminators) {
+ super(parser);
+ this.terminators = (char[]) terminators.clone();
+ }
+ public AbstractParserState consume(char ch) {
+ for (int i = 0; i < terminators.length; i++) {
+ if (ch == terminators[i]) {
+ getParser().addFilename(buf.toString());
+ buf.setLength(0);
+ return null;
+ }
+ }
+ if (ch == '\n') {
+ buf.setLength(0);
+ return getParser().getNewLineState();
+ } else {
+ buf.append(ch);
+ }
+ return this;
+ }
+}
diff --git a/src/net/sf/antcontrib/cpptasks/parser/FortranParser.java b/src/net/sf/antcontrib/cpptasks/parser/FortranParser.java
new file mode 100644
index 0000000..d393e65
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/FortranParser.java
@@ -0,0 +1,106 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.parser;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Vector;
+
+/**
+ * A parser that extracts INCLUDE statements from a Reader.
+ *
+ * @author Curt Arnold
+ */
+public final class FortranParser
+ extends AbstractParser
+ implements Parser {
+ /**
+ * List of included filenames.
+ */
+ private final Vector includes = new Vector();
+
+ /**
+ * State that starts consuming content at the beginning of a line.
+ */
+ private final AbstractParserState newLineState;
+
+ /**
+ * Default constructor.
+ *
+ */
+ public FortranParser() {
+ AbstractParserState filename = new FilenameState(this, new char[] {'\'',
+ '/'});
+ AbstractParserState apos = new WhitespaceOrLetterState(this, '\'',
+ filename);
+ AbstractParserState blank = new LetterState(this, ' ', apos, null);
+ AbstractParserState e = new CaseInsensitiveLetterState(this, 'E',
+ blank, null);
+ AbstractParserState d = new CaseInsensitiveLetterState(this, 'D', e,
+ null);
+ AbstractParserState u = new CaseInsensitiveLetterState(this, 'U', d,
+ null);
+ AbstractParserState l = new CaseInsensitiveLetterState(this, 'L', u,
+ null);
+ AbstractParserState c = new CaseInsensitiveLetterState(this, 'C', l,
+ null);
+ AbstractParserState n = new CaseInsensitiveLetterState(this, 'N', c,
+ null);
+ newLineState = new WhitespaceOrCaseInsensitiveLetterState(this, 'I', n);
+ }
+
+ /**
+ * Called by FilenameState at completion of file name production.
+ *
+ * @param include
+ * include file name
+ */
+ public void addFilename(final String include) {
+ includes.addElement(include);
+ }
+
+ /**
+ * Gets collection of include file names encountered in parse.
+ * @return include file names
+ */
+ public String[] getIncludes() {
+ String[] retval = new String[includes.size()];
+ includes.copyInto(retval);
+ return retval;
+ }
+
+ /**
+ * Get the state for the beginning of a new line.
+ * @return start of line state
+ */
+ public AbstractParserState getNewLineState() {
+ return newLineState;
+ }
+
+ /**
+ * Collects all included files from the content of the reader.
+ *
+ * @param reader
+ * character reader containing a FORTRAN source module
+ * @throws IOException
+ * throw if I/O error during parse
+ */
+ public void parse(final Reader reader) throws IOException {
+ includes.setSize(0);
+ super.parse(reader);
+ }
+}
diff --git a/src/net/sf/antcontrib/cpptasks/parser/LetterState.java b/src/net/sf/antcontrib/cpptasks/parser/LetterState.java
new file mode 100644
index 0000000..fc62f9b
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/LetterState.java
@@ -0,0 +1,80 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.parser;
+
+/**
+ * This parser state checks consumed characters against a specific character.
+ *
+ * @author Curt Arnold
+ */
+public final class LetterState
+ extends AbstractParserState {
+ /**
+ * Next state if a match is found.
+ */
+ private final AbstractParserState nextState;
+
+ /**
+ * Next state if not match is found.
+ */
+ private final AbstractParserState noMatchState;
+
+ /**
+ * Character to match.
+ */
+ private final char thisLetter;
+
+ /**
+ * Constructor.
+ *
+ * @param parser
+ * parser
+ * @param matchLetter
+ * letter to match
+ * @param nextStateArg
+ * next state if a match on the letter
+ * @param noMatchStateArg
+ * state if no match on letter
+ */
+ public LetterState(final AbstractParser parser,
+ final char matchLetter,
+ final AbstractParserState nextStateArg,
+ final AbstractParserState noMatchStateArg) {
+ super(parser);
+ this.thisLetter = matchLetter;
+ this.nextState = nextStateArg;
+ this.noMatchState = noMatchStateArg;
+ }
+
+ /**
+ * Consumes a character and returns the next state for the parser.
+ *
+ * @param ch
+ * next character
+ * @return the configured nextState if ch is the expected character or the
+ * configure noMatchState otherwise.
+ */
+ public AbstractParserState consume(final char ch) {
+ if (ch == thisLetter) {
+ return nextState;
+ }
+ if (ch == '\n') {
+ getParser().getNewLineState();
+ }
+ return noMatchState;
+ }
+}
diff --git a/src/net/sf/antcontrib/cpptasks/parser/Parser.java b/src/net/sf/antcontrib/cpptasks/parser/Parser.java
new file mode 100644
index 0000000..bf63ae7
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/Parser.java
@@ -0,0 +1,28 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.parser;
+import java.io.IOException;
+import java.io.Reader;
+/**
+ * A parser that extracts #include statements from a Reader.
+ *
+ * @author Curt Arnold
+ */
+public interface Parser {
+ String[] getIncludes();
+ void parse(Reader reader) throws IOException;
+}
diff --git a/src/net/sf/antcontrib/cpptasks/parser/PostE.java b/src/net/sf/antcontrib/cpptasks/parser/PostE.java
new file mode 100644
index 0000000..d599f19
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/PostE.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.parser;
+public class PostE extends AbstractParserState {
+ private AbstractParserState bracket;
+ private AbstractParserState quote;
+ public PostE(CParser parser, AbstractParserState bracket,
+ AbstractParserState quote) {
+ super(parser);
+ this.bracket = bracket;
+ this.quote = quote;
+ }
+ public AbstractParserState consume(char ch) {
+ switch (ch) {
+ case ' ' :
+ case '\t' :
+ return this;
+ case '<' :
+ return bracket;
+ case '"' :
+ return quote;
+ case '\n' :
+ return getParser().getNewLineState();
+ }
+ return null;
+ }
+}
diff --git a/src/net/sf/antcontrib/cpptasks/parser/WhitespaceOrCaseInsensitiveLetterState.java b/src/net/sf/antcontrib/cpptasks/parser/WhitespaceOrCaseInsensitiveLetterState.java
new file mode 100644
index 0000000..f7cbcea
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/WhitespaceOrCaseInsensitiveLetterState.java
@@ -0,0 +1,83 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.parser;
+
+/**
+ * This parser state checks consumed characters against a specific character
+ * (case insensitive) or whitespace.
+ *
+ * @author Curt Arnold
+ */
+public final class WhitespaceOrCaseInsensitiveLetterState
+ extends
+ AbstractParserState {
+ /**
+ * Next state if the character is found.
+ */
+ private final AbstractParserState nextState;
+
+ /**
+ * Character to match (lower case).
+ */
+ private final char lowerLetter;
+
+ /**
+ * Character to match (upper case).
+ */
+ private final char upperLetter;
+
+ /**
+ * Constructor.
+ *
+ * @param parser
+ * parser
+ * @param matchLetter
+ * letter to match
+ * @param nextStateArg
+ * next state if a match on the letter
+ */
+ public WhitespaceOrCaseInsensitiveLetterState(final AbstractParser parser,
+ final char matchLetter,
+ final AbstractParserState
+ nextStateArg) {
+ super(parser);
+ this.lowerLetter = Character.toLowerCase(matchLetter);
+ this.upperLetter = Character.toUpperCase(matchLetter);
+ this.nextState = nextStateArg;
+ }
+
+ /**
+ * Consumes a character and returns the next state for the parser.
+ *
+ * @param ch
+ * next character
+ * @return the configured nextState if ch is the expected character or the
+ * configure noMatchState otherwise.
+ */
+ public AbstractParserState consume(final char ch) {
+ if (ch == lowerLetter || ch == upperLetter) {
+ return nextState;
+ }
+ if (ch == ' ' || ch == '\t') {
+ return this;
+ }
+ if (ch == '\n') {
+ getParser().getNewLineState();
+ }
+ return null;
+ }
+}
diff --git a/src/net/sf/antcontrib/cpptasks/parser/WhitespaceOrLetterState.java b/src/net/sf/antcontrib/cpptasks/parser/WhitespaceOrLetterState.java
new file mode 100644
index 0000000..61c133d
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/WhitespaceOrLetterState.java
@@ -0,0 +1,75 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.parser;
+
+/**
+ * This parser state checks consumed characters against a specific character or
+ * whitespace.
+ *
+ * @author Curt Arnold
+ */
+public final class WhitespaceOrLetterState
+ extends AbstractParserState {
+ /**
+ * Next state if the character is found.
+ */
+ private final AbstractParserState nextState;
+
+ /**
+ * Character to match.
+ */
+ private final char thisLetter;
+
+ /**
+ * Constructor.
+ *
+ * @param parser
+ * parser
+ * @param matchLetter
+ * letter to match
+ * @param nextStateArg
+ * next state if a match on the letter
+ */
+ public WhitespaceOrLetterState(final AbstractParser parser,
+ final char matchLetter,
+ final AbstractParserState nextStateArg) {
+ super(parser);
+ this.thisLetter = matchLetter;
+ this.nextState = nextStateArg;
+ }
+
+ /**
+ * Consumes a character and returns the next state for the parser.
+ *
+ * @param ch
+ * next character @returns the configured nextState if ch is the
+ * expected character or the configure noMatchState otherwise.
+ * @return next state
+ */
+ public AbstractParserState consume(final char ch) {
+ if (ch == thisLetter) {
+ return nextState;
+ }
+ if (ch == ' ' || ch == '\t') {
+ return this;
+ }
+ if (ch == '\n') {
+ getParser().getNewLineState();
+ }
+ return null;
+ }
+}
diff --git a/src/net/sf/antcontrib/cpptasks/parser/package.html b/src/net/sf/antcontrib/cpptasks/parser/package.html
new file mode 100644
index 0000000..1d7aa49
--- /dev/null
+++ b/src/net/sf/antcontrib/cpptasks/parser/package.html
@@ -0,0 +1,28 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<!--
+
+Copyright 2004 The Ant-Contrib project
+
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ use this file except in compliance with the License. You may obtain a copy of
+ the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations under
+ the License.
+
+-->
+</head>
+<body bgcolor="white">
+
+Provides minimal scanners to extract dependencies,
+such as include statements, from source files.
+
+</body>
+</html>