From c4e050e1f97b9a4ee7ea2b06ef12ee68bb610fb4 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Wed, 7 Jun 2023 14:14:41 -0500 Subject: [PATCH] =?UTF-8?q?chore(developer):=20boost=20code=20coverage=20?= =?UTF-8?q?=F0=9F=99=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - delete a file which is unused - ordr - delete a file that was moved to common/web/types - pattern-parser - update other lines to increase coverage #7377 --- .../src/kmc-ldml/src/compiler/compiler.ts | 1 + developer/src/kmc-ldml/src/compiler/ordr.ts | 47 ------- .../src/kmc-ldml/src/util/pattern-parser.ts | 116 ------------------ developer/src/kmc-ldml/test/helpers/index.ts | 2 +- 4 files changed, 2 insertions(+), 164 deletions(-) delete mode 100644 developer/src/kmc-ldml/src/compiler/ordr.ts delete mode 100644 developer/src/kmc-ldml/src/util/pattern-parser.ts diff --git a/developer/src/kmc-ldml/src/compiler/compiler.ts b/developer/src/kmc-ldml/src/compiler/compiler.ts index e9d47925e5..44977d0d5e 100644 --- a/developer/src/kmc-ldml/src/compiler/compiler.ts +++ b/developer/src/kmc-ldml/src/compiler/compiler.ts @@ -159,6 +159,7 @@ export class LdmlKeyboardCompiler { Object.keys(constants.section).forEach((sectstr : string) => { const sectid : SectionIdent = constants.section[sectstr]; if (dependencies.has(sectid)) { + /* istanbul ignore if */ if (!kmx.kmxplus[sectid]) { throw new Error(`Internal error: section ${section.id} depends on uninitialized dependency ${sectid}`); } diff --git a/developer/src/kmc-ldml/src/compiler/ordr.ts b/developer/src/kmc-ldml/src/compiler/ordr.ts deleted file mode 100644 index 7264ac985b..0000000000 --- a/developer/src/kmc-ldml/src/compiler/ordr.ts +++ /dev/null @@ -1,47 +0,0 @@ -// import { constants } from "@keymanapp/ldml-keyboard-constants"; -// import { KMXPlus, LDMLKeyboard } from '@keymanapp/common-types'; -// import { SectionCompiler } from "./section-compiler.js"; - -// import DependencySections = KMXPlus.DependencySections; -// // import Ordr = KMXPlus.Ordr; -// // import OrdrItem = KMXPlus.OrdrItem; -// import LKReorder = LDMLKeyboard.LKReorder; -// import LKReorders = LDMLKeyboard.LKReorders; - -// export class OrdrCompiler extends SectionCompiler { - -// public get id() { -// // return constants.section.ordr; -// return null; -// } - -// public validate(): boolean { -// let valid = true; -// // TODO-LDML: linting here should check for identical before+from, but this involves a double-parse which is ugly -// // TODO-LDML: unicodesets means that either we fully parse them and verify conflicting rules or the linting is imperfect -// return valid; -// } - -// private compileReorder(sections: DependencySections, reorder: LKReorder): OrdrItem { -// let result = new OrdrItem(); -// result.elements = sections.elem.allocElementString(sections.strs, reorder.from, reorder.order, reorder.tertiary, reorder.tertiary_base, reorder.prebase); -// result.before = sections.elem.allocElementString(sections.strs, reorder.before); -// return result; -// } - -// private compileReorders(sections: DependencySections, reorders: LKReorders): Ordr { -// let result = new Ordr(); - -// if(reorders?.reorder) { -// for(let reorder of reorders.reorder) { -// result.items.push(this.compileReorder(sections, reorder)); -// } -// } - -// return result; -// } - -// public compile(sections: DependencySections): Ordr { -// return this.compileReorders(sections, this.keyboard.reorders); -// } -// } diff --git a/developer/src/kmc-ldml/src/util/pattern-parser.ts b/developer/src/kmc-ldml/src/util/pattern-parser.ts deleted file mode 100644 index c0c7c459a1..0000000000 --- a/developer/src/kmc-ldml/src/util/pattern-parser.ts +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Utilities for transform and marker processing - */ - - -/** - * Helper function for extracting matched items - * @param str input string - * @param match global RegEx to use - * @returns array of matched values - */ -function matchArray(str: string, match: RegExp) : string[] { - const refs = (str || '').matchAll(match); - return Array.from(refs).map(r => r[1]); -} - -/** - * Class for helping with markers - */ -export class MarkerParser { - /** - * A marker id has the same constraint as a key id. TODO-LDML: Needs to be reflected in the spec - */ - public static readonly ID = /^[0-9A-Za-z_]{1,32}$/; - - /** - * Special marker reference referring to any marker - */ - public static readonly ANY_MARKER = '\\m{.}'; - - /** - * id of the 'any' marker - */ - public static readonly ANY_MARKER_ID = '.'; - - /** - * Pattern for matching a marker reference, OR the special marker \m{.} - */ - public static readonly REFERENCE = /\\m{([0-9A-Za-z_]{1,32}|\.)}/g; - - /** - * parse a string into marker references - * @param str input string such as "\m{a} … \m{.}" - * @returns `[]` or an array of all markers referenced - */ - public static allReferences(str: string): string[] { - return matchArray(str, this.REFERENCE); - } -} - -/** - * Class for helping with markers - */ -export class VariableParser { - /** - * A marker id has the same constraint as a key id. TODO-LDML: Needs to be reflected in the spec - */ - public static readonly ID = /^[0-9A-Za-z_]{1,32}$/; - - /** - * Pattern for matching a string reference `$(str)` - */ - public static readonly STRING_REFERENCE = /\${([0-9A-Za-z_]{1,32})}/g; - - /** - * Pattern for matching a set reference `$[set]` - */ - public static readonly SET_REFERENCE = /\$\[([0-9A-Za-z_]{1,32})\]/g; - - /** - * Pattern for matching a capture set reference `($[set])` - */ - public static readonly CAPTURE_SET_REFERENCE = /\(\$\[([0-9A-Za-z_]{1,32})\]\)/g; - - /** - * `$[1:variable]` - * This regex matches the whole string. - */ - public static readonly MAPPED_SET_REFERENCE = /^\$\[1:([0-9A-Za-z_]{1,32})\]$/; - - /** - * parse a string into references - * @param str input string - * @returns `[]` or an array of all string references referenced - */ - public static allStringReferences(str: string): string[] { - return matchArray(str, this.STRING_REFERENCE); - } - - /** - * parse a string into references - * @param str input string - * @returns `[]` or an array of all string references referenced - */ - public static allSetReferences(str: string): string[] { - return matchArray(str, this.SET_REFERENCE); - } - - /** - * parse a string into references - * @param str input string - * @returns `[]` or an array of all string references referenced - */ - public static allCaptureSetReferences(str: string): string[] { - return matchArray(str, this.CAPTURE_SET_REFERENCE); - } - - /** - * Split an input string into a proper set - * @param str input string - * @returns - */ - public static setSplitter(str: string): string[] { - return str.trim().split(/\s+/); - } -} diff --git a/developer/src/kmc-ldml/test/helpers/index.ts b/developer/src/kmc-ldml/test/helpers/index.ts index 55c53fb284..0592a78e38 100644 --- a/developer/src/kmc-ldml/test/helpers/index.ts +++ b/developer/src/kmc-ldml/test/helpers/index.ts @@ -6,7 +6,7 @@ import * as path from 'path'; import { fileURLToPath } from 'url'; import { SectionCompiler } from '../../src/compiler/section-compiler.js'; import { KMXPlus, LDMLKeyboardXMLSourceFileReader, VisualKeyboard, CompilerEvent, LDMLKeyboardTestDataXMLSourceFile, compilerEventFormat, LDMLKeyboard } from '@keymanapp/common-types'; -import { LdmlKeyboardCompiler } from '../../src/compiler/compiler.js'; +import { LdmlKeyboardCompiler } from '../../src/main.js'; // make sure main.js compiles import { assert } from 'chai'; import { KMXPlusMetadataCompiler } from '../../src/compiler/metadata-compiler.js'; import { CompilerOptions } from '../../src/compiler/compiler-options.js';