diff --git a/developer/src/kmc-ldml/src/compiler/keymanweb-compiler.ts b/developer/src/kmc-ldml/src/compiler/keymanweb-compiler.ts index 6869f1441ea..a35739247b4 100644 --- a/developer/src/kmc-ldml/src/compiler/keymanweb-compiler.ts +++ b/developer/src/kmc-ldml/src/compiler/keymanweb-compiler.ts @@ -9,7 +9,6 @@ export class LdmlKeyboardKeymanWebCompiler { private readonly options: LdmlCompilerOptions; private readonly nl: string; private readonly tab: string; - constructor(private callbacks: CompilerCallbacks, options?: LdmlCompilerOptions) { this.options = { ...options }; this.nl = this.options.saveDebug ? "\n" : ''; @@ -18,7 +17,7 @@ export class LdmlKeyboardKeymanWebCompiler { public compileVisualKeyboard(source: LDMLKeyboard.LDMLKeyboardXMLSourceFile) { const nl = this.nl, tab = this.tab; - const vkc = new LdmlKeyboardVisualKeyboardCompiler(); + const vkc = new LdmlKeyboardVisualKeyboardCompiler(this.callbacks); const vk: VisualKeyboard.VisualKeyboard = vkc.compile(source); let result = diff --git a/developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts b/developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts index 2db9da2b539..bbb2d83abf9 100644 --- a/developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts +++ b/developer/src/kmc-ldml/src/compiler/visual-keyboard-compiler.ts @@ -1,7 +1,11 @@ -import { VisualKeyboard, LDMLKeyboard } from "@keymanapp/common-types"; +import { VisualKeyboard, LDMLKeyboard, CompilerCallbacks } from "@keymanapp/common-types"; import { KeysCompiler } from "./keys.js"; +import { CompilerMessages } from "./messages.js"; export class LdmlKeyboardVisualKeyboardCompiler { + public constructor(private callbacks: CompilerCallbacks) { + } + public compile(source: LDMLKeyboard.LDMLKeyboardXMLSourceFile): VisualKeyboard.VisualKeyboard { let result = new VisualKeyboard.VisualKeyboard(); @@ -29,12 +33,16 @@ export class LdmlKeyboardVisualKeyboardCompiler { layer: LDMLKeyboard.LKLayer, hardware: string, ) { + const layerId = layer.id; if (hardware === 'touch') { hardware = 'us'; // TODO-LDML: US Only. Do something different here? } const keymap = KeysCompiler.getKeymapFromForms(source.keyboard3?.forms?.form, hardware); if (!keymap) { - throw Error(`Internal error: could not find keymap for form ${hardware}`); + this.callbacks.reportMessage( + CompilerMessages.Error_InvalidHardware({ formId: hardware }) + ); + return; } const shift = this.translateLayerIdToVisualKeyboardShift(layer.id); @@ -45,20 +53,23 @@ export class LdmlKeyboardVisualKeyboardCompiler { const keys = row.keys.split(' '); let x = -1; for(let key of keys) { + const keyId = key; x++; let keydef = source.keyboard3.keys?.key?.find(x => x.id == key); if (!keydef) { - throw Error(`Internal Error: could not find key id="${key}" in layer "${layer.id || ''}", row "${y}"`); + this.callbacks.reportMessage( + CompilerMessages.Error_KeyNotFoundInKeyBag({ keyId, layer: layerId, row: y, col: x, form: hardware }) + ); + } else { + vk.keys.push({ + flags: VisualKeyboard.VisualKeyboardKeyFlags.kvkkUnicode, + shift: shift, + text: keydef.output, // TODO-LDML: displays + vkey: keymap[y][x], + }); } - - vk.keys.push({ - flags: VisualKeyboard.VisualKeyboardKeyFlags.kvkkUnicode, - shift: shift, - text: keydef.output, // TODO-LDML: displays - vkey: keymap[y][x], - }); } } } diff --git a/developer/src/kmc-ldml/test/helpers/index.ts b/developer/src/kmc-ldml/test/helpers/index.ts index c919e729ac0..ea76da94b35 100644 --- a/developer/src/kmc-ldml/test/helpers/index.ts +++ b/developer/src/kmc-ldml/test/helpers/index.ts @@ -146,7 +146,7 @@ export function compileVisualKeyboard(inputFilename: string, options: LdmlCompil checkMessages(); assert.isTrue(valid, 'k.validate should not have failed'); - const vk = (new LdmlKeyboardVisualKeyboardCompiler()).compile(source); + const vk = (new LdmlKeyboardVisualKeyboardCompiler(compilerTestCallbacks)).compile(source); checkMessages(); assert.isNotNull(vk, 'LdmlKeyboardVisualKeyboardCompiler.compile should not have returned null');