Skip to content

Commit 15ea8c2

Browse files
committed
implement sandbox tagging and optional recognition of these words
1 parent 1529e9f commit 15ea8c2

7 files changed

Lines changed: 45 additions & 16 deletions

File tree

dictionary.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ e:
151151
`[`marks the start of a direct object`]`(particle def);
152152

153153
eliki:
154-
# # sandbox
155-
#
156-
# trial(n);
157-
# adversity(n);
158-
# bittersweet(adj opinion);
154+
@sandbox;
155+
156+
trial(n);
157+
adversity(n);
158+
bittersweet(adj opinion);
159159

160160
en:
161161
# core

dist/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ <h1>
129129
Randomize output order</label>
130130
<label><input id="multiline" type="checkbox" />
131131
Multiline input</label>
132+
<label><input id="sandbox" type="checkbox" />
133+
Recognize marginal words</label>
132134
<label for="quantity">Singular and plural forms</label>
133135
<select id="quantity">
134136
<option selected value="both">Show all</option>

src/dictionary/dictionary.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { settings } from "../settings.ts";
12
import { dictionary as globalDictionary } from "./global_dictionary.ts";
2-
import { Definition, Dictionary } from "./type.ts";
3+
import { Definition, Dictionary, Entry } from "./type.ts";
34

45
// all of these global constants are mutable
56

7+
let sandbox = false;
8+
69
const customDictionary: Dictionary = new Map();
710
export const dictionary: Dictionary = new Map();
811

@@ -15,6 +18,12 @@ export const tokiPonaWordSet: Set<string> = new Set();
1518

1619
update();
1720

21+
export function updateSandboxInclusion(): void {
22+
if (sandbox !== settings.sandbox) {
23+
sandbox = settings.sandbox;
24+
update();
25+
}
26+
}
1827
export function loadCustomDictionary(dictionary: Dictionary): void {
1928
customDictionary.clear();
2029
for (const [key, value] of dictionary) {
@@ -24,10 +33,14 @@ export function loadCustomDictionary(dictionary: Dictionary): void {
2433
}
2534
function update() {
2635
dictionary.clear();
27-
const words = new Set([
28-
...globalDictionary.keys(),
29-
...customDictionary.keys(),
30-
]);
36+
const words = new Set(
37+
[
38+
...globalDictionary.entries(),
39+
...customDictionary.entries(),
40+
]
41+
.filter(([_, entry]) => !entry.sandbox || settings.sandbox)
42+
.map(([word]) => word),
43+
);
3144
for (const word of words) {
3245
const entry = customDictionary.get(word) ?? globalDictionary.get(word)!;
3346
if (entry.definitions.length > 0) {

src/dictionary/parser.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const closeBracket = lex(matchString("]", "close bracket"));
8080
const comma = lex(matchString(",", "comma"));
8181
const semicolon = lex(matchString(";", "semicolon"));
8282
const slash = lex(matchString("/", "slash"));
83+
const atSign = lex(matchString("@", "slash"));
8384

8485
const keyword = memoize(<T extends string>(keyword: T) =>
8586
lex(
@@ -629,15 +630,19 @@ const positionedHead = sequence(
629630
.map(([init, last]) => [...init, last]);
630631
const entry = withSource(
631632
ignore.with(
632-
allWithCheck(
633-
new CheckedParser(
634-
sequence(unescapedWord, choiceOnlyOne(openParenthesis, slash)),
635-
definition.skip(semicolon),
633+
sequence(
634+
optionalAll(sequence(atSign, keyword("sandbox"), semicolon)),
635+
allWithCheck(
636+
new CheckedParser(
637+
sequence(unescapedWord, choiceOnlyOne(openParenthesis, slash)),
638+
definition.skip(semicolon),
639+
),
636640
),
637641
),
638642
),
639643
)
640-
.map(([definitions, source]): Entry => ({
644+
.map(([[sandbox, definitions], source]): Entry => ({
645+
sandbox: sandbox != null,
641646
definitions,
642647
source: source.trimEnd(),
643648
}));

src/dictionary/type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export type Definition =
9494
| Readonly<{ type: "preposition"; preposition: string }>
9595
| Readonly<{ type: "interjection"; interjection: string }>;
9696
export type Entry = Readonly<{
97+
sandbox: boolean;
9798
definitions: ReadonlyArray<Definition>;
9899
source: string;
99100
}>;

src/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { closestString } from "@std/text/closest-string";
44
import BrowserDetector from "browser-dtector";
55
import PROJECT_DATA from "../project_data.json" with { type: "json" };
66
import { extractResultError, Result, ResultError } from "./compound.ts";
7-
import { dictionary, loadCustomDictionary } from "./dictionary/dictionary.ts";
7+
import {
8+
dictionary,
9+
loadCustomDictionary,
10+
updateSandboxInclusion,
11+
} from "./dictionary/dictionary.ts";
812
import { parseDictionary } from "./dictionary/parser.ts";
913
import { Dictionary } from "./dictionary/type.ts";
1014
import {
@@ -181,6 +185,7 @@ function main() {
181185

182186
// load settings
183187
loadFromLocalStorage();
188+
updateSandboxInclusion();
184189

185190
// states for storing previous dictionary states for discarding dictionary edits
186191
let lastSavedText: string = customDictionaryTextBox.value;
@@ -332,6 +337,7 @@ function main() {
332337
});
333338
confirmButton.addEventListener("click", () => {
334339
loadFromDom();
340+
updateSandboxInclusion();
335341
updateLabel();
336342
settingsDialogBox.close();
337343
});

src/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ export type Redundancy = "both" | "condensed" | "default only";
44
export type Settings = {
55
randomize: boolean;
66
multiline: boolean;
7+
sandbox: boolean;
78
quantity: Redundancy;
89
tense: Redundancy;
910
};
1011
// the default value may change, also change `index.html`
1112
export const defaultSettings: Readonly<Settings> = Object.freeze({
1213
randomize: false,
1314
multiline: false,
15+
sandbox: false,
1416
quantity: "both",
1517
tense: "both",
1618
});

0 commit comments

Comments
 (0)