Skip to content

Commit 59782df

Browse files
committed
rename
1 parent 77a4aed commit 59782df

27 files changed

+382
-366
lines changed

dictionary/parser.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ const adjective = checkedSequence(
232232
optionalAll(keyword("gerund-like")).skip(closeParenthesis),
233233
),
234234
)
235-
.map(([[adverb, adjective], [kind, gerundLike]]) => ({
236-
adverb,
235+
.map(([[adverbs, adjective], [kind, gerundLike]]) => ({
236+
adverbs,
237237
adjective,
238238
kind,
239239
gerundLike: gerundLike != null,
@@ -250,10 +250,10 @@ const noun = sequence(
250250
.map(([adjective, name]) => ({ adjective, name })),
251251
),
252252
)
253-
.map(([determiner, adjective, noun, postAdjective]) => ({
253+
.map(([determiners, adjectives, noun, postAdjective]) => ({
254254
...noun,
255-
determiner,
256-
adjective,
255+
determiners,
256+
adjectives,
257257
postAdjective,
258258
}));
259259
const checkedNoun = new CheckedParser(
@@ -410,9 +410,9 @@ const compoundAdjectiveDefinition = checkedSequence(
410410
.skip(keyword("c")),
411411
closeParenthesis.with(adjective.parser),
412412
)
413-
.map((adjective) => ({ type: "compound adjective", adjective }))
414-
.filterWithPositionedError(({ adjective }) =>
415-
adjective.every((adjective) => adjective.adverb.length === 0) ||
413+
.map((adjectives) => ({ type: "compound adjective", adjectives }))
414+
.filterWithPositionedError(({ adjectives }) =>
415+
adjectives.every((adjective) => adjective.adverbs.length === 0) ||
416416
throwError("compound adjective cannot have adverb")
417417
);
418418
const verbDefinition = checkedSequence(
@@ -434,9 +434,9 @@ const verbDefinition = checkedSequence(
434434
))
435435
.map(nullableAsArray),
436436
)
437-
.map(([_, indirectObject]) => ({
437+
.map(([_, indirectObjects]) => ({
438438
directObject: null,
439-
indirectObject,
439+
indirectObjects,
440440
forObject: true,
441441
predicateType: null,
442442
})),
@@ -446,7 +446,7 @@ const verbDefinition = checkedSequence(
446446
)
447447
.map(() => ({
448448
directObject: null,
449-
indirectObject: [],
449+
indirectObjects: [],
450450
forObject: false,
451451
predicateType: "verb",
452452
})),
@@ -461,7 +461,7 @@ const verbDefinition = checkedSequence(
461461
)
462462
.map(() => ({
463463
directObject: null,
464-
indirectObject: [],
464+
indirectObjects: [],
465465
forObject: false,
466466
predicateType: "noun adjective",
467467
})),
@@ -488,7 +488,7 @@ const verbDefinition = checkedSequence(
488488
if (rawIndirectObject == null) {
489489
return {
490490
directObject,
491-
indirectObject: [],
491+
indirectObjects: [],
492492
forObject: false,
493493
predicateType: null,
494494
};
@@ -497,14 +497,14 @@ const verbDefinition = checkedSequence(
497497
if (indirectObject === "template") {
498498
return {
499499
directObject,
500-
indirectObject: [],
500+
indirectObjects: [],
501501
forObject: preposition,
502502
predicateType: null,
503503
};
504504
} else {
505505
return {
506506
directObject,
507-
indirectObject: [{
507+
indirectObjects: [{
508508
preposition,
509509
object: indirectObject,
510510
}],

dictionary/type.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export type NounForms = Readonly<{
55
export type Noun =
66
& NounForms
77
& Readonly<{
8-
determiner: ReadonlyArray<Determiner>;
9-
adjective: ReadonlyArray<Adjective>;
8+
determiners: ReadonlyArray<Determiner>;
9+
adjectives: ReadonlyArray<Adjective>;
1010
gerund: boolean;
1111
postAdjective:
1212
| null
@@ -51,7 +51,7 @@ export type Adverb = Readonly<{
5151
negative: boolean;
5252
}>;
5353
export type Adjective = Readonly<{
54-
adverb: ReadonlyArray<Adverb>;
54+
adverbs: ReadonlyArray<Adverb>;
5555
adjective: string;
5656
kind: AdjectiveType;
5757
gerundLike: boolean;
@@ -63,7 +63,7 @@ export type VerbForms = Readonly<{
6363
}>;
6464
export type PartialVerb = Readonly<{
6565
directObject: null | Noun;
66-
indirectObject: ReadonlyArray<
66+
indirectObjects: ReadonlyArray<
6767
Readonly<{
6868
preposition: string;
6969
object: Noun;
@@ -88,7 +88,7 @@ export type Definition =
8888
| (Readonly<{ type: "adjective" }> & Adjective)
8989
| Readonly<{
9090
type: "compound adjective";
91-
adjective: ReadonlyArray<Adjective>;
91+
adjectives: ReadonlyArray<Adjective>;
9292
}>
9393
| (Readonly<{ type: "adverb" }> & Adverb)
9494
| (Readonly<{ type: "verb" }> & Verb)

src/compound.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,19 @@ export class IterableResult<const T> {
157157
}
158158
collect(): ReadonlyArray<T> {
159159
const array: Array<T> = [];
160-
const error: Array<ResultError> = [];
160+
const errors: Array<ResultError> = [];
161161
for (const result of this.iterable()) {
162162
switch (result.type) {
163163
case "value":
164164
array.push(result.value);
165165
break;
166166
case "error":
167-
error.push(result.error);
167+
errors.push(result.error);
168168
break;
169169
}
170170
}
171-
if (error.length > 0) {
172-
throw new AggregateError(error);
171+
if (errors.length > 0) {
172+
throw new AggregateError(errors);
173173
} else {
174174
return array;
175175
}

src/main.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import { checkLocalStorage, setIgnoreError } from "./local_storage.ts";
1818
import { PositionedError } from "./parser/parser_lib.ts";
1919
import { settings } from "./settings.ts";
2020
import {
21-
loadFromElements,
21+
loadFromDom,
2222
loadFromLocalStorage,
23-
resetElementsToCurrent,
24-
resetElementsToDefault,
23+
resetDomToCurrent,
24+
resetDomToDefault,
2525
} from "./settings_frontend.ts";
2626
import { translate } from "./translator/translator.ts";
2727

@@ -312,15 +312,15 @@ function main() {
312312
settingsDialogBox.showModal();
313313
});
314314
confirmButton.addEventListener("click", () => {
315-
loadFromElements();
315+
loadFromDom();
316316
updateLabel();
317317
settingsDialogBox.close();
318318
});
319319
cancelButton.addEventListener("click", () => {
320-
resetElementsToCurrent();
320+
resetDomToCurrent();
321321
settingsDialogBox.close();
322322
});
323-
resetButton.addEventListener("click", resetElementsToDefault);
323+
resetButton.addEventListener("click", resetDomToDefault);
324324
customDictionaryButton.addEventListener("click", () => {
325325
customDictionaryDialogBox.showModal();
326326
if (checkLocalStorage()) {

src/parser/filter.ts

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const MODIFIER_RULES: ReadonlyArray<(modifier: Modifier) => boolean> = [
9898
(modifier) => modifier.type !== "pi" || modifier.phrase.emphasis == null,
9999
];
100100
export const MULTIPLE_MODIFIERS_RULES: ReadonlyArray<
101-
(modifier: ReadonlyArray<Modifier>) => boolean
101+
(modifiers: ReadonlyArray<Modifier>) => boolean
102102
> = [
103103
// // disallow multiple pi
104104
// (modifiers) =>
@@ -166,7 +166,7 @@ export const MULTIPLE_MODIFIERS_RULES: ReadonlyArray<
166166
}
167167
},
168168
];
169-
export const PHRASE_RULE: ReadonlyArray<(phrase: Phrase) => boolean> = [
169+
export const PHRASE_RULES: ReadonlyArray<(phrase: Phrase) => boolean> = [
170170
// disallow preverb modifiers other than "ala"
171171
(phrase) =>
172172
phrase.type !== "preverb" || modifiersIsAlaOrNone(phrase.modifiers) ||
@@ -199,38 +199,39 @@ export const PHRASE_RULE: ReadonlyArray<(phrase: Phrase) => boolean> = [
199199
.every(({ emphasis }) => emphasis == null) ||
200200
throwError(new UnrecognizedError("nested emphasis")),
201201
];
202-
export const PREPOSITION_RULE: ReadonlyArray<(phrase: Preposition) => boolean> =
203-
[
204-
// disallow preverb modifiers other than "ala"
205-
(preposition) =>
206-
modifiersIsAlaOrNone(preposition.modifiers) ||
207-
throwError(
208-
new UnrecognizedError('preverb with modifiers other than "ala"'),
209-
),
202+
export const PREPOSITION_RULES: ReadonlyArray<
203+
(phrase: Preposition) => boolean
204+
> = [
205+
// disallow preverb modifiers other than "ala"
206+
(preposition) =>
207+
modifiersIsAlaOrNone(preposition.modifiers) ||
208+
throwError(
209+
new UnrecognizedError('preverb with modifiers other than "ala"'),
210+
),
210211

211-
// disallow nested preposition
212-
(preposition) =>
213-
!everyPhraseInMultiplePhrases(preposition.phrases)
214-
.some(hasPrepositionInPhrase) ||
215-
throwError(new UnrecognizedError("preposition inside preposition")),
212+
// disallow nested preposition
213+
(preposition) =>
214+
!everyPhraseInMultiplePhrases(preposition.phrases)
215+
.some(hasPrepositionInPhrase) ||
216+
throwError(new UnrecognizedError("preposition inside preposition")),
216217

217-
// preposition with "anu" must not have emphasis particle
218-
(preposition) =>
219-
preposition.emphasis == null || preposition.phrases.type !== "anu",
218+
// preposition with "anu" must not have emphasis particle
219+
(preposition) =>
220+
preposition.emphasis == null || preposition.phrases.type !== "anu",
220221

221-
// inner phrase must not have emphasis particle
222-
(preposition) =>
223-
preposition.phrases.type !== "single" ||
224-
!phraseHasTopLevelEmphasis(preposition.phrases.phrase),
222+
// inner phrase must not have emphasis particle
223+
(preposition) =>
224+
preposition.phrases.type !== "single" ||
225+
!phraseHasTopLevelEmphasis(preposition.phrases.phrase),
225226

226-
// emphasis must not be nested
227-
(preposition) =>
228-
preposition.emphasis == null ||
229-
everyWordUnitInPreposition(preposition)
230-
.every(({ emphasis }) => emphasis == null) ||
231-
throwError(new UnrecognizedError("nested emphasis")),
232-
];
233-
export const CONTEXT_CLAUSE_RULE: ReadonlyArray<
227+
// emphasis must not be nested
228+
(preposition) =>
229+
preposition.emphasis == null ||
230+
everyWordUnitInPreposition(preposition)
231+
.every(({ emphasis }) => emphasis == null) ||
232+
throwError(new UnrecognizedError("nested emphasis")),
233+
];
234+
export const CONTEXT_CLAUSE_RULES: ReadonlyArray<
234235
(contextClause: ContextClause) => boolean
235236
> = [
236237
// only allow "anu la" when allowed by the settings
@@ -241,7 +242,7 @@ export const CONTEXT_CLAUSE_RULE: ReadonlyArray<
241242
clause.type !== "anu" || clause.anu.type !== "x ala x" ||
242243
throwError(new UnrecognizedError('"anu ala anu la"')),
243244
];
244-
export const CLAUSE_RULE: ReadonlyArray<(clause: Clause) => boolean> = [
245+
export const CLAUSE_RULES: ReadonlyArray<(clause: Clause) => boolean> = [
245246
// disallow preposition in subject
246247
(clause) => {
247248
let phrases: MultiplePhrases;
@@ -308,7 +309,7 @@ export const CLAUSE_RULE: ReadonlyArray<(clause: Clause) => boolean> = [
308309
return true;
309310
},
310311
];
311-
export const SENTENCE_RULE: ReadonlyArray<(sentence: Sentence) => boolean> = [
312+
export const SENTENCE_RULES: ReadonlyArray<(sentence: Sentence) => boolean> = [
312313
// disallow "taso ala taso" or "kin ala kin"
313314
(sentence) => {
314315
if (sentence.type === "simple") {
@@ -334,7 +335,7 @@ export const SENTENCE_RULE: ReadonlyArray<(sentence: Sentence) => boolean> = [
334335
// there can't be more than 1 "x ala x" or "seme"
335336
(sentence) => {
336337
if (sentence.interrogative != null) {
337-
const interrogative = everyWordUnitInSentence(sentence)
338+
const interrogatives = everyWordUnitInSentence(sentence)
338339
.filter((wordUnit) => {
339340
switch (wordUnit.type) {
340341
case "number":
@@ -346,7 +347,7 @@ export const SENTENCE_RULE: ReadonlyArray<(sentence: Sentence) => boolean> = [
346347
return wordUnit.word === "seme";
347348
}
348349
});
349-
if (interrogative.length > 1) {
350+
if (interrogatives.length > 1) {
350351
throw new UnrecognizedError(
351352
'more than 1 interrogative elements: "x ala x" or "seme"',
352353
);
@@ -355,7 +356,7 @@ export const SENTENCE_RULE: ReadonlyArray<(sentence: Sentence) => boolean> = [
355356
return true;
356357
},
357358
];
358-
export const MULTIPLE_SENTENCES_RULE: ReadonlyArray<
359+
export const MULTIPLE_SENTENCES_RULES: ReadonlyArray<
359360
(sentences: ReadonlyArray<Sentence>) => boolean
360361
> = [
361362
// only allow at most 2 sentences

src/parser/parser.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ import {
2828
} from "./ast.ts";
2929
import { everyWordUnitInSentence } from "./extract.ts";
3030
import {
31-
CLAUSE_RULE,
32-
CONTEXT_CLAUSE_RULE,
31+
CLAUSE_RULES,
32+
CONTEXT_CLAUSE_RULES,
3333
filter,
3434
MODIFIER_RULES,
3535
MULTIPLE_MODIFIERS_RULES,
36-
MULTIPLE_SENTENCES_RULE,
36+
MULTIPLE_SENTENCES_RULES,
3737
NANPA_RULES,
38-
PHRASE_RULE,
39-
PREPOSITION_RULE,
40-
SENTENCE_RULE,
38+
PHRASE_RULES,
39+
PREPOSITION_RULES,
40+
SENTENCE_RULES,
4141
WORD_UNIT_RULES,
4242
} from "./filter.ts";
4343
import { token } from "./lexer.ts";
@@ -258,7 +258,7 @@ const phrase: Parser<Phrase> = lazy(lazyEval(() =>
258258
emphasis,
259259
})),
260260
)
261-
.filter(filter(PHRASE_RULE))
261+
.filter(filter(PHRASE_RULES))
262262
));
263263
const nanpa = sequence(wordUnit(new Set(["nanpa"]), '"nanpa"'), phrase)
264264
.map(([nanpa, phrase]) => ({ nanpa, phrase }))
@@ -449,7 +449,7 @@ const preposition = choice(
449449
emphasis,
450450
})),
451451
)
452-
.filter(filter(PREPOSITION_RULE));
452+
.filter(filter(PREPOSITION_RULES));
453453

454454
function associatedPredicates(nestingRule: ReadonlyArray<"li" | "o" | "anu">) {
455455
return sequence(
@@ -573,7 +573,7 @@ const clause = choice<Clause>(
573573
predicates,
574574
})),
575575
)
576-
.filter(filter(CLAUSE_RULE));
576+
.filter(filter(CLAUSE_RULES));
577577
const contextClause = choice<ContextClause>(
578578
wordUnit(new Set(["anu"]), '"anu"').map((anu) => ({ type: "anu", anu })),
579579
nanpa.map((nanpa) => ({ ...nanpa, type: "nanpa" })),
@@ -589,7 +589,7 @@ const contextClause = choice<ContextClause>(
589589
})),
590590
clause,
591591
)
592-
.filter(filter(CONTEXT_CLAUSE_RULE));
592+
.filter(filter(CONTEXT_CLAUSE_RULES));
593593
const la = choice(
594594
comma.with(specificWord("la")),
595595
specificWord("la").skip(comma),
@@ -688,7 +688,7 @@ const sentence = choice<Sentence>(
688688
interrogative: null,
689689
})),
690690
)
691-
.filter(filter(SENTENCE_RULE));
691+
.filter(filter(SENTENCE_RULES));
692692
export const parser: Parser<MultipleSentences> = spaces
693693
.with(
694694
lookAhead(allRest.filter((source) =>
@@ -702,6 +702,6 @@ export const parser: Parser<MultipleSentences> = spaces
702702
.map((word) => ({ type: "single word", word })),
703703
manyAtLeastOnce(sentence)
704704
.skip(end)
705-
.filter(filter(MULTIPLE_SENTENCES_RULE))
705+
.filter(filter(MULTIPLE_SENTENCES_RULES))
706706
.map((sentences) => ({ type: "sentences", sentences })),
707707
));

0 commit comments

Comments
 (0)