diff --git a/example1ONLYoutput.txt b/example1ONLYoutput.txt index 21a0c97..59f0588 100644 --- a/example1ONLYoutput.txt +++ b/example1ONLYoutput.txt @@ -16,7 +16,7 @@ none s T3 Emma 1 false true 103-118 none e 103 118 3 true true none s T3 Emma 1 false true -Error, could not delete rolling stock +Error, invalid delete rolling stock argument OK 1 2 diff --git a/fuzz10_output.txt b/fuzz10_output.txt index d6e37b0..e4793c0 100644 --- a/fuzz10_output.txt +++ b/fuzz10_output.txt @@ -9,7 +9,7 @@ 9 T3-Emma 103-118 -Error, could not delete rolling stock +Error, invalid delete rolling stock argument OK 1 passenger coach W1 added to train 1 diff --git a/src/edu/kit/informatik/ui/command/CommandFactory.java b/src/edu/kit/informatik/ui/command/CommandFactory.java index eeaf48f..d77193a 100644 --- a/src/edu/kit/informatik/ui/command/CommandFactory.java +++ b/src/edu/kit/informatik/ui/command/CommandFactory.java @@ -15,41 +15,47 @@ import java.util.regex.Pattern; * @version 1.0 */ public final class CommandFactory { + private static final String NUMBER = "[+-]?\\d+"; + private static final String VECTOR = NUMBER + "," + NUMBER; + private static final String ALPHANUMERIC_WORD = "[\\p{L}\\p{N}]+"; + private static final String ROLLING_STOCK_IDENTIFIER + = "(" + ALPHANUMERIC_WORD + "-" + ALPHANUMERIC_WORD + ")|W" + NUMBER; + private static final String ADD_TRACK = "add track"; private static final Pattern ADD_TRACK_ARGUMENTS - = Pattern.compile(" \\(([+-]?\\d+,[+-]?\\d+)\\) -> \\(([+-]?\\d+,[+-]?\\d+)\\)"); + = Pattern.compile(" \\((" + VECTOR + ")\\) -> \\((" + VECTOR + ")\\)"); private static final String ADD_SWITCH = "add switch"; private static final Pattern ADD_SWITCH_ARGUMENTS - = Pattern.compile(" \\(([+-]?\\d+,[+-]?\\d+)\\) -> \\(([+-]?\\d+,[+-]?\\d+)\\),\\(([+-]?\\d+,[+-]?\\d+)\\)"); + = Pattern.compile(" \\((" + VECTOR + ")\\) -> \\((" + VECTOR + ")\\),\\((" + VECTOR + ")\\)"); private static final String DELETE_TRACK = "delete track"; private static final String LIST_TRACKS = "list tracks"; private static final String SET_SWITCH = "set switch"; private static final Pattern SET_SWITCH_ARGUMENTS - = Pattern.compile(" \\+?(\\d+) position \\(([+-]?\\d+,[+-]?\\d+)\\)"); + = Pattern.compile(" (" + NUMBER + ") position \\((" + VECTOR + ")\\)"); private static final String CREATE_ENGINE = "create engine"; private static final Pattern CREATE_ENGINE_ARGUMENTS - = Pattern.compile(" (electrical|diesel|steam) ([\\p{L}\\p{N}]+) ([\\p{L}\\p{N}]+) \\+?(\\d+) (true|false) (true|false)"); + = Pattern.compile(" (electrical|diesel|steam) (" + ALPHANUMERIC_WORD + ") (" + ALPHANUMERIC_WORD + ") (" + NUMBER + ") (true|false) (true|false)"); private static final String LIST_ENGINES = "list engines"; private static final String CREATE_COACH = "create coach"; private static final Pattern CREATE_COACH_ARGUMENTS - = Pattern.compile(" (passenger|freight|special) \\+?(\\d+) (true|false) (true|false)"); + = Pattern.compile(" (passenger|freight|special) (" + NUMBER + ") (true|false) (true|false)"); private static final String LIST_COACHES = "list coaches"; private static final String CREATE_TRAIN_SET = "create train-set"; private static final Pattern CREATE_TRAIN_SET_ARGUMENTS - = Pattern.compile(" ([\\p{L}\\p{N}]+) ([\\p{L}\\p{N}]+) \\+?(\\d+) (true|false) (true|false)"); + = Pattern.compile(" (" + ALPHANUMERIC_WORD + ") (" + ALPHANUMERIC_WORD + ") (" + NUMBER + ") (true|false) (true|false)"); private static final String LIST_TRAIN_SETS = "list train-sets"; private static final String DELETE_ROLLING_STOCK = "delete rolling stock"; private static final Pattern DELETE_ROLLING_STOCK_ARGUMENT - = Pattern.compile(" ([\\p{L}\\p{N}]++(-[\\p{L}\\p{N}]+)?)"); + = Pattern.compile(" (" + ROLLING_STOCK_IDENTIFIER + ")"); private static final String ADD_TRAIN = "add train"; private static final Pattern ADD_TRAIN_ARGUMENTS - = Pattern.compile(" \\+?(\\d+) (([\\p{L}\\p{N}]+-[\\p{L}\\p{N}]+)|(W\\+?\\d+))"); + = Pattern.compile(" (" + NUMBER + ") (" + ROLLING_STOCK_IDENTIFIER + ")"); private static final String DELETE_TRAIN = "delete train"; private static final String LIST_TRAINS = "list trains"; private static final String SHOW_TRAIN = "show train"; private static final String PUT_TRAIN = "put train"; private static final Pattern PUT_TRAIN_ARGUMENTS - = Pattern.compile(" \\+?(\\d+) at \\(([+-]?\\d+,[+-]?\\d+)\\) in direction ([+-]?\\d+,[+-]?\\d+)"); + = Pattern.compile(" (" + NUMBER + ") at \\((" + VECTOR + ")\\) in direction (" + VECTOR + ")"); private static final String STEP = "step"; private static final String POSITIVE_NUMBER = " \\+?\\d+";