diff options
Diffstat (limited to 'clformat/src/main/java/bjc/utils')
| -rw-r--r-- | clformat/src/main/java/bjc/utils/ioutils/format/CLTokenizer.java | 13 | ||||
| -rw-r--r-- | clformat/src/main/java/bjc/utils/ioutils/format/SimpleDecree.java | 32 |
2 files changed, 41 insertions, 4 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( |
