Revision: 14950
http://sourceforge.net/p/foray/code/14950
Author: victormote
Date: 2026-07-30 13:27:21 +0000 (Thu, 30 Jul 2026)
Log Message:
-----------
Conform to aXSL change: Make Lexer implement ListIterator instead of Iterator, to improve client code understanding of context.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java 2026-07-30 11:02:16 UTC (rev 14949)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/Lexer4a.java 2026-07-30 13:27:21 UTC (rev 14950)
@@ -334,8 +334,9 @@
/** The input that has been submitted for processing. */
private Input input = new Input();
- /** The index into the result arrays that will be used by the next call to {@link #next()}. */
- private int nextResultIndex;
+ /** The current index within {@link output} to the iterator. The iterator's current position conceptually sits
+ * immediately after ({@link leafIndex} - 1) and immediately before ({@link leafIndex}). */
+ private int iteratorIndex;
/** The list of output tokens to be returned. */
private List<Token4a> output = new ArrayList<Token4a>();
@@ -353,6 +354,7 @@
public Lexer4a(final OrthographyServer4aStandard server) {
// this.server = server;
this.isLocked = false;
+ this.iteratorIndex = 0;
}
@Override
@@ -417,9 +419,23 @@
this.input.items.clear();
this.output.clear();
this.isLocked = false;
+ this.iteratorIndex = 0;
}
@Override
+ public boolean hasNext() {
+ if (! this.isLocked) {
+ throw new IllegalStateException("This lexer is not locked.");
+ }
+ return this.iteratorIndex < this.output.size();
+ }
+
+ @Override
+ public int nextIndex() {
+ return this.iteratorIndex;
+ }
+
+ @Override
public Token4a next() {
if (! this.isLocked) {
throw new IllegalStateException("This lexer is not locked.");
@@ -427,8 +443,8 @@
if (! hasNext()) {
throw new NoSuchElementException();
}
- final Token4a returnToken = this.output.get(this.nextResultIndex);
- this.nextResultIndex ++;
+ final Token4a returnToken = this.output.get(nextIndex());
+ this.iteratorIndex ++;
return returnToken;
}
@@ -439,24 +455,54 @@
*/
public Token4a peekNext() {
final Token4a token = next();
- this.nextResultIndex --;
+ this.iteratorIndex --;
return token;
}
@Override
- public boolean hasNext() {
+ public boolean hasPrevious() {
+ return this.iteratorIndex > 0;
+ }
+
+ @Override
+ public int previousIndex() {
+ return this.iteratorIndex - 1;
+ }
+
+ @Override
+ public Token previous() {
if (! this.isLocked) {
throw new IllegalStateException("This lexer is not locked.");
}
- return this.nextResultIndex < this.output.size();
+ if (! hasNext()) {
+ throw new NoSuchElementException();
+ }
+ final Token4a returnToken = this.output.get(previousIndex());
+ this.iteratorIndex --;
+ return returnToken;
}
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("Method \"remove\" is not supported.");
+ }
+
+ @Override
+ public void set(final Token e) {
+ throw new UnsupportedOperationException("Method \"set\" is not supported.");
+ }
+
+ @Override
+ public void add(final Token e) {
+ throw new UnsupportedOperationException("Method \"add\" is not supported.");
+ }
+
/**
* Tokenize the content and create the output.
*/
private void process() {
this.output.clear();
- this.nextResultIndex = 0;
+ this.iteratorIndex = 0;
if (this.input.items.size() < 1) {
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|