summaryrefslogtreecommitdiff
path: root/RGens/src/main/java/bjc/rgens/newparser/RGrammar.java
diff options
context:
space:
mode:
Diffstat (limited to 'RGens/src/main/java/bjc/rgens/newparser/RGrammar.java')
-rw-r--r--RGens/src/main/java/bjc/rgens/newparser/RGrammar.java33
1 files changed, 29 insertions, 4 deletions
diff --git a/RGens/src/main/java/bjc/rgens/newparser/RGrammar.java b/RGens/src/main/java/bjc/rgens/newparser/RGrammar.java
index a01aea4..3ffb4b2 100644
--- a/RGens/src/main/java/bjc/rgens/newparser/RGrammar.java
+++ b/RGens/src/main/java/bjc/rgens/newparser/RGrammar.java
@@ -178,7 +178,6 @@ public class RGrammar {
generateCase(start, new GenerationState(contents, rnd, vars));
String body = contents.toString();
-
/*
* Collapse duplicate spaces.
*/
@@ -190,11 +189,34 @@ public class RGrammar {
* This can be done in the grammars, but it is very tedious to
* do so.
*/
+
+ /* Handle 's */
body = body.replaceAll(" 's ", "'s ");
- body = body.replaceAll(" ([,:.)\\]'\"]) ", "$1 ");
- body = body.replaceAll(" (`[(\\[]) ", " $1");
+
+ /* Handle opening/closing punctuation. */
+ body = body.replaceAll("([(\\[]) ", " $1");
+ body = body.replaceAll(" ([)\\]'\"])", "$1 ");
+
+ /* Remove spaces around series of opening/closing punctuation. */
+ body = body.replaceAll("([(\\[])\\s+([(\\[])", "$1$2");
+ body = body.replaceAll("([)\\]])\\s+([)\\]])", "$1$2");
+
+ /* Handle inter-word punctuation. */
+ body = body.replaceAll(" ([,:.])", "$1 ");
+
+ /* Handle intra-word punctuation. */
body = body.replaceAll("\\s?([-/])\\s?", "$1");
+ /*
+ * Collapse duplicate spaces.
+ */
+ body = body.replaceAll("\\s+", " ");
+
+ /* @TODO 11/01/17 Ben Culkin :RegexRule
+ * Replace this once it is no longer needed.
+ */
+ body = body.replaceAll("\\s(ish|burg|ton|ville|opolis|field|boro|dale)", "$1");
+
return body;
}
@@ -205,7 +227,10 @@ public class RGrammar {
case NORMAL:
for (CaseElement elm : start.getElements()) {
generateElement(elm, state);
- state.contents.append(" ");
+
+ if(elm.type != CaseElement.ElementType.VARDEF) {
+ state.contents.append(" ");
+ }
}
break;
case SPACEFLATTEN: