Skip to content

Commit

Permalink
⚰️ Remove terminators argument from concat parser
Browse files Browse the repository at this point in the history
- it never stops at specific terminators other than end of string since its called on entry now
  • Loading branch information
TheAfroOfDoom committed May 20, 2024
1 parent 8026277 commit 7f63ab2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
11 changes: 3 additions & 8 deletions packages/core/src/parser/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,6 @@ export function stopBefore<N extends Returnable>(
}

/**
* @param terminators A list of characters the parser will stop at if it finds them
* before a backslash
* @returns A parser that is based on the passed-in `parser`, but concatenates lines
* together when we reach, in order:
* - a backslash
Expand All @@ -518,25 +516,22 @@ export function stopBefore<N extends Returnable>(
*/
export function concatOnTrailingBackslash<N extends Returnable>(
parser: InfallibleParser<N>,
terminators: string[],
): InfallibleParser<N>
export function concatOnTrailingBackslash<N extends Returnable>(
parser: Parser<N>,
terminators: string[],
): Parser<N>
export function concatOnTrailingBackslash<N extends Returnable>(
parser: Parser<N>,
terminators: string[],
): Parser<N> {
return (src, ctx): Result<N> => {
let wrappedStr = src.sliceToCursor(0)
const wrapper = '\\'
const wrappedSrcCursor = wrappedStr.length
const indexMap: IndexMap = []

while (src.canRead() && !terminators.includes(src.peek())) {
wrappedStr += src.readUntil(wrapper, ...terminators)
if (!src.canRead() || terminators.includes(src.peek())) {
while (src.canRead()) {
wrappedStr += src.readUntil(wrapper)
if (!src.canRead()) {
// Stop wrapping `src` if we reach end of file or a terminator before a wrapper
break
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/parser/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('concatOnTrailingBackslash()', () => {
it(
`Parse "${showWhitespaceGlyph(content)}"`,
() => {
const wrappedParser = concatOnTrailingBackslash(parser, ['\n'])
const wrappedParser = concatOnTrailingBackslash(parser)
snapshot(testParser(wrappedParser, content))
},
)
Expand Down
2 changes: 1 addition & 1 deletion packages/mcfunction/src/parser/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ const comment = core.comment({
export const entry = (
commandTreeName: string,
argument: ArgumentParserGetter,
) => core.concatOnTrailingBackslash(mcfunction(commandTreeName, argument), [])
) => core.concatOnTrailingBackslash(mcfunction(commandTreeName, argument))

0 comments on commit 7f63ab2

Please sign in to comment.