<commit_before>package de.peeeq.wurstscript;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.io.Files;

import de.peeeq.wurstscript.ast.Ast;
import de.peeeq.wurstscript.attributes.CompileError;
import de.peeeq.wurstscript.utils.LineOffsets;

/** 
 * a helper class to run pjass 
 *
 */
public class Pjass {

	public static class Result {

		private boolean ok;
		private String message;
		private File jassFile;

		public Result(File jassFile, boolean ok, String message) {
			this.jassFile = jassFile;
			this.ok = ok;
			this.message = message;
		}

		public boolean isOk() {
			return ok;
		}

		public String getMessage() {
			return message;
		}
		
		public List<CompileError> getErrors() {
			if (isOk()) {
				return Collections.emptyList();
			}
			LineOffsets lineOffsets = new LineOffsets();
			try {
				String cont = Files.toString(jassFile, Charsets.UTF_8);
				int line = 0;
				lineOffsets.set(1, 0);
				for (int i = 0; i<cont.length(); i++) {
					if (cont.charAt(i) == '\n') {
						line++;
						lineOffsets.set(line+1, i);
					}
				}
				lineOffsets.set(line+1, cont.length()-1);
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			List<CompileError> result = Lists.newArrayList();
			for (String error : getMessage().split("(\n|\r)+")) {
				Pattern pat = Pattern.compile(".*:([0-9]+):(.*)");
				Matcher match = pat.matcher(error);
				if (!match.matches()) {
					System.out.println("no match: " + error);
					continue;
				}
				int line = Integer.parseInt(match.group(1));
				String msg = match.group(2);
				result.add(new CompileError(Ast.WPos(jassFile.getAbsolutePath(), lineOffsets, lineOffsets.get(line), lineOffsets.get(line+1)), msg));
			}<commit_msg>made it clear in error message that a pjass error is a bug in the wurst compiler<commit_after>package de.peeeq.wurstscript;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.io.Files;

import de.peeeq.wurstscript.ast.Ast;
import de.peeeq.wurstscript.attributes.CompileError;
import de.peeeq.wurstscript.utils.LineOffsets;

/** 
 * a helper class to run pjass 
 *
 */
public class Pjass {

	public static class Result {

		private boolean ok;
		private String message;
		private File jassFile;

		public Result(File jassFile, boolean ok, String message) {
			this.jassFile = jassFile;
			this.ok = ok;
			this.message = message;
		}

		public boolean isOk() {
			return ok;
		}

		public String getMessage() {
			return message;
		}
		
		public List<CompileError> getErrors() {
			if (isOk()) {
				return Collections.emptyList();
			}
			LineOffsets lineOffsets = new LineOffsets();
			try {
				String cont = Files.toString(jassFile, Charsets.UTF_8);
				int line = 0;
				lineOffsets.set(1, 0);
				for (int i = 0; i<cont.length(); i++) {
					if (cont.charAt(i) == '\n') {
						line++;
						lineOffsets.set(line+1, i);
					}
				}
				lineOffsets.set(line+1, cont.length()-1);
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			List<CompileError> result = Lists.newArrayList();
			for (String error : getMessage().split("(\n|\r)+")) {
				Pattern pat = Pattern.compile(".*:([0-9]+):(.*)");
				Matcher match = pat.matcher(error);
				if (!match.matches()) {
					System.out.println("no match: " + error);
					continue;
				}
				int line = Integer.parseInt(match.group(1));
				String msg = match.group(2);
				result.add(new CompileError(
						Ast.WPos(jassFile.getAbsolutePath(), lineOffsets,
								lineOffsets.get(line),
								lineOffsets.get(line + 1)),
						"This is a bug in the Wurst Compiler. Please Report it. Pjass has found the following problem: "
								+ msg));
			}
{'fraction_non_alphanumeric': 0.14036762950584866, 'fraction_numerical': 0.0062067319169252805, 'mean_word_length': 3.3419689119170983, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '7317511', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1408, 'n_words': 325}