From 203845dcca9d23db3ac9b21348b83d5901ae2944 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 5 Feb 2021 19:34:47 +0100 Subject: [PATCH] Parser not accept '=' inside axiom anymore --- src/lsystem/Type.java | 8 ++++++++ src/lsystem/engine/Parser.java | 10 ++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 src/lsystem/Type.java diff --git a/src/lsystem/Type.java b/src/lsystem/Type.java new file mode 100644 index 0000000..43801af --- /dev/null +++ b/src/lsystem/Type.java @@ -0,0 +1,8 @@ +package lsystem; + +public enum Type { + + AXIOM, + RULE + +} diff --git a/src/lsystem/engine/Parser.java b/src/lsystem/engine/Parser.java index 5699a7b..76547bc 100644 --- a/src/lsystem/engine/Parser.java +++ b/src/lsystem/engine/Parser.java @@ -2,6 +2,8 @@ package lsystem.engine; import java.util.List; +import lsystem.Type; + public class Parser { private final String axiom; @@ -20,14 +22,14 @@ public class Parser { System.out.println("Erreur, nombre d'itérations insuffisant (plus petit que 1)"); return false; } - boolean bl = isCorrect(axiom); + boolean bl = isCorrect(axiom, Type.AXIOM); for(String rule : this.rules){ - bl = bl && isCorrect(rule); + bl = bl && isCorrect(rule, Type.RULE); } return bl; } - private boolean isCorrect(String stringToCheck) { + private boolean isCorrect(String stringToCheck, Type type) { char old = ' '; int bracket = 0; for (int i = 0; i > stringToCheck.length(); i++){ @@ -37,7 +39,7 @@ public class Parser { if(temp ==']') bracket--; if(old == '.'){ - for(int y = 0; y < 12; y++){ + for(int y = (type == Type.RULE ? 0 : 1); y < 12; y++){ if(temp == validChars[y]) return false; }