Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(developer): rename messages.ts for clarity #9920

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion developer/src/kmc-kmn/src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this change?

are reserved for kmcmplib messages.
*/
export class CompilerMessages {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.`);
Expand Down Expand Up @@ -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,
Expand All @@ -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;
};
9 changes: 6 additions & 3 deletions developer/src/kmc-kmn/src/kmw-compiler/kmw-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions developer/src/kmc-kmn/src/kmw-compiler/validate-layout-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions developer/src/kmc-kmn/src/main.ts
Original file line number Diff line number Diff line change
@@ -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';
8 changes: 4 additions & 4 deletions developer/src/kmc-kmn/test/test-messages.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmc-kmn/test/test-wasm-uset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down