/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2014 Ausenco Engineering Canada 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.jaamsim.input;

public class ExpError extends Exception {
	public final String source;
	public final int pos;

	ExpError(String source, int pos, String msg) {
		super(msg);
		this.source = source;
		this.pos = pos;
	}

	ExpError(String source, int pos, String fmt, Object... args) {
		this(source, pos, String.format(fmt, args));
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(super.getMessage()).append("\n");

		if (source == null)
			return sb.toString();

		// Otherwise, append the source expression and an 'arrow' pointing at the error
		String src = source.replaceAll("%", "%%");
		sb.append(src).append("\n");

		for (int i = 0; i < pos; ++i) {
			sb.append(" ");
		}

		sb.append("^\n");

		return sb.toString();
	}
}

@@ -1034,16 +1034,70 @@
 ing() %7B%0A
+%0A%09%09if (source == null)%0A%09%09%09return super.getMessage();%0A%0A
 %09%09String
@@ -1130,16 +1130,39 @@
 lder();%0A
+%09%09sb.append(%22%3Chtml%3E%22);%0A
 %09%09sb.app
@@ -1197,80 +1197,27 @@
 nd(%22
-%5Cn%22);%0A%0A%09%09if (source == null)%0A%09%09%09return sb.toString();%0A%0A%09%09// Otherwise, a
+%3Cbr%3E%3Cbr%3E%22);%0A%0A%09%09// A
 ppen
@@ -1334,16 +1334,52 @@
 .append(
+%22%3Cpre%3E%3Cfont color=%5C%22red%5C%22%3E%22).append(
 src).app
@@ -1383,18 +1383,20 @@
 append(%22
-%5Cn
+%3Cbr%3E
 %22);%0A%0A%09%09f
@@ -1467,11 +1467,36 @@
 nd(%22
-%5E%5Cn
+%3Cb%3E%5E%3C/b%3E%3C/font%3E%3C/pre%3E%3C/html%3E
 %22);%0A

use fixed-pitch font when pointing to an expression error