/*
 * Copyright (C) 2009-2011 Mathias Doenitz
 *
 * 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 org.parboiled.examples.abc;

import org.parboiled.Parboiled;
import org.parboiled.common.StringUtils;
import org.parboiled.parserunners.RecoveringParseRunner;
import static org.parboiled.support.ParseTreeUtils.printNodeTree;
import org.parboiled.support.ParsingResult;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        AbcParser parser = Parboiled.createParser(AbcParser.class);

        while (true) {
            System.out.print("Enter an a^n b^n c^n expression (single RETURN to exit)!\n");
            String input = new Scanner(System.in).nextLine();
            if (StringUtils.isEmpty(input)) break;

            ParsingResult<?> result = new RecoveringParseRunner(parser.S()).run(input);

            System.out.println(input + " = " + result.parseTreeRoot.getValue() + '\n');
            System.out.println(printNodeTree(result) + '\n');

            if (!result.matched) {
                System.out.println(StringUtils.join(result.parseErrors, "---\n"));
            }
        }
    }

}
@@ -708,16 +708,56 @@
 gUtils;%0A
+import org.parboiled.errors.ErrorUtils;%0A
 import o
@@ -870,16 +870,73 @@
 odeTree;
+%0A%0Aimport org.parboiled.parserunners.ReportingParseRunner;
 %0Aimport 
@@ -1408,21 +1408,20 @@
 = new Re
-cover
+port
 ingParse
@@ -1468,147 +1468,134 @@
     
-System.out.println(input + %22 = %22 + result.parseTreeRoot.getValue() + '%5Cn');%0A            System.out.println(printNodeTree(result) + '%5Cn'
+if (!result.parseErrors.isEmpty())%0A                System.out.println(ErrorUtils.printParseError(result.parseErrors.get(0))
 );%0A
-%0A
     
@@ -1606,30 +1606,12 @@
     
-if (!result.matched) %7B
+else
 %0A   
@@ -1646,69 +1646,38 @@
 tln(
-StringUtils.join(result.parseErrors, %22---%5Cn%22));%0A            %7D
+printNodeTree(result) + '%5Cn');
 %0A   

Improve ABC example