Skip to content

Add runtime resource parser + Improve CST resource parser - #471

Draft
eemeli wants to merge 5 commits into
mainfrom
mf-res
Draft

Add runtime resource parser + Improve CST resource parser#471
eemeli wants to merge 5 commits into
mainfrom
mf-res

Conversation

@eemeli

@eemeli eemeli commented Jun 29, 2026

Copy link
Copy Markdown
Member

Filing initially as draft, as this relies on an upstream spec change to allow for empty lines within an entry. Also, I'll likely pile on some more related changes to this PR.

Adds the following new functions to the @messageformat/resource package:

/**
 * Parse input into a tree of MessageFormat instances.
 *
 * The frontmatter locale is required;
 * all other metadata is ignored.
 *
 * @param source - The full source being parsed
 * @param options - The options used for each MessageFormat isntance.
 */
export function parseMessageResource(
  source: string,
  options?: MessageFormatOptions
): MessageResource;
/**
 * Compile a `CST.Resource` value into a tree of MessageFormat instances.
 *
 * @param cst - The previously parsed CST resource
 * @param options - The options used for each MessageFormat isntance.
 */
export function buildMessageResourceFromCST(
  cst: CST.Resource,
  options?: MessageFormatOptions
): MessageResource;

CC @lucacasonato

@eemeli eemeli added the MF2 MessageFormat 2 label Jun 29, 2026
function parseMetadata() {
parseComment();
metadata.lastIndex = pos;
while (metadata.exec(source)) pos = metadata.lastIndex;
pos = valueStart.lastIndex;

valueLine.lastIndex = pos;
const m = valueLine.exec(source);
valueIndent.lastIndex = pos;
if (!valueIndent.test(source)) break;
valueLine.lastIndex = valueIndent.lastIndex;
const m = valueLine.exec(source);
const lineEnd = /[\t ]*\r?\n/y;
function parseLineEnd(context: string) {
lineEnd.lastIndex = pos;
if (lineEnd.exec(source)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MF2 MessageFormat 2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants