Skip to content

Commit 9afcb60

Browse files
committed
reorder noun
1 parent 140070c commit 9afcb60

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/translator/fixer.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import * as English from "./ast.ts";
44
import { encodeDeterminer } from "./determiner.ts";
55
import { FilteredError } from "./error.ts";
66

7+
function rankNoun(noun: English.NounPhrase): number {
8+
switch (noun.type) {
9+
case "simple":
10+
return ["third", "second", "first"].indexOf(noun.perspective);
11+
case "compound":
12+
return rankNoun(noun.nouns[0]);
13+
}
14+
}
715
function fixNounPhrase(noun: English.NounPhrase): English.NounPhrase {
816
switch (noun.type) {
917
case "simple":
@@ -15,7 +23,12 @@ function fixNounPhrase(noun: English.NounPhrase): English.NounPhrase {
1523
prepositions: noun.prepositions.map(fixPreposition),
1624
};
1725
case "compound":
18-
return { ...noun, nouns: noun.nouns.map(fixNounPhrase) };
26+
return {
27+
...noun,
28+
nouns: noun.nouns
29+
.map(fixNounPhrase)
30+
.sort((a, b) => rankNoun(a) - rankNoun(b)),
31+
};
1932
}
2033
}
2134
function filterKind(

0 commit comments

Comments
 (0)