From a3d2728f84375566da3da560b3faad018d34005d Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Fri, 16 Sep 2022 18:58:48 -0400 Subject: Cleanup --- .../java/bjc/utils/ioutils/format/CLTokenizer.java | 13 ++++++--- .../bjc/utils/ioutils/format/SimpleDecree.java | 32 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) (limited to 'clformat/src/main/java/bjc/utils/ioutils/format') 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 { 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 { 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 { 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 { 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. * @@ -34,6 +37,11 @@ public class SimpleDecree implements Decree { */ public CLModifiers modifiers; + /** + * The position in the input this decree had + */ + public Pair position; + /** * Create a new blank decree. */ @@ -53,6 +61,20 @@ public class SimpleDecree implements Decree { this.isLiteral = true; } + /** + * 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. * @@ -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( -- cgit v1.2.3