Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 2e748f07 authored by ZEYEN Olivier's avatar ZEYEN Olivier
Browse files

Merge branch 'work' into 'master'

Work

See merge request ozeyen/complexityparser!5
parents e2dcd2f9 2cfae5f4
No related branches found
No related tags found
No related merge requests found
Showing with 92 additions and 7 deletions
import complexityparser.Model;
import complexityparser.operators.Operators;
import complexityparser.operators.exceptions.OperatorLoadException;
import view.MainFrame;
import java.io.IOException;
......@@ -12,6 +13,10 @@ public class Main {
} catch (IOException e) {
System.err.println("Operator config file load failed, exiting");
System.exit(1);
} catch (OperatorLoadException e) {
System.err.println("Operator config file load failed, exiting");
System.err.println(e.getMessage());
System.exit(1);
}
Model m = new Model();
......
......@@ -185,7 +185,7 @@ public class TypingListener extends JavaParserBaseListener {
Logger.println("statement::if {\n\t" + ctx.getText() + "\n\t-> " + res + "\n}");
}
else if(ctx.block() != null) {
else if(ctx.block() != null && ctx.TRY() == null) {
Tier res = tierTypes.get(ctx.block());
Logger.println("statement::block {\n\t" + ctx.getText() + "\n\t-> " + res + "\n}");
......
package complexityparser.operators;
import complexityparser.Tier;
import complexityparser.operators.exceptions.InputException;
import org.antlr.v4.runtime.ParserRuleContext;
import java.io.IOException;
import java.util.ArrayList;
......@@ -31,9 +33,16 @@ public class Input {
* @param str
* @throws IOException
*/
public Input(String str) throws IOException {
public Input(String str) throws IOException, InputException {
str = str.trim();
Matcher validater = Pattern.compile("\\[\\s*[0-9]+\\s*(,\\s*[0-9]+\\s*)*\\]\\s*>\\s*[0-9]+").matcher(str);
if(! validater.matches()) {
//throw new IOException("Invalid input/output sequence " + str);
throw new InputException(str);
}
Pattern pattern = Pattern.compile("([0-9]+)");
Matcher matcher = pattern.matcher(str);
......@@ -93,4 +102,8 @@ public class Input {
public String toString() {
return Arrays.toString(in) + " > " + out;
}
public static void main(String[] args) throws IOException, InputException {
new Input("[1, 1] > 1");
}
}
package complexityparser.operators;
import complexityparser.Tier;
import complexityparser.operators.exceptions.InputException;
import complexityparser.operators.exceptions.OperatorException;
import complexityparser.operators.exceptions.OperatorLoadException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Operator {
private ArrayList<Input> results;
......@@ -22,8 +27,17 @@ public class Operator {
* @param str
* @throws IOException
*/
public Operator(String str) throws IOException {
public Operator(String str) throws IOException, OperatorLoadException {
this();
str = str.trim();
Matcher validater = Pattern.compile("(.*;)+", Pattern.DOTALL).matcher(str);
if(!validater.matches()) {
throw new OperatorException(str);
}
String[] line = str.split(";");
for(String s : line) {
......@@ -78,4 +92,8 @@ public class Operator {
return str.toString();
}
public static void main(String[] args) throws IOException, OperatorLoadException {
new Operator("[1, 1] > 1;");
}
}
package complexityparser.operators;
import complexityparser.Tier;
import complexityparser.operators.exceptions.InputException;
import complexityparser.operators.exceptions.OperatorException;
import complexityparser.operators.exceptions.OperatorLoadException;
import complexityparser.operators.exceptions.OperatorsException;
import java.io.File;
import java.io.IOException;
......@@ -27,8 +31,17 @@ public class Operators {
* @param str
* @throws IOException
*/
private Operators(String str) throws IOException {
private Operators(String str) throws IOException, OperatorLoadException {
this();
str = str.trim();
Matcher validator = Pattern.compile("(\"[^\"]+\"\\s*\\{[^\\{}]*}\\s*)+", Pattern.DOTALL).matcher(str);
if(!validator.matches()) {
throw new OperatorsException(str);
}
String[] ops = str.split("}");
for(String op : ops) {
......@@ -57,7 +70,7 @@ public class Operators {
* initializes the singleton using the file 'operators.config' in the working directory
* @throws IOException
*/
public static void loadInstanceFromFile() throws IOException {
public static void loadInstanceFromFile() throws IOException, OperatorLoadException {
byte[] b = Files.readAllBytes(new File("operators.config").toPath());
String str = new String(b, StandardCharsets.UTF_8);
instance = new Operators(str);
......@@ -108,7 +121,7 @@ public class Operators {
return str.toString();
}
public static void main(String[] args) throws IOException {
public static void main(String[] args) throws IOException, OperatorLoadException {
Operators op = new Operators();
Operator o = new Operator();
......
package complexityparser.operators.exceptions;
/**
* any error that may me thrown by the Input class
*/
public class InputException extends OperatorLoadException {
public InputException(String message) {
super("Invalid input/output sequence:\n\t\t" + message);
}
}
package complexityparser.operators.exceptions;
/**
* any error that may be thrown by the Operator class
*/
public class OperatorException extends OperatorLoadException {
public OperatorException(String message) {
super("Invalid operator input:\n\t\t" + message);
}
}
package complexityparser.operators.exceptions;
public abstract class OperatorLoadException extends Exception {
public OperatorLoadException(String message) {
super("\nOperatorLoadException:\n\t" + message);
}
}
package complexityparser.operators.exceptions;
/**
* any error that may be thrown by Operators class
*/
public class OperatorsException extends OperatorLoadException {
public OperatorsException(String message) {
super("Invalid operators input:\n\t\t" + message);
}
}
......@@ -87,7 +87,6 @@ public class EditorView extends JPanel {
getActionMap().put("escape", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
System.out.println("transfer focus");
area.transferFocus();
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment