Skip to content

Commit 7f591e6

Browse files
committed
add filter rules for context clause
1 parent d4e4177 commit 7f591e6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/parser/filter.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { flattenError, throwError } from "../../misc/misc.ts";
33
import { settings } from "../settings.ts";
44
import {
55
Clause,
6+
ContextClause,
67
Modifier,
78
MultiplePhrases,
89
Nanpa,
@@ -227,6 +228,14 @@ export const PREPOSITION_RULE: ReadonlyArray<(phrase: Preposition) => boolean> =
227228
.every(({ emphasis }) => emphasis == null) ||
228229
throwError(new UnrecognizedError("nested emphasis")),
229230
];
231+
export const CONTEXT_CLAUSE_RULE: ReadonlyArray<
232+
(contextClause: ContextClause) => boolean
233+
> = [
234+
// Prevent "anu ala anu la"
235+
(clause) =>
236+
clause.type !== "anu" || clause.anu.type !== "x ala x" ||
237+
throwError(new UnrecognizedError('"anu ala anu la"')),
238+
];
230239
export const CLAUSE_RULE: ReadonlyArray<(clause: Clause) => boolean> = [
231240
// disallow preposition in subject
232241
(clause) => {

src/parser/parser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { cache } from "./cache.ts";
2929
import { everyWordUnitInSentence } from "./extract.ts";
3030
import {
3131
CLAUSE_RULE,
32+
CONTEXT_CLAUSE_RULE,
3233
filter,
3334
MODIFIER_RULES,
3435
MULTIPLE_MODIFIERS_RULES,
@@ -607,7 +608,8 @@ const contextClause = choice<ContextClause>(
607608
nanpa.map((nanpa) => ({ ...nanpa, type: "nanpa" })),
608609
wordUnit(new Set(["anu"]), '"anu"').map((anu) => ({ type: "anu", anu })),
609610
clause,
610-
);
611+
)
612+
.filter(filter(CONTEXT_CLAUSE_RULE));
611613
const la = choice(
612614
comma.with(specificWord("la")),
613615
specificWord("la").skip(comma),

0 commit comments

Comments
 (0)