001/*
002 * Copyright (C) 2009-2011 Mathias Doenitz
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.parboiled.errors;
018
019import org.parboiled.buffers.InputBuffer;
020import org.parboiled.common.StringUtils;
021import org.parboiled.support.Position;
022import org.parboiled.common.StringUtils;
023import org.parboiled.support.Position;
024
025/**
026 * Exception thrown by the IndentDedentInputbuffer upon detection of an illegal indentation.
027 */
028public class IllegalIndentationException extends RuntimeException {
029    public final InputBuffer buffer;
030    public final Position position;
031
032    public IllegalIndentationException(InputBuffer buffer, Position position) {
033        this.buffer = buffer;
034        this.position = position;
035    }
036
037    @Override
038    public String getMessage() {
039        return "Illegal indentation in line " + position.line + ":\n" +
040                buffer.extractLine(position.line) + '\n' +
041                StringUtils.repeat('^', position.column - 1) + '\n';
042    }
043}