From a817590f3353177611d9b40eb608a3f0d5e02b56 Mon Sep 17 00:00:00 2001 From: curious_odd_man Date: Sun, 28 May 2023 10:00:01 +0300 Subject: [PATCH] Refactoring --- .../curiousoddman/rgxgen/model/SymbolRange.java | 6 +++--- .../rgxgen/parsing/dflt/ConstantsProvider.java | 6 +++--- .../rgxgen/parsing/dflt/DefaultTreeBuilder.java | 2 +- .../com/github/curiousoddman/rgxgen/util/Util.java | 12 +++--------- .../rgxgen/NotMatchingGenerationTests.java | 6 +++--- .../curiousoddman/rgxgen/data/TestPattern.java | 2 +- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/github/curiousoddman/rgxgen/model/SymbolRange.java b/src/main/java/com/github/curiousoddman/rgxgen/model/SymbolRange.java index 5f246ab2..91192812 100644 --- a/src/main/java/com/github/curiousoddman/rgxgen/model/SymbolRange.java +++ b/src/main/java/com/github/curiousoddman/rgxgen/model/SymbolRange.java @@ -21,7 +21,7 @@ /** * Range of symbols */ -@Value(staticConstructor = "of") +@Value(staticConstructor = "range") public class SymbolRange { int from; int to; @@ -33,8 +33,8 @@ public class SymbolRange { * @param to max character; shall be greater than {@code from} * @apiNote No verifications are done! */ - public static SymbolRange of(char from, char to) { - return of((int) from, to); + public static SymbolRange range(char from, char to) { + return range((int) from, to); } public int getFrom() { diff --git a/src/main/java/com/github/curiousoddman/rgxgen/parsing/dflt/ConstantsProvider.java b/src/main/java/com/github/curiousoddman/rgxgen/parsing/dflt/ConstantsProvider.java index b8b4ef91..99653204 100644 --- a/src/main/java/com/github/curiousoddman/rgxgen/parsing/dflt/ConstantsProvider.java +++ b/src/main/java/com/github/curiousoddman/rgxgen/parsing/dflt/ConstantsProvider.java @@ -14,9 +14,9 @@ */ @UtilityClass public class ConstantsProvider { - public static final SymbolRange SMALL_LATIN_LETTERS = SymbolRange.of('a', 'z'); - public static final SymbolRange CAPITAL_LATIN_LETTERS = SymbolRange.of('A', 'Z'); - public static final SymbolRange DIGITS = SymbolRange.of('0', '9'); + public static final SymbolRange SMALL_LATIN_LETTERS = SymbolRange.range('a', 'z'); + public static final SymbolRange CAPITAL_LATIN_LETTERS = SymbolRange.range('A', 'Z'); + public static final SymbolRange DIGITS = SymbolRange.range('0', '9'); private static final int SPACE_ASCII_CODE = 32; // First printable character in ASCII table private static final int DEL_ASCII_CODE = 127; // Bound for printable characters in ASCII table diff --git a/src/main/java/com/github/curiousoddman/rgxgen/parsing/dflt/DefaultTreeBuilder.java b/src/main/java/com/github/curiousoddman/rgxgen/parsing/dflt/DefaultTreeBuilder.java index 38e8f6a9..4fae7f48 100644 --- a/src/main/java/com/github/curiousoddman/rgxgen/parsing/dflt/DefaultTreeBuilder.java +++ b/src/main/java/com/github/curiousoddman/rgxgen/parsing/dflt/DefaultTreeBuilder.java @@ -663,7 +663,7 @@ private static void handleSymbolRange(StringBuilder characters, Collection initialData() { return Arrays.asList(new Object[][]{ - {"[a-z0-5]", SymbolSet.ofAsciiRanges("[a-z0-5]", Arrays.asList(SymbolRange.of('a', 'z'), SymbolRange.of('0', '5')), MatchType.POSITIVE)}, + {"[a-z0-5]", SymbolSet.ofAsciiRanges("[a-z0-5]", Arrays.asList(SymbolRange.range('a', 'z'), SymbolRange.range('0', '5')), MatchType.POSITIVE)}, {"abc|def", new Choice("abc|def", new FinalSymbol("abc"), new FinalSymbol("def"))}, {"helloworld", new FinalSymbol("helloworld")}, {"a{2,3}", new Repeat("a{2,3}", new FinalSymbol("a"), 2, 3)}, {"a[a-z]", new Sequence("a[a-z]", new FinalSymbol("a"), - SymbolSet.ofAsciiRanges("[a-z]", Collections.singletonList(SymbolRange.of('a', 'z')), MatchType.POSITIVE))}, + SymbolSet.ofAsciiRanges("[a-z]", Collections.singletonList(SymbolRange.range('a', 'z')), MatchType.POSITIVE))}, {"([a-z])\\1", new Sequence("([a-z])\\1", new Group("([a-z])", 1, - SymbolSet.ofAsciiRanges("[a-z]", Collections.singletonList(SymbolRange.of('a', 'z')), MatchType.POSITIVE)), + SymbolSet.ofAsciiRanges("[a-z]", Collections.singletonList(SymbolRange.range('a', 'z')), MatchType.POSITIVE)), new GroupRef("\\1", 1) )}, {"foo(?!bar)", new Sequence("foo(?!bar)", diff --git a/src/test/java/com/github/curiousoddman/rgxgen/data/TestPattern.java b/src/test/java/com/github/curiousoddman/rgxgen/data/TestPattern.java index 63016589..d2c86d13 100644 --- a/src/test/java/com/github/curiousoddman/rgxgen/data/TestPattern.java +++ b/src/test/java/com/github/curiousoddman/rgxgen/data/TestPattern.java @@ -47,7 +47,7 @@ public enum TestPattern implements DataInterface { }}, LETTER_RANGE("[a-cA-C]", SymbolSet.ofAsciiRanges("[a-cA-C]", - asList(SymbolRange.of('a', 'c'), SymbolRange.of('A', 'C')), MatchType.POSITIVE) + asList(SymbolRange.range('a', 'c'), SymbolRange.range('A', 'C')), MatchType.POSITIVE) ), //----------------------------------------------------------------------------------------------------------------------------------------- ANY_WORD_CHARACTER("\\w", // Any word character [a-zA-Z0-9_]