/**
 * Copyright 2007 Google Inc.
 *
 * 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 com.tonicsystems.jarjar;

import java.io.*;
import java.util.*;

class RulesFileParser
{
    private RulesFileParser() {
    }

    public static List<PatternElement> parse(File file) throws IOException {
        return parse(new FileReader(file));
    }

    public static List<PatternElement> parse(String value) throws IOException {
        return parse(new java.io.StringReader(value));
    }

    private static List<PatternElement> parse(Reader r) throws IOException {
      try {
        List<PatternElement> patterns = new ArrayList<PatternElement>();
        BufferedReader br = new BufferedReader(r);
        int c = 1;
        String line;
        while ((line = br.readLine()) != null) {
            String[] parts = line.split("\\s+");
            if (parts.length < 2)
                error(c, parts);
            String type = parts[0];
            PatternElement element = null;
            if (type.equals("rule")) {
                if (parts.length < 3)
                    error(c, parts);
                Rule rule = new Rule();
                rule.setResult(parts[2]);
                element = rule;
            } else if (type.equals("zap")) {
                element = new Zap();
            } else if (type.equals("keep")) {
                element = new Keep();
            } else {
                error(c, parts);
            }
            element.setPattern(parts[1]);
            patterns.add(element);
            c++;
        }
        return patterns;
      } finally {
        r.close();
      }
    }

    private static void error(int line, String[] parts) {
      throw new IllegalArgumentException("Error on line " + line + ": " + Arrays.asList(parts));
    }
}

@@ -984,32 +984,168 @@
 value));%0A    %7D%0A%0A
+    private static String stripComment(String in) %7B%0A      int p = in.indexOf(%22#%22);%0A      return p %3C 0 ? in : in.substring(0, p);%0A    %7D%0A%0A
     private stat
@@ -1426,24 +1426,121 @@
  != null) %7B%0A
+            line = stripComment(line);%0A            if (line.isEmpty())%0A                continue;%0A
             

Fix for http://code.google.com/p/jarjar/issues/detail?id=53. Jarjar rules file syntax should support comments