/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.commons.jexl;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

import org.apache.commons.jexl.context.HashMapContext;

/**
 * Test application for Jexl
 * TODO - needs more options to be more useful.
 * @since 2.0
 */
public class Main {
    /**
     * Test application for Jexl
     * 
     * If a single argument is present, it is treated as a filename of a JEXL
     * script to be executed.
     * Otherwise, lines are read from standard input and evaluated.
     * 
     * @param args (optional) filename to evaluate. Stored in the args variable.
     * 
     * @throws Exception if parsing or IO fail
     */
    public static void main(String[] args) throws Exception {
        JexlEngine engine = new JexlEngine();
        JexlContext context = new HashMapContext();
        context.getVars().put("args", args);
        if (args.length == 1) {
            Script script = engine.createScript(new File(args[0]));
            Object value = script.execute(context);
            System.out.println("Return value: " + value);
        } else {
            BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
            String line;
            System.out.print("> ");
            while (null != (line = console.readLine())) {
                try {
                    Expression expression = engine.createExpression(line);
                    Object value = expression.evaluate(context);
                    System.out.println("Return value: " + value);
                    System.out.print("> ");
                } catch (JexlException e) {
                    System.out.println(e.getLocalizedMessage());
                }
            }
        }
    }
}

@@ -977,89 +977,99 @@
 xt;%0A
-%0A/**%0A * Test application for Jexl%0A * TODO - needs more options to be more useful.
+import org.apache.commons.jexl.parser.ParseException;%0A%0A/**%0A * Test application for JEXL.%0A *
 %0A * 
@@ -1140,19 +1140,19 @@
 on for J
-exl
+EXL
 %0A     * 
@@ -1258,18 +1258,80 @@
 executed
+ as a script. Any exceptions terminate the application
 .%0A
+     * %0A
      * O
@@ -1390,16 +1390,171 @@
 luated.%0A
+     * ParseExceptions and JexlExceptions are logged, and do not cause the application to exit.%0A     * This is done so that interactive testing is easier.%0A
      * %0A
@@ -1596,21 +1596,20 @@
 ame to e
-valua
+xecu
 te. Stor
@@ -2586,33 +2586,99 @@
     
-    System.out.print(%22%3E %22
+%7D catch (ParseException e) %7B%0A                    System.out.println(e.getLocalizedMessage()
 );%0A 
@@ -2777,32 +2777,32 @@
 izedMessage());%0A
-
                 
@@ -2795,32 +2795,72 @@
               %7D%0A
+                System.out.print(%22%3E %22);%0A
             %7D%0A  

Document expected behaviour when Exceptions occur. Don't exit interactive session on ParseException.