summaryrefslogtreecommitdiff
path: root/clformat/src
diff options
context:
space:
mode:
Diffstat (limited to 'clformat/src')
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java13
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java32
-rw-r--r--clformat/src/main/java/module-info.java15
-rw-r--r--clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java9
4 files changed, 58 insertions, 11 deletions
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java b/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java
index 7ed76d2..9fd56f5 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java
@@ -128,6 +128,8 @@ public class CLTokenizer implements Iterator<SimpleDecree> {
dir = new SimpleDecree(directiveName, isUser,
CLParameters.fromDirective(directiveParameterString),
CLModifiers.fromString(directiveModifierString));
+
+ dir.setPosition(mat.start(), mat.end());
}
if (tmp.equals("")) {
@@ -138,7 +140,7 @@ public class CLTokenizer implements Iterator<SimpleDecree> {
return dcr;
}
- return new SimpleDecree(sb.toString());
+ return new SimpleDecree(sb.toString(), mat.start(), mat.end());
}
mat.appendTail(sb);
@@ -182,7 +184,10 @@ public class CLTokenizer implements Iterator<SimpleDecree> {
GroupDecree newGroup = new GroupDecree();
newGroup.opening = openedWith;
- if (!hasNext()) throw new NoSuchElementException("No decrees available");
+ if (!hasNext()) {
+ String fmt = "No decrees available for group starting with %s at %#s";
+ throw new NoSuchElementException(String.format(fmt, openedWith.name, openedWith.position));
+ }
ClauseDecree curClause = new ClauseDecree();
@@ -233,8 +238,8 @@ public class CLTokenizer implements Iterator<SimpleDecree> {
if (newGroup.closing == null) {
String msg = String.format(
- "Did not find closing directive for group (wanted \"%s\", last decree was \"%s\")",
- desiredClosing, curDecree.name);
+ "Did not find closing directive for group (wanted \"%s\", last decree was \"%s\" at %#s)",
+ desiredClosing, curDecree.name, curDecree.position);
throw new NoSuchElementException(msg);
}
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java b/clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java
index a7db42f..35d4355 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java
@@ -1,5 +1,8 @@
package bjc.utils.ioutils.format;
+import bjc.data.Pair;
+import bjc.data.SimplePair;
+
/**
* A decree is the building blocks of what we need to pick and call a directive.
*
@@ -35,6 +38,11 @@ public class SimpleDecree implements Decree {
public CLModifiers modifiers;
/**
+ * The position in the input this decree had
+ */
+ public Pair<Integer, Integer> position;
+
+ /**
* Create a new blank decree.
*/
public SimpleDecree() {
@@ -54,6 +62,20 @@ public class SimpleDecree implements Decree {
}
/**
+ * Create a new literal text directive.
+ *
+ * @param txt
+ * The text of the directive.
+ * @param start The starting position of this directive
+ * @param end The ending position of this directive
+ */
+ public SimpleDecree(String txt, int start, int end) {
+ this(txt);
+
+ this.setPosition(start, end);
+ }
+
+ /**
* Create a new directive.
*
* @param name
@@ -120,6 +142,16 @@ public class SimpleDecree implements Decree {
else return name.equals(nam);
}
+ /**
+ * Set the position of this decree.
+ *
+ * @param start The starting position of this decree
+ * @param end The ending position of this decree
+ */
+ public void setPosition(int start, int end) {
+ position = new SimplePair<>(start, end);
+ }
+
@Override
public String toString() {
return String.format(
diff --git a/clformat/src/main/java/module-info.java b/clformat/src/main/java/module-info.java
index d32a9a7..51396bf 100644
--- a/clformat/src/main/java/module-info.java
+++ b/clformat/src/main/java/module-info.java
@@ -1,10 +1,21 @@
+/**
+ * Represents an implementation of string formatting which is inspired by Common
+ * Lisps FORMAT.
+ *
+ * I say inspired because there are a number of extensions to it, as well as a
+ * few things that either aren't implemented, or are implemented in a different
+ * way.
+ *
+ * @author bjculkin
+ *
+ */
module clformat {
exports bjc.utils.ioutils.format.directives;
exports bjc.utils.ioutils.format;
exports bjc.utils.ioutils.format.exceptions;
- requires bjc.utils;
- requires esodata;
+ requires transitive bjc.utils;
+ requires transitive esodata;
requires inflexion;
requires junit;
} \ No newline at end of file
diff --git a/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java b/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java
index 629e802..250e52c 100644
--- a/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java
+++ b/clformat/src/test/java/bjc/utils/test/ioutils/CLFormatterTest.java
@@ -101,13 +101,12 @@ public class CLFormatterTest {
assertEquals("XIV xiv", format("~@R ~(~@R~)", 14, 14));
}
- // @Test
+// @Test
public void testListPrinting() {
// Test printing a list
- // String fmtStr = "Items:~#[ none~; ~A~; ~A and ~A~:;~@{~#[~; and~]
- // ~A~^,~}~].";
- String fmtStr
- = "Items:~#[ none~; ~A~; ~A and ~A~:;~@{~#*[ ~A,~; and ~A~; ~A~]~}~].";
+ String fmtStr = "Items:~#[ none~; ~A~; ~A and ~A~:;~@{~#[~; and~]~A~^,~}~].";
+// String fmtStr
+// = "Items:~#[ none~; ~A~; ~A and ~A~:;~@{~#*[ ~A,~; and ~A~; ~A~]~}~].";
fmt.DEBUG = true;
assertEquals("Items: none.", format(fmtStr));