diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-09-16 22:01:43 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2018-09-16 22:01:43 -0300 |
| commit | 941a5bcff34154cd8f236ec5b2348e4721242db1 (patch) | |
| tree | a3aef17817ee17b7fee282507069e7bc4c4514e6 | |
| parent | 3b0b96a00e667a50c1135f88e9b72d68af2474cc (diff) | |
More module refactoring
| -rw-r--r-- | base/data/formats.sprop | 15 | ||||
| -rw-r--r-- | base/data/regexes.sprop | 21 | ||||
| -rw-r--r-- | clformat/data/formats.sprop | 42 | ||||
| -rw-r--r-- | clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java | 36 |
4 files changed, 69 insertions, 45 deletions
diff --git a/base/data/formats.sprop b/base/data/formats.sprop index 72f6e74..f8bd7f6 100644 --- a/base/data/formats.sprop +++ b/base/data/formats.sprop @@ -10,21 +10,6 @@ ## 2) The expression for the delimiter delimSeparatedList (?:%1$s(?:%2$s%1$s)*) -###################################### -# CL format string regular expressions -###################################### - -## Format a regular expression for matching a potential CL format directive -## Has two parts -## 1) The optional set of prefix parameters -## 2) The optional modifier -## Captures three things -## 1) The prefix parameters -## 2) The modifiers -## 3) The directive name -## 4) The function name, if the directive was a function call. -clFormatDirective ~(?<params>%1$s)?(?<modifiers>%2$s?)(?:%3$s) - #################################################### # Format strings for handling double-quoted strings. #################################################### diff --git a/base/data/regexes.sprop b/base/data/regexes.sprop index fed984a..f1e6787 100644 --- a/base/data/regexes.sprop +++ b/base/data/regexes.sprop @@ -34,27 +34,6 @@ fpExponent [eE][+-]? ## NOTE: The incomplete parts are finished by where it is inserted. fpLeader [\x00-\x20]*[+-]?(?:NaN|Infinity| -###################################### -# CL format string regular expressions -###################################### - -## Matches a format string prefix parameter -## A prefix parameter is one of -## * A signed decimal number -## * A single character preceded by a single quote -## * The letter V (or v) -## * The character # -clFormatPrefix (?:(?:[-+]?\d+|'.|[Vv]|#|%)?) - -## Match a format string modifier -## A modifier is any combination of $, :, * and @; duplicates don't matter though -clFormatModifier (?:[@$:*]+) - -## Matches a directive name. -## A directive name is either -## 1) A single, non-whitespace, non-/ character -## 2) A name enclosed in /'s -clFormatName (?:(?<name>[\S&&[^/]])|(?:/(?<funcname>[\S&&[^/]]+)/)) ############################################## # Miscellaneous validation regular expressions ############################################## diff --git a/clformat/data/formats.sprop b/clformat/data/formats.sprop new file mode 100644 index 0000000..c44ab51 --- /dev/null +++ b/clformat/data/formats.sprop @@ -0,0 +1,42 @@ +###################################### +# CL format string regular expressions +###################################### + +## Format a regular expression for matching a potential CL format directive +## Has two parts +## 1) The optional set of prefix parameters +## 2) The optional modifier +## Captures three things +## 1) The prefix parameters +## 2) The modifiers +## 3) The directive name +## 4) The function name, if the directive was a function call. +clFormatDirective ~(?<params>%1$s)?(?<modifiers>%2$s?)(?:%3$s) + +## Matches a format string prefix parameter +## A prefix parameter is one of +## * A signed decimal number +## * A single character preceded by a single quote +## * The letter V (or v) +## * The character # +clFormatPrefix (?:(?:[-+]?\d+|'.|[Vv]|#|%)?) + +## Match a format string modifier +## A modifier is any combination of $, :, * and @; duplicates don't matter though +clFormatModifier (?:[@$:*]+) + +## Matches a directive name. +## A directive name is either +## 1) A single, non-whitespace, non-/ character, optionally preceded by a grave +## 2) A name enclosed in /'s +clFormatName (?:(?<name>`?[\S&&[^/]])|(?:/(?<funcname>[\S&&[^/]]+)/)) + +################################################# +# Generic format strings for regular expressions. +################################################# + +## Format a regular expression for matching a delimiter separated list. +## Takes two parameters +## 1) The expression for each term +## 2) The expression for the delimiter +delimSeparatedList (?:%1$s(?:%2$s%1$s)*) diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java index 9e01ca6..e2a80ce 100644 --- a/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java +++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLFormatter.java @@ -2,9 +2,11 @@ package bjc.utils.ioutils.format; import bjc.utils.esodata.SingleTape; import bjc.utils.esodata.Tape; -import bjc.utils.ioutils.format.directives.*; import bjc.utils.ioutils.ReportWriter; +import bjc.utils.ioutils.SimpleProperties; +import bjc.utils.ioutils.format.directives.*; +import java.io.InputStream; import java.io.IOException; import java.io.StringWriter; import java.io.Writer; @@ -15,8 +17,6 @@ import java.util.UnknownFormatConversionException; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static bjc.utils.misc.PropertyDB.applyFormat; -import static bjc.utils.misc.PropertyDB.getRegex; /** * An implementation of CL's FORMAT. * @@ -24,19 +24,37 @@ import static bjc.utils.misc.PropertyDB.getRegex; * */ public class CLFormatter { - private static final String prefixParam = getRegex("clFormatPrefix"); - private static final String formatMod = getRegex("clFormatModifier"); - private static final String directiveName = getRegex("clFormatName"); + private static String prefixParam; + private static String formatMod; + private static String directiveName; - private static final String prefixList = applyFormat("delimSeparatedList", prefixParam, ","); - private static final String formatDirective = applyFormat("clFormatDirective", prefixList, formatMod, directiveName); + private static String prefixList; + private static String formatDirective; - private static final Pattern pFormatDirective = Pattern.compile(formatDirective); + private static Pattern pFormatDirective; private static Map<String, Directive> builtinDirectives; private Map<String, Directive> extraDirectives; static { + SimpleProperties props = new SimpleProperties(); + + try (InputStream is = CLFormatter.class.getResourceAsStream("/formats.sprop")) { + props.loadFrom(is, false); + } catch (IOException ioex) { + // WELP, we failed. Bail + throw new RuntimeException("Couldn't load formats for formatter"); + } + + prefixParam = props.get("clFormatPrefix"); + formatMod = props.get("clFormatModifier"); + directiveName = props.get("clFormatName"); + + prefixList = String.format(props.get("delimSeparatedList"), prefixParam, ","); + formatDirective = String.format(props.get("clFormatDirective"), prefixList, formatMod, directiveName); + + pFormatDirective = Pattern.compile(formatDirective); + builtinDirectives = new HashMap<>(); builtinDirectives.put("A", new AestheticDirective()); |
