]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/parser/LetterState.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / parser / LetterState.java
diff --git a/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/parser/LetterState.java b/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/parser/LetterState.java
new file mode 100644 (file)
index 0000000..945ae91
--- /dev/null
@@ -0,0 +1,80 @@
+/*\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
+\r
+/**\r
+ * This parser state checks consumed characters against a specific character.\r
+ *\r
+ * @author Curt Arnold\r
+ */\r
+public final class LetterState\r
+    extends AbstractParserState {\r
+  /**\r
+   * Next state if a match is found.\r
+   */\r
+  private final AbstractParserState nextState;\r
+\r
+  /**\r
+   * Next state if not match is found.\r
+   */\r
+  private final AbstractParserState noMatchState;\r
+\r
+  /**\r
+   * Character to match.\r
+   */\r
+  private final char thisLetter;\r
+\r
+  /**\r
+   * Constructor.\r
+   *\r
+   * @param parser\r
+   *            parser\r
+   * @param matchLetter\r
+   *            letter to match\r
+   * @param nextStateArg\r
+   *            next state if a match on the letter\r
+   * @param noMatchStateArg\r
+   *            state if no match on letter\r
+   */\r
+  public LetterState(final AbstractParser parser,\r
+                     final char matchLetter,\r
+                     final AbstractParserState nextStateArg,\r
+                     final AbstractParserState noMatchStateArg) {\r
+    super(parser);\r
+    this.thisLetter = matchLetter;\r
+    this.nextState = nextStateArg;\r
+    this.noMatchState = noMatchStateArg;\r
+  }\r
+\r
+  /**\r
+   * Consumes a character and returns the next state for the parser.\r
+   *\r
+   * @param ch\r
+   *            next character\r
+   * @return the configured nextState if ch is the expected character or the\r
+   *         configure noMatchState otherwise.\r
+   */\r
+  public AbstractParserState consume(final char ch) {\r
+    if (ch == thisLetter) {\r
+      return nextState;\r
+    }\r
+    if (ch == '\n') {\r
+      getParser().getNewLineState();\r
+    }\r
+    return noMatchState;\r
+  }\r
+}\r