From e9fbf137c7a907e1fe4107321399cc4c0ba5019b Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Sun, 6 Aug 2023 02:09:30 -0400 Subject: [PATCH] Fixup types to make TS happy --- src/3x5.ts | 15 +++++++-------- src/notcl.ts | 4 ++-- src/peg.ts | 8 ++++---- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/3x5.ts b/src/3x5.ts index 1c65d70..ed24524 100644 --- a/src/3x5.ts +++ b/src/3x5.ts @@ -32,11 +32,11 @@ type Vm = { }; /** - * @param {Vm} state VM state - * @param {string} code Script to run - * @returns {string} Markup to render / output + * @param state VM state + * @param code Script to run + * @returns Markup to render / output */ -function renderCard(state, code) { +function renderCard(state: Vm, code: string) { const script = parse(code); if (script[0]) { state.output = JSON.stringify(script[1], null, 2); @@ -48,9 +48,8 @@ function renderCard(state, code) { /** * Global state: a single card - * @type {Card} */ -let theCard = { +let theCard: Card = { id: 100, fields: {}, code: String.raw` @@ -100,8 +99,8 @@ const display = document.createElement("blockquote"); const debugDisplay = document.createElement("pre"); function render() { - const vm = { - mode: /** @type {ScriptType} */ "render", + const vm: Vm = { + mode: "render", output: "", }; const html = renderCard(vm, theCard.code); diff --git a/src/notcl.ts b/src/notcl.ts index 6a1730b..51fc2ca 100644 --- a/src/notcl.ts +++ b/src/notcl.ts @@ -1,5 +1,5 @@ import { escapeHtml } from "./helpers"; -import { AtLeast, Choose, End, Regex, Sequence, Use } from "./peg"; +import { AtLeast, Choose, End, Pattern, Regex, Sequence, Use } from "./peg"; export type Word = { text: string; @@ -23,7 +23,7 @@ const BasicWord = Regex(/(?!\{)[^\s;]+/y) // WIP, need to be able to escape braces correctly -const Brace = Sequence( +const Brace: Pattern = Sequence( Regex(/\{/y).expects("{"), AtLeast( 0, diff --git a/src/peg.ts b/src/peg.ts index 8016f9e..3705b7d 100644 --- a/src/peg.ts +++ b/src/peg.ts @@ -74,7 +74,7 @@ export function Use(getPattern: () => Pattern): Pattern { * Creates a pattern matching a regex & returning any captures. The regex needs to be sticky (using the //y modifier) */ export function Regex(regex: RegExp): Pattern { - const pattern = WrapPattern((source, index) => { + const pattern: Pattern = WrapPattern((source, index) => { regex.lastIndex = index; const matches = regex.exec(source); return matches @@ -151,10 +151,10 @@ export function Sequence( * If the given pattern does not consume input, the matching will be terminated to prevent an eternal loop. * * Note that if the minimum run is zero, this pattern will always succeed, but might not consume any input. - * @param {number} min + * @param min */ -export function AtLeast(min, pattern: Pattern): Pattern { +export function AtLeast(min: number, pattern: Pattern): Pattern { return WrapPattern(function (source, index) { const values: T[] = []; let furthestFound = index; @@ -192,6 +192,6 @@ export function End(): Pattern { index, end.expectLabel, ]; - }).expects(""); + }).expects("") as Pattern; return end; }