diff --git a/developer/src/kmc-kmn/src/compiler/compiler.ts b/developer/src/kmc-kmn/src/compiler/compiler.ts index 8e718116710..df20b698529 100644 --- a/developer/src/kmc-kmn/src/compiler/compiler.ts +++ b/developer/src/kmc-kmn/src/compiler/compiler.ts @@ -9,7 +9,7 @@ TODO: implement additional interfaces: import { UnicodeSetParser, UnicodeSet, Osk, VisualKeyboard, KvkFileReader } from '@keymanapp/common-types'; import { CompilerCallbacks, CompilerEvent, CompilerOptions, KeymanFileTypes, KvkFileWriter, KvksFileReader } from '@keymanapp/common-types'; import loadWasmHost from '../import/kmcmplib/wasm-host.js'; -import { CompilerMessages, mapErrorFromKmcmplib } from './messages.js'; +import { CompilerMessages, mapErrorFromKmcmplib } from './kmn-compiler-messages.js'; import { WriteCompiledKeyboard } from '../kmw-compiler/kmw-compiler.js'; export interface CompilerResultFile { diff --git a/developer/src/kmc-kmn/src/compiler/messages.ts b/developer/src/kmc-kmn/src/compiler/kmn-compiler-messages.ts similarity index 99% rename from developer/src/kmc-kmn/src/compiler/messages.ts rename to developer/src/kmc-kmn/src/compiler/kmn-compiler-messages.ts index cbd35f85155..2995c8f0165 100644 --- a/developer/src/kmc-kmn/src/compiler/messages.ts +++ b/developer/src/kmc-kmn/src/compiler/kmn-compiler-messages.ts @@ -42,7 +42,7 @@ export const enum KmnCompilerMessageRanges { /* The messages in this class share the namespace with messages from - kmn_compiler_errors.h, which are generated by kmcmplib, so values below 0x1000 + kmn_compiler_errors.h, which are generated by kmcmplib, so values below 0x900 are reserved for kmcmplib messages. */ export class CompilerMessages { diff --git a/developer/src/kmc-kmn/src/kmw-compiler/javascript-strings.ts b/developer/src/kmc-kmn/src/kmw-compiler/javascript-strings.ts index bea396d4fdb..7c59f69e6f9 100644 --- a/developer/src/kmc-kmn/src/kmw-compiler/javascript-strings.ts +++ b/developer/src/kmc-kmn/src/kmw-compiler/javascript-strings.ts @@ -2,7 +2,7 @@ import { TSentinelRecord, GetSuppChar, ExpandSentinel, incxstr, xstrlen, xstrlen import { KMX } from "@keymanapp/common-types"; import { callbacks, FCallFunctions, FFix183_LadderLength, FMnemonic, FTabStop, FUnreachableKeys, IsKeyboardVersion10OrLater, IsKeyboardVersion14OrLater, kmxResult, nl, options } from "./compiler-globals.js"; -import { KmwCompilerMessages } from "./messages.js"; +import { KmwCompilerMessages } from "./kmw-compiler-messages.js"; import { FormatModifierAsBitflags, RuleIsExcludedByPlatform } from "./kmw-compiler.js"; import { KMXCodeNames, SValidIdentifierCharSet, UnreachableKeyCodes, USEnglishShift, USEnglishUnshift, USEnglishValues } from "./constants.js"; import { KMWVKeyNames, TKeymanWebTouchStandardKey, VKeyNames } from "./keymanweb-key-codes.js"; diff --git a/developer/src/kmc-kmn/src/kmw-compiler/messages.ts b/developer/src/kmc-kmn/src/kmw-compiler/kmw-compiler-messages.ts similarity index 91% rename from developer/src/kmc-kmn/src/kmw-compiler/messages.ts rename to developer/src/kmc-kmn/src/kmw-compiler/kmw-compiler-messages.ts index c0d5085dcca..0c2e5bbdb64 100644 --- a/developer/src/kmc-kmn/src/kmw-compiler/messages.ts +++ b/developer/src/kmc-kmn/src/kmw-compiler/kmw-compiler-messages.ts @@ -1,4 +1,4 @@ -import { KmnCompilerMessages } from "../compiler/messages.js"; +import { KmnCompilerMessages } from "../compiler/kmn-compiler-messages.js"; import { CompilerErrorNamespace, CompilerErrorSeverity, CompilerMessageSpec as m } from "@keymanapp/common-types"; const Namespace = CompilerErrorNamespace.KmwCompiler; @@ -19,7 +19,7 @@ export class KmwCompilerMessages extends KmnCompilerMessages { static Error_InvalidBegin = () => m(this.ERROR_InvalidBegin, `A "begin unicode" statement is required to compile a KeymanWeb keyboard`); - static Error_TouchLayoutFileInvalid = (o:{filename:string}) => m(this.ERROR_InvalidTouchLayoutFile, + static Error_InvalidTouchLayoutFile = (o:{filename:string}) => m(this.ERROR_InvalidTouchLayoutFile, `Touch layout file ${o.filename} is not valid`); static Warn_DontMixChiralAndNonChiralModifiers = () => m(this.WARN_DontMixChiralAndNonChiralModifiers, `This keyboard contains Ctrl,Alt and LCtrl,LAlt,RCtrl,RAlt sets of modifiers. Use only one or the other set for web target.`); @@ -55,8 +55,6 @@ export class KmwCompilerMessages extends KmnCompilerMessages { `Key "${o.keyId}" on platform "${o.platformName}", layer "${o.layerId}" does not have the key type "Special" or "Special (active)" but has the label "${o.label}". This feature is only supported in Keyman 14 or later`); static Error_InvalidKeyCode = (o:{keyId: string}) => m(this.ERROR_InvalidKeyCode, `Invalid key identifier "${o.keyId}"`); - static Error_InvalidTouchLayoutFile = (o:{msg: string}) => m(this.ERROR_InvalidTouchLayoutFile, - `Invalid touch layout file: ${o.msg}`); static Warn_TouchLayoutFontShouldBeSameForAllPlatforms = () => m(this.WARN_TouchLayoutFontShouldBeSameForAllPlatforms, `The touch layout font should be the same for all platforms.`); static Warn_TouchLayoutMissingRequiredKeys = (o:{layerId:string, platformName:string, missingKeys:string}) => m(this.WARN_TouchLayoutMissingRequiredKeys, @@ -71,4 +69,12 @@ export class KmwCompilerMessages extends KmnCompilerMessages { static Error_TouchLayoutIdentifierRequires15 = (o:{keyId:string, platformName:string, layerId:string}) => m(this.ERROR_TouchLayoutIdentifierRequires15, `Key "${o.keyId}" on "${o.platformName}", layer "${o.layerId}" has a multi-part identifier which requires version 15.0 or newer.`); static ERROR_TouchLayoutIdentifierRequires15 = SevError | 0x0002; + + static Error_InvalidTouchLayoutFileFormat = (o:{msg: string}) => m(this.ERROR_InvalidTouchLayoutFileFormat, + `Invalid touch layout file: ${o.msg}`); + static ERROR_InvalidTouchLayoutFileFormat = SevError | 0x0003; + + static Error_TouchLayoutFileDoesNotExist = (o:{filename:string}) => m(this.ERROR_TouchLayoutFileDoesNotExist, + `Touch layout file ${o.filename} does not exist`); + static ERROR_TouchLayoutFileDoesNotExist = SevError | 0x0004; }; diff --git a/developer/src/kmc-kmn/src/kmw-compiler/kmw-compiler.ts b/developer/src/kmc-kmn/src/kmw-compiler/kmw-compiler.ts index 986db18050e..29922a492f2 100644 --- a/developer/src/kmc-kmn/src/kmw-compiler/kmw-compiler.ts +++ b/developer/src/kmc-kmn/src/kmw-compiler/kmw-compiler.ts @@ -2,7 +2,7 @@ import { KMX, CompilerOptions, CompilerCallbacks, KvkFileReader, VisualKeyboard, import { ExpandSentinel, incxstr, xstrlen } from "./util.js"; import { options, nl, FTabStop, setupGlobals, IsKeyboardVersion10OrLater, callbacks, FFix183_LadderLength, FCallFunctions, fk } from "./compiler-globals.js"; import { JavaScript_ContextMatch, JavaScript_KeyAsString, JavaScript_Name, JavaScript_OutputString, JavaScript_Rules, JavaScript_Shift, JavaScript_ShiftAsString, JavaScript_Store, zeroPadHex } from './javascript-strings.js'; -import { KmwCompilerMessages } from "./messages.js"; +import { KmwCompilerMessages } from "./kmw-compiler-messages.js"; import { ValidateLayoutFile } from "./validate-layout-file.js"; import { VisualKeyboardFromFile } from "./visual-keyboard-compiler.js"; import { CompilerResult, STORETYPE_DEBUG, STORETYPE_OPTION, STORETYPE_RESERVED } from "../compiler/compiler.js"; @@ -157,9 +157,12 @@ export function WriteCompiledKeyboard( sLayoutFilename = callbacks.resolveFilename(kmnfile, sLayoutFilename); let result = ValidateLayoutFile(keyboard, options.saveDebug, sLayoutFilename, sVKDictionary, kmxResult.displayMap); - if(!result.result) { + if(!result) { sLayoutFile = ''; - callbacks.reportMessage(KmwCompilerMessages.Error_TouchLayoutFileInvalid({filename:sLayoutFilename})); + return null; + } else if(!result.result) { + sLayoutFile = ''; + callbacks.reportMessage(KmwCompilerMessages.Error_InvalidTouchLayoutFile({filename:sLayoutFilename})); return null; } else { sLayoutFile = result.output; diff --git a/developer/src/kmc-kmn/src/kmw-compiler/validate-layout-file.ts b/developer/src/kmc-kmn/src/kmw-compiler/validate-layout-file.ts index 6a28c38b477..16bd2dbfddd 100644 --- a/developer/src/kmc-kmn/src/kmw-compiler/validate-layout-file.ts +++ b/developer/src/kmc-kmn/src/kmw-compiler/validate-layout-file.ts @@ -3,7 +3,7 @@ import { callbacks, IsKeyboardVersion14OrLater, IsKeyboardVersion15OrLater } fro import { JavaScript_Key } from "./javascript-strings.js"; import { TRequiredKey, CRequiredKeys, CSpecialText10, CSpecialText14, CSpecialText14ZWNJ, CSpecialText14Map } from "./constants.js"; import { KeymanWebTouchStandardKeyNames, KMWAdditionalKeyNames, VKeyNames } from "./keymanweb-key-codes.js"; -import { KmwCompilerMessages } from "./messages.js"; +import { KmwCompilerMessages } from "./kmw-compiler-messages.js"; interface VLFOutput { @@ -207,13 +207,17 @@ export function ValidateLayoutFile(fk: KMX.KEYBOARD, FDebug: boolean, sLayoutFil let reader = new TouchLayoutFileReader(); let data: TouchLayout.TouchLayoutFile; try { + if(!callbacks.fs.existsSync(sLayoutFile)) { + callbacks.reportMessage(KmwCompilerMessages.Error_TouchLayoutFileDoesNotExist({filename: sLayoutFile})); + return null; + } data = reader.read(callbacks.loadFile(sLayoutFile)); if(!data) { throw new Error('Unknown error reading touch layout file'); } } catch(e) { - callbacks.reportMessage(KmwCompilerMessages.Error_InvalidTouchLayoutFile({msg: (e??'Unspecified error').toString()})); - return {output:null, result: false}; + callbacks.reportMessage(KmwCompilerMessages.Error_InvalidTouchLayoutFileFormat({msg: (e??'Unspecified error').toString()})); + return null; } let result: boolean = true; diff --git a/developer/src/kmc-kmn/src/main.ts b/developer/src/kmc-kmn/src/main.ts index 878e4c87ab7..27a4895da61 100644 --- a/developer/src/kmc-kmn/src/main.ts +++ b/developer/src/kmc-kmn/src/main.ts @@ -1,4 +1,4 @@ export { KmnCompiler } from './compiler/compiler.js'; -export { KmnCompilerMessages, CompilerMessages } from './compiler/messages.js'; -export { KmwCompilerMessages } from './kmw-compiler/messages.js'; +export { KmnCompilerMessages, CompilerMessages } from './compiler/kmn-compiler-messages.js'; +export { KmwCompilerMessages } from './kmw-compiler/kmw-compiler-messages.js'; diff --git a/developer/src/kmc-kmn/test/test-messages.ts b/developer/src/kmc-kmn/test/test-messages.ts index 72066d9018b..8123a78ae7f 100644 --- a/developer/src/kmc-kmn/test/test-messages.ts +++ b/developer/src/kmc-kmn/test/test-messages.ts @@ -1,6 +1,6 @@ import 'mocha'; import { assert } from 'chai'; -import { CompilerMessages, KmnCompilerMessages } from '../src/compiler/messages.js'; +import { CompilerMessages, KmnCompilerMessages } from '../src/compiler/kmn-compiler-messages.js'; import { TestCompilerCallbacks, verifyCompilerMessagesObject } from '@keymanapp/developer-test-helpers'; import { makePathToFixture } from './helpers/index.js'; import { KmnCompiler } from '../src/main.js'; @@ -51,21 +51,21 @@ describe('CompilerMessages', function () { await testForMessage(this, ['invalid-keyboards', 'warn_invalid_vkey_in_kvks_file.kmn'], CompilerMessages.WARN_InvalidVkeyInKvksFile); }); - // CERR_DuplicateGroup + // ERROR_DuplicateGroup it('should generate CERR_DuplicateGroup if the kmn contains two groups with the same name', async function() { await testForMessage(this, ['invalid-keyboards', 'error_duplicate_group.kmn'], KmnCompilerMessages.ERROR_DuplicateGroup); //TODO: consolidate messages from kmcmplib, CompilerMessages.CERR_DuplicateGroup assert.equal(callbacks.messages[0].message, "A group with this name has already been defined. Group 'ខ្មែរ' declared on line 9"); }); - // CERR_DuplicateStore + // ERROR_DuplicateStore it('should generate CERR_DuplicateStore if the kmn contains two stores with the same name', async function() { await testForMessage(this, ['invalid-keyboards', 'error_duplicate_store.kmn'], KmnCompilerMessages.ERROR_DuplicateStore); assert.equal(callbacks.messages[0].message, "A store with this name has already been defined. Store 'ខ្មែរ' declared on line 11"); }); - // CERR_VirtualKeyInContext + // ERROR_VirtualKeyInContext it('should generate ERROR_VirtualKeyInContext if a virtual key is found in the context part of a rule', async function() { await testForMessage(this, ['invalid-keyboards', 'error_virtual_key_in_context.kmn'], KmnCompilerMessages.ERROR_VirtualKeyInContext); diff --git a/developer/src/kmc-kmn/test/test-wasm-uset.ts b/developer/src/kmc-kmn/test/test-wasm-uset.ts index 0b11ddf789e..e2bf5fcf1d6 100644 --- a/developer/src/kmc-kmn/test/test-wasm-uset.ts +++ b/developer/src/kmc-kmn/test/test-wasm-uset.ts @@ -2,7 +2,7 @@ import 'mocha'; import { assert } from 'chai'; import { KmnCompiler } from '../src/main.js'; import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers'; -import { CompilerMessages } from '../src/compiler/messages.js'; +import { CompilerMessages } from '../src/compiler/kmn-compiler-messages.js'; import { compilerErrorFormatCode } from '@keymanapp/common-types'; describe('Compiler UnicodeSet function', function() {