Beginner Code Check

Hello Keyman Developers!

I wrote this code below, but it doesn’t seem to work. When I press [K_BKQUOTE] and then one of the keys stored in consonants, I get (for example): `l

What I want is the output: l̩

store (consonants) "lɹmn"
store (syllabicconsonants) "l̩ɹm̩n̩"
[K_BKQUOTE] + any(consonant) > index ( syllabicconsonants, 2 )

Also, this code throws an error if I am trying to compile web or mobile:
CERR_NotSupportedInKeymanWeb
4054

But I don’t get this error when compiling for desktop.

Thanks in advance for your time and patience!

B

It looks like consonants and syllabicconsonants have uneven stores. The stores must be exactly the same length. You probably see “l̩” as one character, but the computer sees it as U+006C U+0329 (el plus dot under).
In your case, the characters you want do exist in precomposed form, so you could change syllabicconsonants to:
store(styllabicconsonants) U+1E37 U+0279 U+1E43 U+1E47

Additionally, your first store is consonants and the rule calls for consonant so make those consistent. It may be that you have a store called consonants AND another called consonant which is why you aren’t getting an error the first time. I’m not sure.

Besides what Lorna mentioned, another syntax issue is you have different open and closing quotes when defining your stores. Both quotes need to be the same, either the ordinary straight quote " or the ordinary apostrophe ’

(Or maybe you had it this way, and the web page is just being “helpful” by changing the quotes to smart quotes).

So, this rule also needs changing:
[K_BKQUOTE] + any(consonant) > index ( syllabicconsonants, 2 )
to
+ [K_BKQUOTE] any(consonants) > index ( syllabicconsonants, 2 )

That’s because the key strokes need to be on the right side of the +. Things on the left of the plus should be context.

Actually, you would need to refer to the character code for the BKQuote, because you have to have the plus sign before the last character pressed, so you cannot use the virtual key for the BKQuote.
This should work:

'`' + any(consonants) > index ( syllabicconsonants, 2 )

(the first three characters is a backquote surrounded by apostrophes, not smart single quotes around a backquote).

There are a few things to think about here. I’m going to summarize the advice that @Lorna and @Steve_White have mentioned above also in this post:

  1. The first part of the rule, before the +, matches characters immediately prior to the insertion point (cursor) in the document. So, as @Steve_White suggested, you could match the backquote as a character already in the document:

    '`' + any(consonant) > index(syllabicconsonants,2)
    
  2. As @lorna mentioned, the syllabicconsonants are multiple codepoints, so you will need to tweak the store for the composed versions. Note on ‘normalization forms’: where Unicode offers a decomposed form of a character, and a composed form, it is generally better to try and use the composed form, as the majority of data out there uses composed forms. Lorna used the Unicode character values to clarify that they were the composed forms in her example; you could also choose to use the characters in string form if you prefer.

    store (consonant) "lɹmn"
    store(styllabicconsonants) U+1E37 U+0279 U+1E43 U+1E47
    '`' + any(consonant) > index (consonant,2)
    
  3. The consonant vs consonants store name typo is an easy fix :grin:

  4. Last, but not least, there is a problem with the ɹ letter in the consonant store. That will never match, as it stands, because there is no ɹ key on the system keyboard layout! So we need a way to type that letter before we can do anything with it. Several ways to solve this; perhaps you want the K_R key to be converted to ɹ when prefixed with BKQUOTE?

    store(consonant) "lrmn"
    

    You may find it clearer to name consonant as consonant_key and use key identifiers instead of characters to clarify that this is the input keystroke:

    store(consonant_key) [K_L] [K_R] [K_M] [K_N]
    store(styllabicconsonant) U+1E37 U+0279 U+1E43 U+1E47
    "`" + any(consonant_key) > index(syllabicconsonant, 2)
    

    If, however, you want another way to type the ɹ letter, perhaps you can describe that, and we can suggest methods to do that.

Hope this helps!


Forum usage note: surround short code snippets with backquote (`) and multi-line code snippets with three backquotes (```) to get code formatting and avoid other formatting side-effects. (I have edited your comment to add this formatting for clarity for future readers.)

Thanks Lorna, Steve and Marc for making me so welcome. I am humbled by your help.

My (full) code now looks like this:

store(&KEYBOARDVERSION) '2.5'
store(&TARGETS) 'web mobile desktop tablet'
store(&NAME) 'ausphonem_2_5'
begin Unicode > use(main)
group(main) using keys
store (consonants) "lmn"
store (syllabicconsonants) "U+1E37 U+1E43 U+1E47"
'`' + any(consonants) > index ( syllabicconsonants, 2 )
+ [SHIFT K_N] > 'ŋ'
+ [SHIFT K_Z] > 'ʒ'
+ [SHIFT K_D] > 'd͡z'
+ [SHIFT K_S] > 'ʃ'
+ [SHIFT K_A] > 'ɑ'
+ [SHIFT K_O] > 'o'
+ [SHIFT K_I] > 'i'
+ [SHIFT K_Y] > 'ð'
+ [SHIFT K_T] > 'tʃ'
+ [SHIFT K_E] > 'ə'
+ [K_C] > 'ʉ'
+ [K_X] > 'ʊ'
+ [K_QUOTE] > 'ʔ'
+ [K_COLON] > 'ː'
+ [K_G] > 'ɡ'
+ [K_A] > 'æ'
+ [K_O] > 'ɔ'
+ [K_I] > 'ɪ'
+ [K_U] > 'ɐ'
+ [K_Y] > 'θ'
+ [K_R] > 'ɹ'
+ [K_Q] > 'ɜ'

And I do want a composed form of ‘Latin small letter r’ (ɹ) + ‘with dot below’ but can’t seem to find it on the internet. As you can see from my code ‘ɹ’ is something my users want to type frequently; but then they may also need to mark it as syllabic with a composed form including a dot below.

The code above compiles green on everything. Cheers!

But no doubt there is something I still don’t understand. When I press the key ‘`’ and then ‘l’ the output is ‘U’. And I’ve been careful to install Word and set my font to Charis SIL (for good luck?). In summary my outputs do this:

[key]` + [key]l = U
[key]` + [key]m = +
[key]` + [key]n = 1

Thanks again for your feedback. Your replies really embody the liberating mission of SIL.

1 Like

If you look carefully, you’ll see that those three characters emitted, when put together, look familiar: U+1 – that is, the start of the string "U+1E37..."! You need to remove the quotes from the U+xxxx string. The line below:

store (syllabicconsonants) "U+1E37 U+1E43 U+1E47"

should be changed to →

store (syllabicconsonants) U+1E37 U+1E43 U+1E47

Because there is no combined form of ‘ɹ’ with dot below, you’ll need to use the combining diacritic mark instead. You can do this with another rule:

'`' + [K_R] > 'ɹ' U+0323

Or, equivalently:

'`' + [K_R] > 'ɹ̣'

Thanks Marc for these suggestions! I’ve now realized I am not dealing with a dot below but rather IPA U+0329.

The code below seems to work great. But perhaps there are some hidden traps? A more elegant way to code it?

store(&TARGETS) 'web mobile desktop tablet'
store(&NAME) 'ausphonem_2_8'
begin Unicode > use(main)
group(main) using keys
'`' + [K_R] > 'ɹ' U+0329
'`' + [K_L] > 'l' U+0329
'`' + [K_M] > 'm' U+0329
'`' + [K_N] > 'n' U+0329
+ [SHIFT K_N] > 'ŋ'
+ [SHIFT K_Z] > 'ʒ'
+ [SHIFT K_D] > 'd͡z'
+ [SHIFT K_S] > 'ʃ'
+ [SHIFT K_A] > 'ɑ'
+ [SHIFT K_O] > 'o'
+ [SHIFT K_I] > 'i'
+ [SHIFT K_Y] > 'ð'
+ [SHIFT K_T] > 'tʃ'
+ [SHIFT K_E] > 'ə'
+ [K_C] > 'ʉ'
+ [K_X] > 'ʊ'
+ [K_QUOTE] > 'ʔ'
+ [K_COLON] > 'ː'
+ [K_G] > 'ɡ'
+ [K_A] > 'æ'
+ [K_O] > 'ɔ'
+ [K_I] > 'ɪ'
+ [K_U] > 'ɐ'
+ [K_Y] > 'θ'
+ [K_R] > 'ɹ'
+ [K_Q] > 'ɜ'
1 Like

You could change these lines:

'`' + [K_R] > 'ɹ' U+0329
'`' + [K_L] > 'l' U+0329
'`' + [K_M] > 'm' U+0329
'`' + [K_N] > 'n' U+0329

to this:

store(K_consonants) "rlmn"
store(U_consonants) U+0279 U+006C U+006D U+006E
'`' + any(K_consonants) > index(U_consonants,2) U+0329

In this case, it only saves you one line of code so it’s not really worth it. But if you end up with a lot of characters needing the syllabic mark it could be useful. It’s also tidier for someone else to pick up the code and understand there’s a relationship with those rules.

Also, totally unrelated, just so you know, the “name” does not have to be the same as the id. You could call it “Ausphonem”. And you definitely do not want the version as part of the name or the id. There’s a separate version statement you should use.

Since desktop + web + mobile covers all the cases, you can use any instead, that is replace:

store(&TARGETS) 'web mobile desktop tablet'

with

store(&TARGETS) 'any'

A more radical change would be to change the rules so that you type the backtick after the base character instead of before it.

Cheers @Ben_Hinton :grin: Glad we can help!

In the same way that @lorna suggested that you can merge the four related '`' rules, you can also merge all the remaining key rules into a single rule with a pair of stores. I’ve just demonstrated with a few rules (spacing is not important, just used for clarity):

store(key) [SHIFT K_N] [SHIFT K_Z] [K_C]
store(out) 'ŋ'         'ʒ'         'ʉ'

+ any(key) > index(out, 1)

Lorna, Steve, Marc and Drow. Thanks! What a brilliant supportive community.

1 Like

It looks like this issue has been resolved with the help provided above. I’ll mark it as Resolved for now. If it’s pending, feel free to reply to this thread and point to what needs further assistance.