Skip to content

Commit

Permalink
Fix unrecognized 重紐A類
Browse files Browse the repository at this point in the history
  • Loading branch information
graphemecluster committed Sep 14, 2022
1 parent 9beca79 commit 27ee999
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
3 changes: 3 additions & 0 deletions src/lib/音韻地位.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ test('音韻地位.調整', t => {
t.is(地位.調整({ : '見', : '合' }).描述, '見合三元上');
t.is(地位.調整`見母 合口`.描述, '見合三元上');
t.is(地位.調整`${'見'}${'合口'}`.描述, '見合三元上');
t.is(地位.調整`仙韻 重紐A類`.描述, '幫三A仙上');
t.is(地位.調整`仙韻 重紐${'A'}類`.描述, '幫三A仙上');
t.throws(() => 地位.調整`壞耶`, { message: 'unrecognized expression: 壞耶' });
t.throws(() => 地位.調整`見影母`, { message: 'unrecognized expression: 見影母' });
t.throws(() => 地位.調整`${'見影'}母`, { message: 'unexpected 母: 見影' });
t.throws(() => 地位.調整`見母 ${'影'}母`, { message: 'duplicated assignment of 母' });
t.throws(() => 地位.調整`${'開合'}中立`, { message: 'unrecognized expression: 開合, 中立' });
t.throws(() => 地位.調整`仙韻 重紐${'A類'}`, { message: 'unrecognized expression: 重紐, A類' });
t.is(地位.描述, '幫三元上', '.調整() 不修改原對象');
});

Expand Down
54 changes: 27 additions & 27 deletions src/lib/音韻地位.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const 脣音分寒桓by分析體系: Record<其他分析體系, boolean> = {
yonh: true,
};

/** @internal Indicates bypassed verification in `音韻地位.constructor` */
/** (For internal use) Indicates bypassed verification in `音韻地位.constructor` */
export const Unchecked: 其他分析體系 = Symbol('Unchecked') as unknown as 其他分析體系;

/**
Expand Down Expand Up @@ -445,27 +445,27 @@ export class 音韻地位 {
if (typeof 調整屬性 === 'string') 調整屬性 = [調整屬性];

if (isArray(調整屬性)) {
const tokens: string[][] = [[]];
const tokenGroups: string[][] = [[]];
for (let i = 0; i < 調整屬性.length; i++) {
let 屬性 = 調整屬性[i];
let fragment = 調整屬性[i];
if (!i) {
屬性 = 屬性.trimStart();
fragment = fragment.trimStart();
}
if (i === 調整屬性.length - 1) {
屬性 = 屬性.trimEnd();
fragment = fragment.trimEnd();
}

const fragments = 屬性.split(/\s+/);
for (let j = 0; j < fragments.length; j++) {
if (fragments[j]) {
tokens[tokens.length - 1].push(fragments[j]);
const tokens = fragment.split(/\s+/);
for (let j = 0; j < tokens.length; j++) {
if (tokens[j]) {
tokenGroups[tokenGroups.length - 1].push(tokens[j]);
}
if (j < fragments.length - 1) {
tokens.push([]);
if (j < tokens.length - 1) {
tokenGroups.push([]);
}
}
if (i < 參數.length) {
tokens[tokens.length - 1].push(參數[i]);
tokenGroups[tokenGroups.length - 1].push(參數[i]);
}
}

Expand All @@ -475,32 +475,32 @@ export class 音韻地位 {
音韻屬性[屬性] = ;
};

for (let fragment of tokens) {
assert(fragment.length, 'empty expression');
for (let tokens of tokenGroups) {
assert(tokens.length, 'empty expression');
let original: string | undefined;
if (fragment.length === 1) {
switch (fragment[0]) {
if (tokens.length === 1) {
switch (tokens[0]) {
case '開合中立':
tryAssign('呼', null);
continue;
case '不分重紐':
tryAssign('重紐', null);
continue;
}
original = fragment[0];
fragment = [...fragment[0]];
original = tokens[0];
tokens = [...tokens[0]];
}
let 屬性 = tokens[tokens.length - 1];
const = tokens[tokens.length - 2];
assert(
fragment.length === 3
? fragment[0] === '重紐' && fragment[1] === '類' && fragment.shift()
: fragment.length === 2 && ['母', '等', '韻', '聲', '口'].includes(fragment[1]),
`unrecognized expression: ${original ?? fragment.join(', ')}`
屬性 === '類' ? tokens.slice(0, -2).join('') === '重紐' : tokens.length === 2 && ['母', '等', '韻', '聲', '口'].includes(屬性),
`unrecognized expression: ${original ?? tokens.join(', ')}`
);
if (fragment[1] === '口') fragment[1] = '呼';
if (fragment[1] === '類') fragment[1] = '重紐';
const check = 檢查[fragment[1] as keyof 部分音韻屬性];
assert(check.includes(fragment[0]), `unexpected ${fragment[1]}: ${fragment[0]}`);
tryAssign(fragment[1] as keyof 部分音韻屬性, fragment[0]);
if (屬性 === '口') 屬性 = '呼';
if (屬性 === '類') 屬性 = '重紐';
const check = 檢查[屬性 as keyof 部分音韻屬性];
assert(check.includes(), `unexpected ${屬性}: ${}`);
tryAssign(屬性 as keyof 部分音韻屬性, );
}

調整屬性 = 音韻屬性;
Expand Down

0 comments on commit 27ee999

Please sign in to comment.