/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2014 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
package com.jaamsim.input;

import com.jaamsim.input.ExpParser.Expression;
import com.sandwell.JavaSimulation.Entity;
import com.sandwell.JavaSimulation.InputErrorException;
import com.sandwell.JavaSimulation.StringVector;

public class ExpressionInput extends Input<ExpParser.Expression> {
	private Entity thisEnt;

	public ExpressionInput(String key, String cat, ExpParser.Expression def) {
		super(key, cat, def);
	}

	public void setEntity(Entity ent) {
		thisEnt = ent;
	}

	@Override
	public void parse(StringVector input)
	throws InputErrorException {

		try {
			Input.assertCount(input, 1);
			Expression exp = ExpParser.parseExpression(input.get(0));

			// Test whether the expression can be evaluated
			try {
				@SuppressWarnings("unused")
				double x = ExpEvaluator.evaluateExpression(exp, 0.0, thisEnt, null).value;
			} catch (ExpEvaluator.Error e) {
				throw new InputErrorException(e.toString());
			}

			// Save the expression
			value = exp;

		} catch (ExpParser.Error e) {
			throw new InputErrorException(e.toString());
		}
	}

}

@@ -772,57 +772,8 @@
 ion;
-%0Aimport com.sandwell.JavaSimulation.StringVector;
 %0A%0Apu
@@ -1059,26 +1059,23 @@
 rse(
-StringVector input
+KeywordIndex kw
 )%0A%09t
@@ -1105,21 +1105,11 @@
 on %7B
-%0A%0A%09%09try %7B
 %0A%09%09
-%09
 Inpu
@@ -1126,19 +1126,24 @@
 unt(
-input
+kw
 , 1);%0A
+%09%09try %7B%0A
 %09%09%09E
@@ -1188,17 +1188,17 @@
 ion(
-input
+kw
 .get
+Arg
 (0))

use KeywordIndex in ExpressionInput