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;
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 Fcl fcl;
@ -34,10 +47,11 @@ public class Dictionary {
dict.remove(existing);
}
public Set<String> wordList() {
public Set<String> wordList(Filter filter) {
Set<String> result = new HashSet<>();
for (Word word : dict) {
result.add(word.name());
if (filter.shouldInclude(word.name()))
result.add(word.name());
}
return result;
}

View file

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