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): produce correct index parameter value for context in kmw compiler #13003

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mcdurdin
Copy link
Member

The KMW compiler would produce incorrect indices for the corresponding character in the context after adjusting for the presence of nul and if statements at the start of the context string, when using the context and context(n) statements in the output.

This fix addresses the offset calculation for those scenarios and adds a unit test to verify that the new offsets are correct.

I have audited the keyboards repository, and only one keyboard in the repository is impacted: sil_greek_polytonic. Once v18 is released, we should publish an updated version of that keyboard, rebuilt with the 18.0 compiler to resolve this issue.

Another keyboard, keymangr_all, is not in the keyboards repository but is also impacted by this issue. This keyboard currently has patches to workaround the issue, which would need to be removed if rebuilt with the new compiler. I will communicate this information to the author of the keyboard.

Fixes: #12980
Fixes: #12985

@keymanapp-test-bot skip

…kmw compiler

The KMW compiler would produce incorrect indices for the corresponding
character in the context after adjusting for the presence of `nul` and
`if` statements at the start of the context string, when using the
`context` and `context(n)` statements in the output.

This fix addresses the offset calculation for those scenarios and adds a
unit test to verify that the new offsets are correct.

Fixes: #12980
@keymanapp-test-bot
Copy link

keymanapp-test-bot bot commented Jan 23, 2025

User Test Results

Test specification and instructions

User tests are not required

Test Artifacts

  • Developer
    • Keyman Developer - build pending
    • Compiler Regression Tests - build pending
    • kmcomp.zip - build pending
  • Keyboards
    • Test Keyboards - build pending

@@ -759,15 +759,14 @@ export function JavaScript_OutputString(fk: KMX.KEYBOARD, FTabStops: string, fkp
case KMX.KMXFile.CODE_CONTEXT:
if (x > 0 || len == -1) {
let xContext = 0;
let n = 0;
let n = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we document some of the magic:

  • why n = 1
  • why l.781 adjusts rec.ContextEx.Index + 1 below?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was an off-by-one error in the use of the ContextChar function where there were prefix tests in the context (if, nul, etc). Adjusting n to 1 here resolves the issue. Similar resolution for rec.ContextEx.Index on L.781.

if(&platform = 'web') notany(c) + 'c' > context 'C'
if(&platform = 'web') notany(d) + 'd' > context(2) 'D'
nul any(e) + 'e' > context 'E'
nul any(f) + 'f' > context(2) 'F'
Copy link
Contributor

Choose a reason for hiding this comment

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

Any value in also testing the combo

+ nul notany(g) + 'g' >  ...?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fun detail: notany(g) can match nul. I'm not 100% on if that holds true here, with nul notany(g), but the Web-side implementation will happily match such a rule in that manner.

Copy link
Contributor

Choose a reason for hiding this comment

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

... and upon re-inspection of the tests that led me to think this, I may have interpreted what I saw wrongly. It has been a while since I worked on that set of unit tests; my apologies for the confusion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any value in also testing the combo

+ nul notany(g) + 'g' >  ...?

I don't think it adds any additional coverage but am happy to add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
3 participants