summaryrefslogtreecommitdiff
path: root/src/runtime/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/java/org')
-rw-r--r--src/runtime/java/org/grammaticalframework/pgf/Completer.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/runtime/java/org/grammaticalframework/pgf/Completer.java b/src/runtime/java/org/grammaticalframework/pgf/Completer.java
new file mode 100644
index 000000000..21d3ea127
--- /dev/null
+++ b/src/runtime/java/org/grammaticalframework/pgf/Completer.java
@@ -0,0 +1,37 @@
+package org.grammaticalframework.pgf;
+
+import java.util.*;
+
+class Completer implements Iterable<TokenProb> {
+ private Concr concr;
+ private String s;
+ private String prefix;
+ private String startCat;
+ private TokenIterator iter;
+
+ public Completer(Concr concr, String startCat, String s, String prefix) throws ParseError {
+ this.concr = concr;
+ this.startCat = startCat;
+ this.s = s;
+ this.prefix = prefix;
+ this.iter = complete(concr, startCat, s, prefix);
+ }
+
+ public Iterator<TokenProb> iterator() {
+ if (iter == null) {
+ // If someone has asked for a second iterator over
+ // the same parse results then we have to parse again.
+ try {
+ return complete(concr, startCat, s, prefix);
+ } catch (ParseError e) {
+ return null;
+ }
+ } else {
+ TokenIterator tmp_iter = iter;
+ iter = null;
+ return tmp_iter;
+ }
+ }
+
+ static native TokenIterator complete(Concr concr, String startCat, String s, String prefix) throws ParseError;
+}