diff --git a/packages/java-edition/src/mcfunction/parser/argument.ts b/packages/java-edition/src/mcfunction/parser/argument.ts index 2655b8eed..a0c93a5b4 100644 --- a/packages/java-edition/src/mcfunction/parser/argument.ts +++ b/packages/java-edition/src/mcfunction/parser/argument.ts @@ -337,7 +337,7 @@ function block(isPredicate: boolean): core.InfallibleParser { const blockState: core.InfallibleParser = block(false) export const blockPredicate: core.InfallibleParser = block(true) -export const component = json.parser.json() +export const component = json.parser.json function double( min = DoubleMin, diff --git a/packages/json/src/parser/array.ts b/packages/json/src/parser/array.ts index 5f1d73fd9..391da91a0 100644 --- a/packages/json/src/parser/array.ts +++ b/packages/json/src/parser/array.ts @@ -5,7 +5,7 @@ import { json } from './entry.js' export const array: core.Parser = (src, ctx) => { const parser = core.list({ start: '[', - value: json(), + value: json, sep: ',', trailingSep: false, end: ']', diff --git a/packages/json/src/parser/entry.ts b/packages/json/src/parser/entry.ts index 9b9458810..1975ea356 100644 --- a/packages/json/src/parser/entry.ts +++ b/packages/json/src/parser/entry.ts @@ -20,7 +20,7 @@ const LegalNumberStart = new Set([ '9', '-', ]) -export function json(dumpErrors = false): core.Parser { +function jsonParser(dumpErrors: boolean): core.Parser { return (src, ctx) => { const result = core.select([ { predicate: (src) => src.tryPeek('['), parser: array }, @@ -44,4 +44,19 @@ export function json(dumpErrors = false): core.Parser { } } -export const entry: core.Parser = json(true) +/** + * A JSON parser that dumps any parser errors after it finishes parsing. + * This should be used when it is the root parser, e.g. for this package's + * initialization method (the JSON package). + */ +export const entry = jsonParser(true) + +/** + * A JSON parser that doesn't dump parser errors after it finishes parsing. + * This should be used when it is a child parser under another parent parser, + * e.g. in the JSON `array` parser. + * + * Since this parser doesn't dump its errors when it's done, those errors + * should be subsequently absorbed by the parent parser's `ParserContext`. + */ +export const json = jsonParser(false) diff --git a/packages/json/src/parser/object.ts b/packages/json/src/parser/object.ts index b0edc603b..810b2609f 100644 --- a/packages/json/src/parser/object.ts +++ b/packages/json/src/parser/object.ts @@ -11,7 +11,7 @@ export const object: core.InfallibleParser = (src, ctx) => { pair: { key: string, sep: ':', - value: json(), + value: json, end: ',', trailingEnd: false, },