// Path: java_sentence_completion/src/utils/RuntimeIOException.java
// public class RuntimeIOException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -1399650097256466789L;
// 
// 	public RuntimeIOException() {
// 		super();
// 	}
// 
// 	public RuntimeIOException(String message) {
// 		super(message);
// 	}
// 
// 	public RuntimeIOException(Throwable cause) {
// 		super(cause);
// 	}
// 
// 	public RuntimeIOException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// }
// 
// Path: java_sentence_completion/src/utils/ArrayTools.java
// public static boolean in(boolean elem, boolean... list) {
// 	if (list == null) {
// 		return false;
// 	}
// 	for (boolean e : list) {
// 		if (elem == e) {
// 			return true;
// 		}
// 	}
// 	return false;
// }


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import utils.RuntimeIOException;
import static utils.ArrayTools.in;

/**
 * Copyright 2011-2012 Bernard Paulus and Cédric Snauwaert
 * 
 * Confabulation_Symbolic 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.
 * 
 * Confabulation_Symbolic 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 Confabulation_Symbolic.  If not, see <http://www.gnu.org/licenses/>.
 */

package parser;



/**
 * A parametric parser.
 * <p>
 * The essential parameter is the {@link Tokenizer} which controls the parsing
 * process.
 * </p>
 * 
 * @author bernard and Cédric
 * 
 */
public class GenericSymbolParser {

	protected FileInputStream fis;
	// private BufferedInputStream bis;
	// private DataInputStream stream;
	protected BufferedReader stream;

	String file;
	protected Tokenizer tok;
	/**
	 * whether the parser is at the beginning of the file
	 */
	protected boolean head_of_file;

	/**
	 * Open the file for reading. Parses the line word by word
	 * 
	 * @param file
	 *            non-null, a readable file
	 */
	public GenericSymbolParser(String file) throws IOException {
		this(file, new WordTokenizer());
	}

	/**
	 * Open the file for reading
	 * 
	 * @param file
	 *            non-null, a readable file
	 * @param tok
	 *            non-null the tokenizer
	 * @throws IOException
	 */
	public GenericSymbolParser(String file, Tokenizer tok) throws IOException {

// Path: java_sentence_completion/src/utils/RuntimeIOException.java
// public class RuntimeIOException extends RuntimeException {
// 
// 	private static final long serialVersionUID = -1399650097256466789L;
// 
// 	public RuntimeIOException() {
// 		super();
// 	}
// 
// 	public RuntimeIOException(String message) {
// 		super(message);
// 	}
// 
// 	public RuntimeIOException(Throwable cause) {
// 		super(cause);
// 	}
// 
// 	public RuntimeIOException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// }
// 
// Path: java_sentence_completion/src/utils/ArrayTools.java
// public static boolean in(boolean elem, boolean... list) {
// 	if (list == null) {
// 		return false;
// 	}
// 	for (boolean e : list) {
// 		if (elem == e) {
// 			return true;
// 		}
// 	}
// 	return false;
// }


// Path: java_sentence_completion/src/parser/GenericSymbolParser.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import utils.RuntimeIOException;
import static utils.ArrayTools.in;

/**
 * Copyright 2011-2012 Bernard Paulus and Cédric Snauwaert
 * 
 * Confabulation_Symbolic 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.
 * 
 * Confabulation_Symbolic 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 Confabulation_Symbolic.  If not, see <http://www.gnu.org/licenses/>.
 */

package parser;



/**
 * A parametric parser.
 * <p>
 * The essential parameter is the {@link Tokenizer} which controls the parsing
 * process.
 * </p>
 * 
 * @author bernard and Cédric
 * 
 */
public class GenericSymbolParser {

	protected FileInputStream fis;
	// private BufferedInputStream bis;
	// private DataInputStream stream;
	protected BufferedReader stream;

	String file;
	protected Tokenizer tok;
	/**
	 * whether the parser is at the beginning of the file
	 */
	protected boolean head_of_file;

	/**
	 * Open the file for reading. Parses the line word by word
	 * 
	 * @param file
	 *            non-null, a readable file
	 */
	public GenericSymbolParser(String file) throws IOException {
		this(file, new WordTokenizer());
	}

	/**
	 * Open the file for reading
	 * 
	 * @param file
	 *            non-null, a readable file
	 * @param tok
	 *            non-null the tokenizer
	 * @throws IOException
	 */
	public GenericSymbolParser(String file, Tokenizer tok) throws IOException {

		if (in(null, file, tok)) {
