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

fix(developer): raise error if virtual key in context string #9908

Merged
merged 2 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ interface
CERR_DuplicateGroup = $4071;
CERR_DuplicateStore = $4072;
CERR_RepeatedBegin = $4073;
CERR_VirtualKeyInContext = $4074;

CWARN_TooManyWarnings = $2080;
CWARN_OldVersion = $2081;
Expand Down
2 changes: 1 addition & 1 deletion developer/src/common/include/kmn_compiler_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@

#define CERR_DuplicateGroup 0x00004071
#define CERR_DuplicateStore 0x00004072

#define CERR_RepeatedBegin 0x00004073
#define CERR_VirtualKeyInContext 0x00004074

#define CWARN_TooManyWarnings 0x00002080
#define CWARN_OldVersion 0x00002081
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmc-kmn/src/compiler/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ export class KmnCompilerMessages {

static ERROR_DuplicateGroup = SevError | 0x071;
static ERROR_DuplicateStore = SevError | 0x072;

static ERROR_RepeatedBegin = SevError | 0x073;
static ERROR_VirtualKeyInContext = SevError | 0x074;

static WARN_TooManyWarnings = SevWarn | 0x080;
static WARN_OldVersion = SevWarn | 0x081;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
store(&NAME) 'ERROR_VirtualKeyInContext'
store(&VERSION) '9.0'

begin Unicode > use(main)

group(main) using keys

c ERROR_VirtualKeyInContext
[K_BKQUOTE] + 'a' > 'b'
13 changes: 10 additions & 3 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 } from '../src/compiler/messages.js';
import { CompilerMessages, KmnCompilerMessages } from '../src/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 @@ -54,15 +54,22 @@ describe('CompilerMessages', function () {
// CERR_DuplicateGroup

it('should generate CERR_DuplicateGroup if the kmn contains two groups with the same name', async function() {
await testForMessage(this, ['invalid-keyboards', 'cerr_duplicate_group.kmn'], 0x302071); //TODO: consolidate messages from kmcmplib, CompilerMessages.CERR_DuplicateGroup
await testForMessage(this, ['invalid-keyboards', 'error_duplicate_group.kmn'], KmnCompilerMessages.ERROR_DuplicateGroup);
assert.equal(callbacks.messages[0].message, "A group with this name has already been defined. Group 'ខ្មែរ' declared on line 9");
});

// CERR_DuplicateStore

it('should generate CERR_DuplicateStore if the kmn contains two stores with the same name', async function() {
await testForMessage(this, ['invalid-keyboards', 'cerr_duplicate_store.kmn'], 0x302072); //TODO: consolidate messages from kmcmplib, CompilerMessages.CERR_DuplicateStore
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

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);
assert.equal(callbacks.messages[0].message, "Virtual keys are not permitted in context");
});

});
1 change: 1 addition & 0 deletions developer/src/kmcmplib/src/CompMsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const struct CompilerError CompilerErrors[] = {
{ CERR_DuplicateGroup , "A group with this name has already been defined."},
{ CERR_DuplicateStore , "A store with this name has already been defined."},
{ CERR_RepeatedBegin , "Begin has already been set"},
{ CERR_VirtualKeyInContext , "Virtual keys are not permitted in context"},

{ CHINT_UnreachableRule , "This rule will never be matched as another rule takes precedence"},
{ CHINT_NonUnicodeFile , "Keyman Developer has detected that the file has ANSI encoding. Consider converting this file to UTF-8"},
Expand Down
8 changes: 6 additions & 2 deletions developer/src/kmcmplib/src/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1295,10 +1295,11 @@ KMX_DWORD CheckStatementOffsets(PFILE_KEYBOARD fk, PFILE_GROUP gp, PKMX_WCHAR co
}

/**
*Checks that the order of statements in the context matches the specification
* Checks that the order of statements in the context matches the specification.
* Rule structure: [context] ['+' key] '>' output
* Context structure: [nul] [if()|baselayout()|platform()]+ [char|any|context()|deadkey()|dk()|index()|notany()|outs()]
* Test that nul is first, then if(), baselayout(), platform() statements are before any other content
* Test that nul is first, then if(), baselayout(), platform() statements are before any other content.
* Also verifies that virtual keys are not found in the context.
*/
KMX_BOOL CheckContextStatementPositions(PKMX_WCHAR context) {
KMX_BOOL hadContextChar = FALSE;
Expand All @@ -1316,6 +1317,9 @@ KMX_BOOL CheckContextStatementPositions(PKMX_WCHAR context) {
AddWarningBool(CWARN_IfShouldBeAtStartOfContext);
}
break;
case CODE_EXTENDED:
AddCompileError(CERR_VirtualKeyInContext);
Copy link
Member Author

Choose a reason for hiding this comment

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

Update the function comment to note this test.

break;
default:
hadContextChar = TRUE;
}
Expand Down