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(web): feature-gestures master merge (end of A17S18) 🐵 #9418

Merged
merged 119 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
bc378dc
feat(core): move transform processing to u32 🙀
srl295 Jul 19, 2023
9fc6279
feat(core): transform/reorder processing a little less broken 🙀
srl295 Jul 19, 2023
7f07f95
feat(core): transform/reorder passing tests! 🙀
srl295 Jul 19, 2023
c4c5f5e
Merge branch 'master' into feat/core/7375-merge-transform-path-epic-ldml
srl295 Jul 19, 2023
96b11d8
feat(core): transform/reorder passing tests! 🙀
srl295 Jul 19, 2023
8f72f61
chore(deps-dev): bump word-wrap from 1.2.3 to 1.2.4
dependabot[bot] Jul 20, 2023
ac6dbb6
chore(core): scale back kmxplus debugging 🙀
srl295 Jul 20, 2023
4d9fd28
feat(core): fix UMR in Uset 🙀
srl295 Jul 21, 2023
78a5879
feat(core): fix testing string 🙀
srl295 Jul 21, 2023
f88ffbf
chore(core): improve validity check on transform 🙀
srl295 Jul 21, 2023
11d5a42
auto: increment master version to 17.0.146
keyman-server Jul 21, 2023
c6102df
Merge pull request #9322 from keymanapp/auto/version-master-17.0.146
keyman-server Jul 21, 2023
9bc27e5
Merge branch 'master' into feat/core/7375-merge-transform-path-epic-ldml
srl295 Jul 21, 2023
fe28c8b
Merge pull request #9314 from keymanapp/dependabot/npm_and_yarn/word-…
mcdurdin Jul 24, 2023
93f05d6
docs(core): Document how to build Core on Linux
ermshiperete Jul 24, 2023
6553be2
auto: increment master version to 17.0.147
keyman-server Jul 24, 2023
f39765b
Merge pull request #9329 from keymanapp/auto/version-master-17.0.147
keyman-server Jul 24, 2023
168a98d
chore(linux): Update debian changelog
ermshiperete Jul 24, 2023
a054137
Merge pull request #9327 from keymanapp/chore/linux/cherry-pick/chang…
ermshiperete Jul 25, 2023
a97a966
chore(linux): Update supported Ubuntu versions
ermshiperete Jul 25, 2023
77895ad
auto: increment master version to 17.0.148
keyman-server Jul 25, 2023
5930cca
Merge pull request #9343 from keymanapp/auto/version-master-17.0.148
keyman-server Jul 25, 2023
0a2aa6c
Apply suggestions from code review
srl295 Jul 25, 2023
84dc28f
feat(core): transform/reorder 🙀
srl295 Jul 25, 2023
2f38127
chore(developer): make unknown vkey a hint, not error 🙀
srl295 Jul 25, 2023
7ee574b
chore(developer): make unknown vkey a hint, not error 🙀
srl295 Jul 25, 2023
352328f
fix(core): Better range check for Uni_IsValid() 🙀
srl295 Jul 25, 2023
480fd3b
fix(core): More range checks for Uni_IsValid() 🙀
srl295 Jul 26, 2023
a8b8c3d
Merge pull request #9293 from keymanapp/feat/core/7375-merge-transfor…
srl295 Jul 26, 2023
08787ea
Merge pull request #9344 from keymanapp/chore/developer-9236-vkey-war…
srl295 Jul 26, 2023
f57c66e
Merge branch 'master' into fix/core/7375-verify-uset-range-epic-ldml
srl295 Jul 26, 2023
97b3120
fix(core): Optimize checks for Uni_IsValid() 🙀
srl295 Jul 26, 2023
875d599
chore(core): update documentation in transform logic and processor 🙀
srl295 Jul 26, 2023
99c2aff
chore(core): turn off debugging 🙀
srl295 Jul 26, 2023
f2915bb
spec(core): update marker spec 🙀
srl295 Jul 26, 2023
0c7ad2c
feat(developer): Marker tests 🙀
srl295 Jul 26, 2023
ab4a0f3
feat(developer): Marker tests 🙀
srl295 Jul 26, 2023
8b4d5b4
Merge pull request #9341 from keymanapp/chore/linux/kineticmantic
ermshiperete Jul 27, 2023
b71b350
auto: increment master version to 17.0.149
keyman-server Jul 27, 2023
64e1d13
Merge pull request #9361 from keymanapp/auto/version-master-17.0.149
keyman-server Jul 27, 2023
b4c074a
chore(linux): Fix creation of PRs after uploading to Debian
ermshiperete Jul 27, 2023
c4720a0
chore(linux): Update debian changelog
ermshiperete Jul 27, 2023
4854cba
feat(developer): fix marker validation test 🙀
srl295 Jul 29, 2023
ccc86a9
feat(core): fix uset range check 🙀
srl295 Jul 29, 2023
c7881d9
Update core/src/ldml/ldml_processor.cpp
srl295 Jul 29, 2023
52e5439
feat(developer): marker accounting 🙀
srl295 Jul 29, 2023
9988662
feat(developer): marker accounting 🙀
srl295 Jul 29, 2023
7ad3f95
Merge branch 'chore/core/7375-reorder-comments-epic-ldml' into feat/d…
srl295 Jul 29, 2023
581d65a
fix(common): list fix 🙀
srl295 Jul 29, 2023
d514dc9
feat(common): marker processing support 🙀
srl295 Jul 29, 2023
2211900
feat(common): marker - move values into constants 🙀
srl295 Jul 29, 2023
97c8380
feat(common): marker - emit sentinel values 🙀
srl295 Jul 29, 2023
a6bce2d
feat(common): marker - utilities to emit sentinel values 🙀
srl295 Jul 29, 2023
bab4998
Merge pull request #9346 from keymanapp/fix/core/7375-verify-uset-ran…
srl295 Jul 29, 2023
2ec20ae
Merge pull request #9352 from keymanapp/chore/core/7375-reorder-comme…
srl295 Jul 29, 2023
e71e1c1
Merge branch 'master' into feat/developer/9119-marker-epic-ldml
srl295 Jul 29, 2023
c15e1f3
Merge branch 'feat/developer/9119-marker-epic-ldml' into feat/develop…
srl295 Jul 29, 2023
8c79f14
feat(developer): marker - use marker in the sections 🙀
srl295 Jul 29, 2023
1c95435
feat(developer): marker - basic.xml update 🙀
srl295 Jul 29, 2023
0d3ffbb
chore(core): marker - pt-abnt2 broken 🙀
srl295 Jul 30, 2023
0e5fcca
auto: increment master version to 17.0.150
keyman-server Jul 30, 2023
003f196
Merge pull request #9366 from keymanapp/auto/version-master-17.0.150
keyman-server Jul 30, 2023
8a57a17
Merge pull request #9358 from keymanapp/chore/linux/cherry-pick/chang…
ermshiperete Jul 31, 2023
b4e612d
Merge pull request #9360 from keymanapp/chore/linux/uploadScript
ermshiperete Jul 31, 2023
c4efba0
chore(linux): Don't fail on parallel builds
ermshiperete Jul 31, 2023
1d0db59
docs(core): Don't put emscripten on the path
ermshiperete Jul 27, 2023
8c2cd89
fix(developer): fix breakage from emscripten 3.1.44
srl295 Jul 31, 2023
ea14dae
auto: increment master version to 17.0.151
keyman-server Jul 31, 2023
50d0e26
Merge pull request #9372 from keymanapp/auto/version-master-17.0.151
keyman-server Jul 31, 2023
1bb3ae5
fix(developer): more wasm uset fixes 🙀
srl295 Jul 31, 2023
f2fea17
Update developer/src/kmc-ldml/test/fixtures/sections/vars/fail-marker…
srl295 Jul 31, 2023
2fa9e8e
Merge pull request #9364 from keymanapp/feat/developer/9119-marker-ep…
srl295 Jul 31, 2023
b6fade3
Merge pull request #9365 from keymanapp/feat/developer/9119-marker-em…
srl295 Jul 31, 2023
e1d5513
Update developer/src/kmcmplib/src/meson.build
srl295 Aug 1, 2023
781351b
Merge branch 'master' into fix/developer/wasm-epic-ldml
srl295 Aug 1, 2023
51774b6
Apply suggestions from code review
srl295 Aug 1, 2023
f6a64bc
docs(windows): corrected nmake cmd for certificates
rc-swag Aug 1, 2023
4135078
Merge pull request #9368 from keymanapp/chore/linux/waitapt
ermshiperete Aug 1, 2023
b8d0777
chore(linux): Remove package build on Jenkins for Keyman 17
ermshiperete Aug 1, 2023
ecf35b3
docs(windows): Update OS requirement to Windows 10
darcywong00 Aug 1, 2023
1d63b88
Merge pull request #9375 from keymanapp/fix/developer/wasm-epic-ldml
srl295 Aug 1, 2023
5afa3c5
Merge pull request #9328 from keymanapp/docs/core/8913_BuildOnLinux
ermshiperete Aug 1, 2023
00bf3cc
Merge branch 'master' into fix/developer/wasm-more-uset-fix
srl295 Aug 1, 2023
f154c49
docs(linux): Add build doc for Keyman Web and Android
ermshiperete Jul 31, 2023
0ac8b2a
auto: increment master version to 17.0.152
keyman-server Aug 1, 2023
05f6728
Merge pull request #9385 from keymanapp/auto/version-master-17.0.152
keyman-server Aug 1, 2023
50309e9
Merge pull request #9382 from keymanapp/fix/developer/wasm-more-uset-fix
srl295 Aug 1, 2023
de1d8e9
Merge pull request #9376 from keymanapp/docs/windows/create-test-cert…
rc-swag Aug 2, 2023
669198a
chore(linux): touch linux so we get a build
mcdurdin Aug 1, 2023
a010507
chore: add run-name to deb-packaging
mcdurdin Aug 1, 2023
9517883
Merge pull request #9386 from keymanapp/chore/gha-master
mcdurdin Aug 2, 2023
1566c14
chore: try another variable for reporting
mcdurdin Aug 2, 2023
2863bdb
Merge pull request #9388 from keymanapp/chore/gha-pr-2
mcdurdin Aug 2, 2023
bf5b5f6
docs(windows): Clarify OS versions per review comments
darcywong00 Aug 2, 2023
ee12ad4
docs(windows): Remove troubleshooting hidden page
darcywong00 Aug 2, 2023
08f33bb
docs(windows): Remove other references to Win 7
darcywong00 Aug 2, 2023
4ea880b
Apply suggestions from code review
darcywong00 Aug 2, 2023
b5fd394
docs(windows): Address more comments
darcywong00 Aug 2, 2023
f8d4f8e
fix(web): restoring original outputTarget only active due to focus-ma…
jahorton Aug 2, 2023
e37d538
chore(linux): Remove Kinetic from GHA
ermshiperete Aug 2, 2023
48e54b1
Merge pull request #9380 from keymanapp/chore/linux/jenkins
ermshiperete Aug 2, 2023
1289a54
chore(linux): Properly treat test builds with packaging GHA
ermshiperete Aug 2, 2023
f5819ad
Update docs/build/linux-ubuntu.md
ermshiperete Aug 2, 2023
9290d2d
Merge pull request #9383 from keymanapp/docs/linux/8913_BuildOnLinux
ermshiperete Aug 2, 2023
323d741
auto: increment master version to 17.0.153
keyman-server Aug 2, 2023
d633de9
Merge pull request #9402 from keymanapp/auto/version-master-17.0.153
keyman-server Aug 2, 2023
985c3ee
Apply suggestions from code review
darcywong00 Aug 2, 2023
3a522a4
Merge pull request #9381 from keymanapp/docs/windows/os-support
darcywong00 Aug 3, 2023
d69d67f
fix(web): forgot to target es5 when minifying polyfilled worker
jahorton Aug 3, 2023
bdff790
chore(web): Apply suggestions from code review
jahorton Aug 3, 2023
11fcac1
Merge pull request #9397 from keymanapp/fix/web/active-target-mainten…
jahorton Aug 3, 2023
19fef7f
Merge pull request #9399 from keymanapp/chore/linux/gha
ermshiperete Aug 3, 2023
ca1c15c
chore(common): Update crowdin GHA to trigger daily
darcywong00 Aug 3, 2023
464f702
Merge pull request #9400 from keymanapp/chore/linux/gha-environment
ermshiperete Aug 3, 2023
4ff375c
auto: increment master version to 17.0.154
keyman-server Aug 3, 2023
a211dd0
Merge pull request #9414 from keymanapp/auto/version-master-17.0.154
keyman-server Aug 3, 2023
1127071
Merge pull request #9410 from keymanapp/chore/gha-crowdin-daily
darcywong00 Aug 3, 2023
9bd12cb
Merge pull request #9409 from keymanapp/fix/web/lm-worker-es5-minific…
jahorton Aug 4, 2023
fa16bbf
chore: Merge branch 'master' into chore/feature-gestures-a17s18-maste…
jahorton Aug 4, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Upload translation sources to Crowdin translate.keyman.com

on:
schedule:
# At 06:00 every two weeks
- cron: '0 6 1,15 * *'
# At 06:00 every day. https://crontab.cronhub.io/
- cron: '0 6 * * *'

jobs:
upload-sources-to-crowdin:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/deb-packaging.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: "Ubuntu packaging"
run-name: "Ubuntu packaging - ${{ github.event.client_payload.branch }} (branch ${{ github.head_ref }}), by @${{ github.actor }}"
on:
repository_dispatch:
types: ['deb-release-packaging:*', 'deb-pr-packaging:*']
Expand All @@ -17,6 +18,8 @@ jobs:
VERSION: ${{ steps.version_step.outputs.VERSION }}
PRERELEASE_TAG: ${{ steps.prerelease_tag.outputs.PRERELEASE_TAG }}
GIT_SHA: ${{ steps.set_status.outputs.GIT_SHA }}
GHA_TEST_BUILD: ${{ github.event.client_payload.isTestBuild }}
GHA_BRANCH: ${{ github.event.client_payload.branch }}
steps:
- name: Checkout
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c #v3.3.0
Expand Down Expand Up @@ -102,7 +105,10 @@ jobs:
strategy:
fail-fast: true
matrix:
dist: [focal, jammy, kinetic, lunar]
# Currently not building mantic until ibus version on mantic stabilizied
# and we can provide a patched version
# dist: [focal, jammy, lunar, mantic]
dist: [focal, jammy, lunar]
arch: [amd64]

runs-on: ubuntu-latest
Expand Down
55 changes: 55 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
# Keyman Version History

## 17.0.153 alpha 2023-08-03

* docs(windows): Update OS requirement to Windows 10 (#9381)
* fix(web): maintenance of focus when changing keyboard via Toolbar UI (#9397)
* chore(linux): Remove Kinetic from GHA (#9399)
* chore(linux): Properly treat test builds with packaging GHA (#9400)

## 17.0.152 alpha 2023-08-02

* fix(developer): more wasm uset fixes (#9382)
* docs(windows): corrected nmake cmd for certificates (#9376)
* chore: add run-name to deb-packaging (#9386)
* chore: try another variable for reporting (#9388)
* chore(linux): Remove package build on Jenkins for Keyman 17 (#9380)
* docs(linux): Add build doc for Keyman Web and Android (#9383)

## 17.0.151 alpha 2023-08-01

* feat(developer) marker steps (#9364)
* feat(common): marker processing (#9365)
* chore(linux): Don't fail on parallel builds (#9368)
* fix(developer): fix breakage from emscripten 3.1.44 (#9375)
* docs(core): Document how to build Core on Linux (#9328)

## 17.0.150 alpha 2023-07-31

* chore(linux): Update debian changelog (#9358)
* chore(linux): Fix creation of PRs after uploading to Debian (#9360)

## 17.0.149 alpha 2023-07-30

* fix(core): Better range check for Uni_IsValid() (#9346)
* chore(core): update documentation in transform logic and processor (#9352)

## 17.0.148 alpha 2023-07-27

* feat(core): merge transform/reorder processing w/ u32 (#9293)
* chore(developer): make unknown vkey a hint, not error (#9344)
* chore(linux): Update supported Ubuntu versions (#9341)

## 17.0.147 alpha 2023-07-25

* chore(linux): Update debian changelog (#9327)

## 17.0.146 alpha 2023-07-24

* chore(deps-dev): bump word-wrap from 1.2.3 to 1.2.4 (#9314)

## 17.0.145 alpha 2023-07-21

* fix(linux): Fix logging (#9310)
* fix(windows): open pdf in an external browser (#9295)
* fix(linux): Fix installation of keyboards with lang tag `mul` (#9027)
* fix(web): allows registering precached keyboards (#9304)

## 17.0.144 alpha 2023-07-20

* refactor(linux): Use better way to get username (#9313)
Expand Down
2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
17.0.145
17.0.154
1 change: 1 addition & 0 deletions common/web/lm-worker/build-wrap-and-minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if(MINIFY) {
sourcesContent: DEBUG,
minify: true,
keepNames: true,
target: 'es5',
outfile: `build/lib/worker-main.polyfilled.min.js`
});
}
Expand Down
3 changes: 3 additions & 0 deletions common/web/types/src/kmx/kmx-plus-builder/build-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export function build_list(source_list: List, sect_strs: BUILDER_STRS): BUILDER_
* @returns
*/
export function build_list_index(sect_list: BUILDER_LIST, value: ListItem) : BUILDER_LIST_REF {
if (!value) {
return 0; // empty list
}
if(!(value instanceof ListItem)) {
throw new Error('unexpected value '+ value);
}
Expand Down
6 changes: 3 additions & 3 deletions common/web/types/src/kmx/kmx-plus-builder/build-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { constants } from "@keymanapp/ldml-keyboard-constants";
import { KMXPlusData } from "../kmx-plus.js";
import { build_strs_index, BUILDER_STR_REF, BUILDER_STRS } from "./build-strs.js";
import { BUILDER_SECTION } from "./builder-section.js";
import { BUILDER_LIST_REF } from "./build-list.js";
import { build_list_index, BUILDER_LIST, BUILDER_LIST_REF } from "./build-list.js";
import { build_elem_index, BUILDER_ELEM, BUILDER_ELEM_REF } from "./build-elem.js";


Expand All @@ -22,7 +22,7 @@ export interface BUILDER_VARS extends BUILDER_SECTION {
/**
* Builder for the 'vars' section
*/
export function build_vars(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_elem: BUILDER_ELEM) : BUILDER_VARS {
export function build_vars(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_elem: BUILDER_ELEM, sect_list: BUILDER_LIST) : BUILDER_VARS {
if(!kmxplus.vars) {
return null;
}
Expand All @@ -49,7 +49,7 @@ export function build_vars(kmxplus: KMXPlusData, sect_strs: BUILDER_STRS, sect_e
size: constants.length_vars +
(constants.length_vars_item * kmxplus.vars.totalCount()),
_offset: 0,
markers: 0,
markers: build_list_index(sect_list, kmxplus.vars.markers),
varCount: kmxplus.vars.totalCount(),
varEntries: [
...stringVars,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default class KMXPlusBuilder {
this.sect.name = build_name(this.file.kmxplus, this.sect.strs);
this.sect.tran = build_tran(this.file.kmxplus.tran, this.sect.strs, this.sect.elem);
this.sect.uset = build_uset(this.file.kmxplus, this.sect.strs);
this.sect.vars = build_vars(this.file.kmxplus, this.sect.strs, this.sect.elem);
this.sect.vars = build_vars(this.file.kmxplus, this.sect.strs, this.sect.elem, this.sect.list);
this.sect.vkey = build_vkey(this.file.kmxplus);

// Finalize the sect (index) section
Expand Down
4 changes: 4 additions & 0 deletions common/web/types/src/kmx/kmx-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isOneChar, toOneChar, unescapeString } from '../util/util.js';
import { KMXFile } from './kmx.js';
import { UnicodeSetParser, UnicodeSet } from '@keymanapp/common-types';
import { VariableParser } from '../ldml-keyboard/pattern-parser.js';
import { MarkerParser } from '../ldml-keyboard/pattern-parser.js';

// Implementation of file structures from /core/src/ldml/C7043_ldml.md
// Writer in kmx-builder.ts
Expand Down Expand Up @@ -292,6 +293,9 @@ export class Vars extends Section {
return v[0];
}
}
substituteMarkerString(s : string) : string {
return MarkerParser.toSentinelString(s, this.markers);
}
};

/**
Expand Down
13 changes: 11 additions & 2 deletions common/web/types/src/kmx/string-list.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OrderedStringList } from 'src/ldml-keyboard/pattern-parser.js';
import { Strs, StrsItem } from './kmx-plus.js';

/**
Expand All @@ -22,7 +23,7 @@ export class ListIndex {
* A string list in memory. This will be replaced with an index
* into the string table at finalization.
*/
export class ListItem extends Array<ListIndex> {
export class ListItem extends Array<ListIndex> implements OrderedStringList {
/**
* Construct a new list from an array of strings.
* Use List. This is meant to be called by the List.allocString*() functions.
Expand All @@ -41,6 +42,9 @@ export class ListItem extends Array<ListIndex> {
this.push(index);
}
}
getItemOrder(item: string): number {
return this.findIndex(({value}) => value.value === item);
}
isEqual(a: ListItem | string[]): boolean {
if (a.length != this.length) {
return false;
Expand Down Expand Up @@ -68,7 +72,12 @@ export class ListItem extends Array<ListIndex> {
return 0;
}
}
/** for debugging, print as single string */
toString(): string {
return this.map(v => v.value.value).join(' ');
return this.toStringArray().join(' ');
}
/** for debugging, map to string array */
toStringArray(): string[] {
return this.map(v => v.value.value);
}
};
58 changes: 58 additions & 0 deletions common/web/types/src/ldml-keyboard/pattern-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Utilities for transform and marker processing
*/

import { constants } from "@keymanapp/ldml-keyboard-constants";
import { MATCH_QUAD_ESCAPE, isOneChar, unescapeOneQuadString, unescapeString } from "../util/util.js";


Expand All @@ -21,6 +22,12 @@ function matchArray(str: string, match: RegExp) : string[] {
*/
const COMMON_ID = /^[0-9A-Za-z_]{1,32}$/;

/** for use with markers, means an ordering can be determined */
export interface OrderedStringList {
/** @returns the ordering of an item (0..), or -1 if not found */
getItemOrder(item : string) : number;
}

/**
* Class for helping with markers
*/
Expand All @@ -40,6 +47,25 @@ export class MarkerParser {
*/
public static readonly ANY_MARKER_ID = '.';

/**
* Marker sentinel as a string - U+FFFF
*/
public static readonly SENTINEL = String.fromCodePoint(constants.marker_sentinel);

/**
* Matches all markers.
*/
public static readonly SENTINEL_ALL_MARKERS = this.SENTINEL + this.SENTINEL;

/** Minimum ID (trailing code unit) */
public static readonly MIN_MARKER_INDEX = constants.marker_min_index;
/** Index meaning 'any marker' == `\m{.}` */
public static readonly ANY_MARKER_INDEX = constants.marker_any_index;
/** Maximum usable marker index */
public static readonly MAX_MARKER_INDEX = constants.marker_max_index;
/** Max count of markers */
public static readonly MAX_MARKER_COUNT = constants.marker_max_count;

/**
* Pattern for matching a marker reference, OR the special marker \m{.}
*/
Expand All @@ -51,8 +77,40 @@ export class MarkerParser {
* @returns `[]` or an array of all markers referenced
*/
public static allReferences(str: string): string[] {
if (!str) {
return [];
}
return matchArray(str, this.REFERENCE);
}

/** @returns string for marker #n */
public static markerOutput(n: number): string {
if (n < MarkerParser.MIN_MARKER_INDEX || n > MarkerParser.ANY_MARKER_INDEX) {
throw RangeError(`Internal Error: marker index out of range ${n}`);
}
return this.SENTINEL + String.fromCharCode(n);
}

/** @returns all marker strings as sentinel values */
public static toSentinelString(s: string, markers?: OrderedStringList) : string {
if (!s) return s;
return s.replaceAll(this.REFERENCE, (sub, arg) => {
if (arg === MarkerParser.ANY_MARKER_ID) {
return MarkerParser.SENTINEL_ALL_MARKERS;
}
if (!markers) {
throw RangeError(`Internal Error: Could not find marker \\m{${arg}} (no markers defined)`);
}
const order = markers.getItemOrder(arg);
if (order === -1) {
throw RangeError(`Internal Error: Could not find marker \\m{${arg}}`);
} else if(order >= MarkerParser.MAX_MARKER_INDEX) {
throw RangeError(`Internal Error: marker \\m{${arg}} has out of range index ${order}`);
} else {
return MarkerParser.markerOutput(order+1);
}
});
}
}

/**
Expand Down
53 changes: 52 additions & 1 deletion common/web/types/test/ldml-keyboard/test-pattern-parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'mocha';
import { assert } from 'chai';
import { ElementParser, ElementSegment, ElementType, MarkerParser, VariableParser } from '../../src/ldml-keyboard/pattern-parser.js';
import { ElementParser, ElementSegment, ElementType, MarkerParser, OrderedStringList, VariableParser } from '../../src/ldml-keyboard/pattern-parser.js';

describe('Test of Pattern Parsers', () => {
describe('should test MarkerParser', () => {
Expand Down Expand Up @@ -51,6 +51,57 @@ describe('Test of Pattern Parsers', () => {
assert.deepEqual(MarkerParser.allReferences(str), [], `expected no markers: ${str}`);
}
});
it('should be able to emit sentinel values', () => {
assert.equal(MarkerParser.markerOutput(295), '\uFFFF\u0127', 'Wrong sentinel value emitted');
assert.equal(MarkerParser.markerOutput(MarkerParser.ANY_MARKER_INDEX), MarkerParser.SENTINEL_ALL_MARKERS, 'Wrong sentinel value emitted for ffff');
assert.throws(() => MarkerParser.markerOutput(0)); // below MIN
assert.throws(() => MarkerParser.markerOutput(0x10000)); // above MAX
});
it('should be able to output sentinel strings', () => {
// with nothing (no markers)
assert.equal(
MarkerParser.toSentinelString(`No markers here!`),
`No markers here!`
);
assert.throws(() =>
MarkerParser.toSentinelString(`Marker \\m{sorryNoMarkers}`)
);
// with a custom class
class MyMarkers implements OrderedStringList {
getItemOrder(item: string): number {
const m : any = {
'a': 0,
'b': 1,
'c': 2,
'zzz': 0x2FFFFF,
};
const o = m[item];
if (o === undefined) return -1;
return o;
}
};
const markers = new MyMarkers();
assert.equal(MarkerParser.toSentinelString(
`No markers here!`, markers),
`No markers here!`
);
assert.equal(MarkerParser.toSentinelString(
`Give me \\m{a} and \\m{c}, or \\m{.}.`, markers),
`Give me \uFFFF\u0001 and \uFFFF\u0003, or \uFFFF\uFFFF.`
);
assert.throws(() =>
MarkerParser.toSentinelString(
`Want to see something funny? \\m{zzz}`, // out of range
markers
)
);
assert.throws(() =>
MarkerParser.toSentinelString(
`Want to see something sad? \\m{nothing}`, // non existent
markers
)
);
});
});
describe('should test VariableParser', () => {
// same test as for markers
Expand Down
5 changes: 5 additions & 0 deletions core/include/ldml/keyboardprocessor_ldml.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
#define LDML_LENGTH_VARS_ITEM 0x10
#define LDML_LENGTH_VKEY 0xC
#define LDML_LENGTH_VKEY_ITEM 0x8
#define LDML_MARKER_ANY_INDEX 0xFFFF
#define LDML_MARKER_MAX_COUNT 0xFFFD
#define LDML_MARKER_MAX_INDEX 0xFFFE
#define LDML_MARKER_MIN_INDEX 0x1
#define LDML_MARKER_SENTINEL 0xFFFF
#define LDML_META_SETTINGS_FALLBACK_OMIT 0x1
#define LDML_META_SETTINGS_TRANSFORMFAILURE_OMIT 0x2
#define LDML_META_SETTINGS_TRANSFORMPARTIAL_HIDE 0x4
Expand Down
13 changes: 13 additions & 0 deletions core/include/ldml/keyboardprocessor_ldml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,19 @@ class Constants {
}
return chars.join('');
}

// ---- marker stuff ----
/** sentinel value indicating a marker follows */
readonly marker_sentinel = 0xFFFF;
/** minimum usable marker index */
readonly marker_min_index = 0x0001;
/** index value referring to the 'any' marker match */
readonly marker_any_index = 0xFFFF;
/** maximum marker index prior to the 'any' value */
readonly marker_max_index = this.marker_any_index - 1;
/** maximum count of markers (not including 'any') */
readonly marker_max_count = this.marker_max_index - this.marker_min_index;

};

export const constants = new Constants();
Expand Down
Loading