Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion packages/svs/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export function parseSvs(sourceName: string, source: string): ParsedSvsSheet {
if (openEnd < 0) fail(sourceName, "SVS_ROOT", "Opening <sheet> is not closed.", cursor);
const attributes = parseAttributes(sourceName, text.slice(cursor + 6, openEnd), cursor + 6);
cursor = openEnd + 1;
const close = text.indexOf("</sheet>", cursor);
const close = text.lastIndexOf("</sheet>");
if (close < 0) fail(sourceName, "SVS_ROOT_UNCLOSED", "Source is missing </sheet>.", source.length);
if (text.slice(close + "</sheet>".length).trim().length > 0) {
fail(sourceName, "SVS_TRAILING", "Only trivia may follow </sheet>.", close + "</sheet>".length);
Expand Down
9 changes: 9 additions & 0 deletions packages/svs/test/source-closure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,15 @@ test("quoted Recipe values may contain Prompt punctuation without changing SVS s
assert.equal(sheet.recipes[0]?.value.properties.text, "first; second } /* literal */");
});

test("quoted Recipe text may contain a sheet closing tag", () => {
const prompt = "Show a literal </sheet> tag in the output";
const source = `<sheet version="1">demo.prompt { text: ${formatSvsValue(prompt)}; }</sheet>`;
const sheet = parseSvs("prompt.svs", source);
assert.equal(sheet.recipes[0]?.value.properties.text, prompt);
assert.throws(() => parseSvs("trailing.svs", `${source} extra`),
(error: unknown) => error instanceof SvsSyntaxError && error.code === "SVS_TRAILING");
});

test("SVS parses and serializes canonical arrays and objects as one Recipe value", () => {
const source = `<sheet version="1">
ranking.column {
Expand Down
14 changes: 13 additions & 1 deletion packages/text/test/text.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from "node:assert/strict";
import test from "node:test";
import { parseStructuredElement } from "@hypit/markup";
import type { SurfaceResolvedReference } from "@hypit/markup";
import { svsRecipeType } from "@hypit/svs";
import { formatSvsValue, parseSvs, svsRecipeType } from "@hypit/svs";

import {
bindText,
Expand All @@ -15,9 +15,21 @@ import {
sealTextBindings,
sealTextTemplate,
textTypes,
textTemplateFromSvsRecipes,
verifyTextTemplate,
} from "@hypit/text";

test("Text Templates keep a sheet closing tag in prompt text", () => {
const prompt = "Show the literal </sheet> tag in the video";
const source = `<sheet version="1">
text-template.demo {}
text-template.demo.block.example { kind: fixed; order: 0; text: ${formatSvsValue(prompt)}; }
</sheet>`;
const recipes = parseSvs("template.svs", source).recipes.map((recipe) => recipe.value);
const template = textTemplateFromSvsRecipes(recipes, "demo");
assert.equal(renderText(template, sealTextBindings({})).value, prompt);
});

test("text programs compose nested templates, choices, lists and transforms", () => {
const template = sealTextTemplate({

Expand Down