Skip to content

Commit 6dc4506

Browse files
committed
reorganize parser for marginal speed
1 parent d269b6d commit 6dc4506

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

dictionary/parser.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -417,19 +417,19 @@ const verbDefinition = checkedSequence(
417417
),
418418
choiceWithCheck<null | PartialVerb>(
419419
checkedSequence(
420-
keyword("modal"),
421-
sequence(closeParenthesis, template(keyword("predicate"))),
422-
)
423-
.map(() => null),
424-
checkedSequence(
425-
keyword("linking"),
426-
sequence(closeParenthesis, template(keyword("predicate"))),
420+
sequence(closeParenthesis, openBracket, keyword("object")),
421+
closeBracket
422+
.with(optionalWithCheck(
423+
simpleDefinitionWith(keyword("prep"), noun)
424+
.map(([preposition, object]) => ({ preposition, object }) as const),
425+
))
426+
.map(nullableAsArray),
427427
)
428-
.map(() => ({
428+
.map(([_, indirectObject]) => ({
429429
directObject: null,
430-
indirectObject: [],
431-
forObject: false,
432-
predicateType: "noun adjective",
430+
indirectObject,
431+
forObject: true,
432+
predicateType: null,
433433
})),
434434
checkedSequence(
435435
sequence(closeParenthesis, openBracket, keyword("predicate")),
@@ -442,19 +442,19 @@ const verbDefinition = checkedSequence(
442442
predicateType: "verb",
443443
})),
444444
checkedSequence(
445-
sequence(closeParenthesis, openBracket, keyword("object")),
446-
closeBracket
447-
.with(optionalWithCheck(
448-
simpleDefinitionWith(keyword("prep"), noun)
449-
.map(([preposition, object]) => ({ preposition, object }) as const),
450-
))
451-
.map(nullableAsArray),
445+
keyword("modal"),
446+
sequence(closeParenthesis, template(keyword("predicate"))),
452447
)
453-
.map(([_, indirectObject]) => ({
448+
.map(() => null),
449+
checkedSequence(
450+
keyword("linking"),
451+
sequence(closeParenthesis, template(keyword("predicate"))),
452+
)
453+
.map(() => ({
454454
directObject: null,
455-
indirectObject,
456-
forObject: true,
457-
predicateType: null,
455+
indirectObject: [],
456+
forObject: false,
457+
predicateType: "noun adjective",
458458
})),
459459
new CheckedParser(
460460
nothing,
@@ -554,22 +554,22 @@ const verbDefinition = checkedSequence(
554554
}
555555
});
556556
const definition = choiceWithCheck<Definition>(
557-
interjectionDefinition,
558-
particleDefinition,
559-
prepositionDefinition,
560-
numeralDefinition,
561-
fillerDefinition,
562-
fourFormPersonalPronounDefinition,
563-
twoFormPersonalPronounDefinition,
564557
// noun parser must come before adjective, compound adjective, and determiner parsers
565558
nounDefinition,
566559
// compound adjective parser must come before adjective parser
567560
compoundAdjectiveDefinition,
568561
// adjective parser must come before adverb parser
569562
adjective.map((adjective) => ({ ...adjective, type: "adjective" })),
563+
verbDefinition,
570564
adverbDefinition,
565+
interjectionDefinition,
566+
particleDefinition,
571567
determiner.map((determiner) => ({ ...determiner, type: "determiner" })),
572-
verbDefinition,
568+
prepositionDefinition,
569+
numeralDefinition,
570+
fillerDefinition,
571+
twoFormPersonalPronounDefinition,
572+
fourFormPersonalPronounDefinition,
573573
);
574574
const head = sequence(all(tokiPonaWord.skip(comma)), tokiPonaWord)
575575
.skip(colon)

0 commit comments

Comments
 (0)