keep alpha source states during node propagation
[IRC.git] / Robust / src / Benchmarks / mlp / tagger / mlp-smaller / PropertyParser.java
diff --git a/Robust/src/Benchmarks/mlp/tagger/mlp-smaller/PropertyParser.java b/Robust/src/Benchmarks/mlp/tagger/mlp-smaller/PropertyParser.java
new file mode 100644 (file)
index 0000000..ca999d1
--- /dev/null
@@ -0,0 +1,107 @@
+/**\r
+ * PropertyParser class\r
+ * Parses property files\r
+ * <p>\r
+ * <code>int</code>.\r
+ *\r
+ * @author  Daniel Jackson\r
+ * @version 0, 07/02/01\r
+ */\r
+\r
+//package tagger;\r
+//import java.io.*;\r
+//import java.util.*;\r
+\r
+public class PropertyParser {\r
+  private FileInputStream reader;\r
+  private String token;\r
+  private int next_char;\r
+\r
+  public PropertyParser (FileInputStream r) {\r
+    reader = r;\r
+    next_char = reader.read ();\r
+    consume_comments ();\r
+  }\r
+  \r
+  private void consume_comments () {\r
+    // consume lines that don't start with <\r
+    while (next_char != '<' && !is_eos (next_char)) {\r
+      if (!is_eol (next_char))\r
+       reader.readLine ();\r
+      consume_char ();\r
+    }\r
+  }\r
+  \r
+  private void consume_char () {\r
+    token += (char) next_char;\r
+    next_char = reader.read ();\r
+    //while(next_char == 13 || next_char==10) {\r
+    //  next_char = reader.read ();\r
+    //}\r
+    //System.out.println( "next_char: "+(char)next_char );\r
+  }\r
+  \r
+  private void error (String msg) {\r
+    // correct to number from 1, not zero\r
+    //t line_number = reader.getLineNumber() + 1;\r
+    System.out.println (msg);\r
+    System.exit(-1);\r
+  }\r
+  \r
+  public boolean has_more_properties () {\r
+    return (!is_eos (next_char));\r
+  }\r
+  \r
+  /**\r
+   * requires: next_char contains next character in reader <p>\r
+   * ensures: returns list of properties until end of line or stream <p>\r
+   *   according to the following syntax:\r
+   *           property list is sequence of properties followed by eol of eos\r
+   *           property is left-angle, property-name, colon, value, right-angle\r
+   *           property-name is alphanumeric string, but value is any char sequence\r
+   *   skips lines that do not start with <\r
+   *   reports syntax errors on this.error_reporter\r
+   *   Syntax\r
+   * @return list of properties until end of line or stream.\r
+   *   Notes: chose LinkedList because it provides removeFirst, to support common\r
+   *   case in which first property is removed (eg, because it's a style name)\r
+   */\r
+  public LinkedList get_property_list () {\r
+    LinkedList result = /*disjoint llPropList*/ new LinkedList ();\r
+    while (!is_eol (next_char) && !is_eos(next_char))\r
+      result.add (get_property ());\r
+    consume_char ();\r
+    consume_comments ();\r
+    return result;\r
+  }\r
+  \r
+  private Property get_property () {    \r
+    if (next_char != '<')\r
+      error ("Found " + next_char + " when expecting <");\r
+    consume_char ();\r
+    token = "";\r
+    while (is_alphanumeric (next_char)) consume_char ();\r
+    String property = token;\r
+    if (next_char != ':')\r
+      error ("Found " + next_char + " following " + token + " when expecting :");\r
+    consume_char ();\r
+    token = "";\r
+    while (next_char != '>' && !is_eol(next_char) && !is_eos (next_char))\r
+      consume_char ();\r
+    String value = token;\r
+    if (next_char != '>')\r
+      error ("Found " + next_char + " following " + token + " when expecting >");\r
+    consume_char ();\r
+    return new Property (property, value);\r
+  }\r
+  \r
+  static boolean is_eol (int c) {return c == '\n';}\r
+  static boolean is_eos (int c) {return c == -1;}\r
+  static boolean is_alphabetic (int c) {\r
+    return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z';\r
+  }\r
+  static boolean is_numeric (int c) {return c >= '0' && c <= '9';}\r
+  static boolean is_alphanumeric (int c) {\r
+    return is_numeric (c) || is_alphabetic (c);\r
+  }\r
+}\r