From 3bc50609856e00ec6eee19a392ac39b26814bfeb Mon Sep 17 00:00:00 2001 From: zeroflag Date: Tue, 22 Feb 2022 14:07:38 +0100 Subject: [PATCH] filter out -impl words from auto complete list +font size fix --- src/main/java/com/vectron/fcl/Dictionary.java | 18 ++++++++++++++++-- src/main/java/com/vectron/fcl/Fcl.java | 6 +++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/vectron/fcl/Dictionary.java b/src/main/java/com/vectron/fcl/Dictionary.java index f893192..227e1dc 100644 --- a/src/main/java/com/vectron/fcl/Dictionary.java +++ b/src/main/java/com/vectron/fcl/Dictionary.java @@ -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 dict = new ArrayList<>(); private final Fcl fcl; @@ -34,10 +47,11 @@ public class Dictionary { dict.remove(existing); } - public Set wordList() { + public Set wordList(Filter filter) { Set result = new HashSet<>(); for (Word word : dict) { - result.add(word.name()); + if (filter.shouldInclude(word.name())) + result.add(word.name()); } return result; } diff --git a/src/main/java/com/vectron/fcl/Fcl.java b/src/main/java/com/vectron/fcl/Fcl.java index 41260c8..8e59372 100644 --- a/src/main/java/com/vectron/fcl/Fcl.java +++ b/src/main/java/com/vectron/fcl/Fcl.java @@ -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 words = new ArrayList<>(wordList()); + List 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 wordList() { - return dict.wordList(); + public Set wordList(Dictionary.Filter filter) { + return dict.wordList(filter); } } \ No newline at end of file