<commit_before>package wycs;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;

import wycs.lang.*;
import wycs.solver.Verifier;
import wycs.io.*;
import wyone.util.SyntaxError;

public class WycsMain {
	public static PrintStream errout;
	
	/**
	 * Initialise the error output stream so as to ensure it will display
	 * unicode characters (when possible). Additionally, extract version
	 * information from the enclosing jar file.
	 */
	static {
		try {
			errout = new PrintStream(System.err, true, "UTF-8");
		} catch(Exception e) {
			errout = System.err;
			System.err.println("Warning: terminal does not support unicode");
		}
	}
	
	public static boolean run(String[] args) throws IOException {
		boolean verbose = false;
		File file = new File(args[0]);			
		Lexer lexer = new Lexer(file);
		Parser parser = new Parser(file.getName(),lexer.scan());
		WycsFile wycs = parser.parse();
		new WycsFileWriter(new PrintStream(System.out, true, "UTF-8")).write(wycs);
		
		List<Boolean> results = new Verifier(verbose).verify(wycs);
		for(int i = 0;i!=results.size();++i) {
			if(!results.get(i)) {
				return false;
			} 
		}		
		return true;
	}
	
	public static void main(String[] args) {
		boolean verbose = true;
		try {
			try {				
				File file = new File(args[0]);			
				Lexer lexer = new Lexer(file);
				Parser parser = new Parser(file.getName(),lexer.scan());
				WycsFile wycs = parser.parse();
				new WycsFileWriter(new PrintStream(System.out, true, "UTF-8")).write(wycs);
				List<Boolean> results = new Verifier(verbose).verify(wycs);
				for(int i = 0;i!=results.size();++i) {
					if(results.get(i)) {
						System.out.println("Valid");
					} else {
						System.out.println("Invalid");
					}
				}
			} catch (SyntaxError e) {
				outputSourceError(e.filename(), e.start(), e.end(),
						e.getMessage());

				if (verbose) {
					e.printStackTrace(System.err);
				}
			}
		} catch (Throwable e) {
			errout.println("internal failure (" + e.getMessage() + ")");
			if (verbose) {
				e.printStackTrace(errout);
			}		
		}	
	}
	
	/**
	 * This method simply reads in the input file, and prints out a
	 * given line of text, with little markers (i.e. '^') placed
	 * underneath a portion of it.  
	 *
	 * @param fileArg - the name of the file whose line to print
	 * @param start - the start position of the offending region.
	 * @param end - the end position of the offending region.
	 * @param message - the message to print about the error
	 */
	public static void outputSourceError(String fileArg, int start, int end,
			String message) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader(fileArg));
						
		int line = 0;
		String lineText = "";
		while (in.ready() && start >= lineText.length()) {
			start -= lineText.length() + 1;
			end -= lineText.length() + 1;
			lineText = in.readLine();						
			line = line + 1;			
		}		<commit_msg>WYCS: minor bug fix for reporting error messages.<commit_after>package wycs;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;

import wycs.lang.*;
import wycs.solver.Verifier;
import wycs.io.*;
import wybs.lang.SyntaxError;

public class WycsMain {
	public static PrintStream errout;
	
	/**
	 * Initialise the error output stream so as to ensure it will display
	 * unicode characters (when possible). Additionally, extract version
	 * information from the enclosing jar file.
	 */
	static {
		try {
			errout = new PrintStream(System.err, true, "UTF-8");
		} catch(Exception e) {
			errout = System.err;
			System.err.println("Warning: terminal does not support unicode");
		}
	}
	
	public static boolean run(String[] args) throws IOException {
		boolean verbose = false;
		File file = new File(args[0]);			
		Lexer lexer = new Lexer(file);
		Parser parser = new Parser(file.getName(),lexer.scan());
		WycsFile wycs = parser.parse();
		new WycsFileWriter(new PrintStream(System.out, true, "UTF-8")).write(wycs);
		
		List<Boolean> results = new Verifier(verbose).verify(wycs);
		for(int i = 0;i!=results.size();++i) {
			if(!results.get(i)) {
				return false;
			} 
		}		
		return true;
	}
	
	public static void main(String[] args) {
		boolean verbose = true;
		try {
			try {				
				File file = new File(args[0]);			
				Lexer lexer = new Lexer(file);
				Parser parser = new Parser(file.getName(),lexer.scan());
				WycsFile wycs = parser.parse();
				new WycsFileWriter(new PrintStream(System.out, true, "UTF-8")).write(wycs);
				List<Boolean> results = new Verifier(verbose).verify(wycs);
				for(int i = 0;i!=results.size();++i) {
					if(results.get(i)) {
						System.out.println("Valid");
					} else {
						System.out.println("Invalid");
					}
				}
			} catch (SyntaxError e) {
				outputSourceError(e.filename(), e.start(), e.end(),
						e.getMessage());

				if (verbose) {
					e.printStackTrace(System.err);
				}
			}
		} catch (Throwable e) {			
			errout.println("internal failure (" + e.getMessage() + ")");
			if (verbose) {
				e.printStackTrace(errout);
			}		
		}	
	}
	
	/**
	 * This method simply reads in the input file, and prints out a
	 * given line of text, with little markers (i.e. '^') placed
	 * underneath a portion of it.  
	 *
	 * @param fileArg - the name of the file whose line to print
	 * @param start - the start position of the offending region.
	 * @param end - the end position of the offending region.
	 * @param message - the message to print about the error
	 */
	public static void outputSourceError(String fileArg, int start, int end,
			String message) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader(fileArg));
						
		int line = 0;
		String lineText = "";
		while (in.ready() && start >= lineText.length()) {
			start -= lineText.length() + 1;
			end -= lineText.length() + 1;
			lineText = in.readLine();						
			line = line + 1;			
		}		
{'fraction_non_alphanumeric': 0.1341503809208347, 'fraction_numerical': 0.00364359059291156, 'mean_word_length': 3.2171787709497206, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2473651', 'n_tokens_mistral': 2282, 'n_tokens_neox': 1902, 'n_words': 557}