filter out -impl words from auto complete list

+font size fix
This commit is contained in:
zeroflag 2022-02-22 14:07:38 +01:00
parent 9019abff9b
commit 3bc5060985
2 changed files with 19 additions and 5 deletions

View file

@ -8,6 +8,19 @@ import java.util.List;
import java.util.Set; import java.util.Set;
public class Dictionary { public class Dictionary {
public interface Filter {
boolean shouldInclude(String name);
Filter ALL = new Filter() {
public boolean shouldInclude(String name) {
return true;
}
};
Filter NO_IMPLS = new Filter() {
public boolean shouldInclude(String name) {
return !name.endsWith("-impl");
}
};
}
private final List<Word> dict = new ArrayList<>(); private final List<Word> dict = new ArrayList<>();
private final Fcl fcl; private final Fcl fcl;
@ -34,9 +47,10 @@ public class Dictionary {
dict.remove(existing); dict.remove(existing);
} }
public Set<String> wordList() { public Set<String> wordList(Filter filter) {
Set<String> result = new HashSet<>(); Set<String> result = new HashSet<>();
for (Word word : dict) { for (Word word : dict) {
if (filter.shouldInclude(word.name()))
result.add(word.name()); result.add(word.name());
} }
return result; return result;

View file

@ -451,7 +451,7 @@ public class Fcl {
addPrimitive("abort", () -> { throw new Aborted(stack.pop().asStr().value()); }); addPrimitive("abort", () -> { throw new Aborted(stack.pop().asStr().value()); });
addPrimitive("eval", () -> eval(stack.pop().asStr().value())); addPrimitive("eval", () -> eval(stack.pop().asStr().value()));
addPrimitive("words", () -> { addPrimitive("words", () -> {
List<String> words = new ArrayList<>(wordList()); List<String> words = new ArrayList<>(wordList(Dictionary.Filter.ALL));
Collections.sort(words); Collections.sort(words);
for (String each : words) { for (String each : words) {
transcript.show(each); transcript.show(each);
@ -709,7 +709,7 @@ public class Fcl {
rstack.clean(); rstack.clean();
} }
public Set<String> wordList() { public Set<String> wordList(Dictionary.Filter filter) {
return dict.wordList(); return dict.wordList(filter);
} }
} }