// Path: src/main/java/jhilbert/scanners/Scanner.java
// public interface Scanner<E> {
// 
// 	/**
// 	 * Resets the context of this scanner.
// 	 * Clears the context. That is, a call to {@link #getContextString}
// 	 * immediately following a call to this method will return an empty
// 	 * string.
// 	 */
// 	public void resetContext();
// 
// 	/**
// 	 * Returns the current context of this scanner.
// 	 *
// 	 * @return a String representation of the current context.
// 	 */
// 	public String getContextString();
// 
// 	/**
// 	 * Obtains the next token.
// 	 *
// 	 * @return the token, or <code>null</code> if there are no more tokens.
// 	 * 
// 	 * @throws ScannerException if this scanner is unable to produce a
// 	 * 	token due to either an input problem or because of a syntax
// 	 * 	error in the input source.
// 	 *
// 	 * @see #putToken
// 	 */
// 	public E getToken() throws ScannerException;
// 
// 	/**
// 	 * Put a token back.
// 	 * This method provides a means of &quot;unwinding&quot; the Scanner.
// 	 * The tokens put back are returned by {@link #getToken()} on a first
// 	 * in, last out basis.
// 	 * <p>
// 	 * The token to be put back must have been obtained by the thus far
// 	 * last call to to {@link #getToken}, or, if more than token is put back
// 	 * between calls to {@link #getToken}, the tokens must be provided in
// 	 * proper reverse order with no omissions. Otherwise the scanner may
// 	 * end up in an undefined state.
// 	 *
// 	 * @param token token to be put back.
// 	 *
// 	 * @see #getToken
// 	 */
// 	public void putToken(E token);
// 
// }
// 
// Path: src/main/java/jhilbert/scanners/ScannerException.java
// public class ScannerException extends JHilbertException {
// 
// 	/**
// 	 * Scanner which created the exception.
// 	 */
// 	private final Scanner scanner;
// 
// 	/**
// 	 * Creates a new <code>ScannerException</code> with the specified
// 	 * detail message. This constructor should only be used by a
// 	 * {@link Scanner}, which the constructor is provided with.
// 	 *
// 	 * @param message detail message.
// 	 * @param scanner the scanner which created the exception.
// 	 */
// 	public ScannerException(final String message, final Scanner scanner) {
// 		this(message, scanner, null);
// 	}
// 
// 	/**
// 	 * Creates a new <code>ScannerException</code> with the specified
// 	 * detail message and cause.
// 	 * This constructor should only be used by a {@link Scanner}, which
// 	 * the constructor is provided with.
// 	 *
// 	 * @param message detail message.
// 	 * @param scanner the scanner which created the exception.
// 	 * @param cause the cause. (A <code>null</code> value is permitted, and
// 	 * 	indicates that the cause is nonexistent or unknown.)
// 	 */
// 	public ScannerException(final String message, final Scanner scanner, final Throwable cause) {
// 		super(message, cause);
// 		this.scanner = scanner;
// 	}
// 
// 	/**
// 	 * Obtains the scanner which caused this exception.
// 	 *
// 	 * @return scanner which caused this exception.
// 	 */
// 	public final Scanner getScanner() {
// 		return scanner;
// 	}
// 
// }


import java.util.Stack;
import jhilbert.scanners.Scanner;
import jhilbert.scanners.ScannerException;
/*
    JHilbert, a verifier for collaborative theorem proving

    Copyright © 2008, 2009, 2011 The JHilbert Authors
      See the AUTHORS file for the list of JHilbert authors.
      See the commit logs ("git log") for a list of individual contributions.

    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.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    You may contact the author on this Wiki page:
    http://www.wikiproofs.de/w/index.php?title=User_talk:GrafZahl
*/

package jhilbert.scanners.impl;



/**
 * Basic implementation of the scanner interface.
 * This class implements methods to handle the putting back of tokens
 * as well as context manipulation.
 *
 * @param E token type.
 */
abstract class AbstractScanner<E> implements Scanner<E> {

	/**
	 * Stack for putting back tokens.
	 */
	private final Stack<E> tokenStack;

	/**
	 * Current scanner context.
	 */
	private final StringBuilder context;

	/**
	 * Creates a new <code>AbstractScanner</code> with empty
	 * context.
	 */
	protected AbstractScanner() {
		tokenStack = new Stack();
		context = new StringBuilder();
	}

	public void resetContext() {
		context.setLength(0);
	}

	/**
	 * Appends the specified character to the current context.
	 *
	 * @param c character to append.
	 */
	protected void appendToContext(final char c) {
		context.append(c);
	}

	/**
	 * Appends the specified character sequence to the current context.
	 *
	 * @param s character sequence to append.
	 */
	protected void appendToContext(final CharSequence s) {
		context.append(s);
	}

	public String getContextString() {
		return context.toString();
	}

	/**
	 * Obtains a new token.
	 * This method is called by this class's implementation of the
	 * {@link #getToken} method whenever all tokens which have been put
	 * back are exhausted.
	 * <p>
	 * This method must be implemented by subclasses.
	 *
	 * @return the new token, or <code>null</code> if there are no more
	 * 	tokens.
	 *
	 * @throws ScannerException for the same reasons as {@link #getToken}
	 * 	does.
	 *
	 * @see #getToken
	 */
// Path: src/main/java/jhilbert/scanners/Scanner.java
// public interface Scanner<E> {
// 
// 	/**
// 	 * Resets the context of this scanner.
// 	 * Clears the context. That is, a call to {@link #getContextString}
// 	 * immediately following a call to this method will return an empty
// 	 * string.
// 	 */
// 	public void resetContext();
// 
// 	/**
// 	 * Returns the current context of this scanner.
// 	 *
// 	 * @return a String representation of the current context.
// 	 */
// 	public String getContextString();
// 
// 	/**
// 	 * Obtains the next token.
// 	 *
// 	 * @return the token, or <code>null</code> if there are no more tokens.
// 	 * 
// 	 * @throws ScannerException if this scanner is unable to produce a
// 	 * 	token due to either an input problem or because of a syntax
// 	 * 	error in the input source.
// 	 *
// 	 * @see #putToken
// 	 */
// 	public E getToken() throws ScannerException;
// 
// 	/**
// 	 * Put a token back.
// 	 * This method provides a means of &quot;unwinding&quot; the Scanner.
// 	 * The tokens put back are returned by {@link #getToken()} on a first
// 	 * in, last out basis.
// 	 * <p>
// 	 * The token to be put back must have been obtained by the thus far
// 	 * last call to to {@link #getToken}, or, if more than token is put back
// 	 * between calls to {@link #getToken}, the tokens must be provided in
// 	 * proper reverse order with no omissions. Otherwise the scanner may
// 	 * end up in an undefined state.
// 	 *
// 	 * @param token token to be put back.
// 	 *
// 	 * @see #getToken
// 	 */
// 	public void putToken(E token);
// 
// }
// 
// Path: src/main/java/jhilbert/scanners/ScannerException.java
// public class ScannerException extends JHilbertException {
// 
// 	/**
// 	 * Scanner which created the exception.
// 	 */
// 	private final Scanner scanner;
// 
// 	/**
// 	 * Creates a new <code>ScannerException</code> with the specified
// 	 * detail message. This constructor should only be used by a
// 	 * {@link Scanner}, which the constructor is provided with.
// 	 *
// 	 * @param message detail message.
// 	 * @param scanner the scanner which created the exception.
// 	 */
// 	public ScannerException(final String message, final Scanner scanner) {
// 		this(message, scanner, null);
// 	}
// 
// 	/**
// 	 * Creates a new <code>ScannerException</code> with the specified
// 	 * detail message and cause.
// 	 * This constructor should only be used by a {@link Scanner}, which
// 	 * the constructor is provided with.
// 	 *
// 	 * @param message detail message.
// 	 * @param scanner the scanner which created the exception.
// 	 * @param cause the cause. (A <code>null</code> value is permitted, and
// 	 * 	indicates that the cause is nonexistent or unknown.)
// 	 */
// 	public ScannerException(final String message, final Scanner scanner, final Throwable cause) {
// 		super(message, cause);
// 		this.scanner = scanner;
// 	}
// 
// 	/**
// 	 * Obtains the scanner which caused this exception.
// 	 *
// 	 * @return scanner which caused this exception.
// 	 */
// 	public final Scanner getScanner() {
// 		return scanner;
// 	}
// 
// }


// Path: src/main/java/jhilbert/scanners/impl/AbstractScanner.java
import java.util.Stack;
import jhilbert.scanners.Scanner;
import jhilbert.scanners.ScannerException;

/*
    JHilbert, a verifier for collaborative theorem proving

    Copyright © 2008, 2009, 2011 The JHilbert Authors
      See the AUTHORS file for the list of JHilbert authors.
      See the commit logs ("git log") for a list of individual contributions.

    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.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    You may contact the author on this Wiki page:
    http://www.wikiproofs.de/w/index.php?title=User_talk:GrafZahl
*/

package jhilbert.scanners.impl;



/**
 * Basic implementation of the scanner interface.
 * This class implements methods to handle the putting back of tokens
 * as well as context manipulation.
 *
 * @param E token type.
 */
abstract class AbstractScanner<E> implements Scanner<E> {

	/**
	 * Stack for putting back tokens.
	 */
	private final Stack<E> tokenStack;

	/**
	 * Current scanner context.
	 */
	private final StringBuilder context;

	/**
	 * Creates a new <code>AbstractScanner</code> with empty
	 * context.
	 */
	protected AbstractScanner() {
		tokenStack = new Stack();
		context = new StringBuilder();
	}

	public void resetContext() {
		context.setLength(0);
	}

	/**
	 * Appends the specified character to the current context.
	 *
	 * @param c character to append.
	 */
	protected void appendToContext(final char c) {
		context.append(c);
	}

	/**
	 * Appends the specified character sequence to the current context.
	 *
	 * @param s character sequence to append.
	 */
	protected void appendToContext(final CharSequence s) {
		context.append(s);
	}

	public String getContextString() {
		return context.toString();
	}

	/**
	 * Obtains a new token.
	 * This method is called by this class's implementation of the
	 * {@link #getToken} method whenever all tokens which have been put
	 * back are exhausted.
	 * <p>
	 * This method must be implemented by subclasses.
	 *
	 * @return the new token, or <code>null</code> if there are no more
	 * 	tokens.
	 *
	 * @throws ScannerException for the same reasons as {@link #getToken}
	 * 	does.
	 *
	 * @see #getToken
	 */
	protected abstract E getNewToken() throws ScannerException;