Skip to content

Commit

Permalink
add backslash continuation to command parser
Browse files Browse the repository at this point in the history
- add space char ` ` as a terminator to improve performance (needed to pass test)
  • Loading branch information
TheAfroOfDoom committed May 19, 2024
1 parent c9ebc24 commit 5b41b76
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 3 deletions.
162 changes: 162 additions & 0 deletions __snapshots__/packages/mcfunction/test-out/parser/command.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions packages/mcfunction/src/parser/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ function dispatch(
parser: argument(treeNode) ?? unknown(treeNode),
}))
const literalParser = literalTreeNodes.length
? literal(
literalTreeNodes.map(([name, _treeNode]) => name),
parent.type === 'root',
? core.concatOnTrailingBackslash(
literal(
literalTreeNodes.map(([name, _treeNode]) => name),
parent.type === 'root',
),
[' ', '\n', '\r'],
)
: undefined

Expand Down
3 changes: 3 additions & 0 deletions packages/mcfunction/test/parser/command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ describe('mcfunction parser command()', () => {
{ content: 'say hi ' },
{ content: 'say hi garbage text' },
{ content: 'execute if true if true run say hi' },
{ content: 'sa\\\ny hi' },
{ content: 'sa\\ \n y hi' },
{ content: 'sa\\ \n y h\\ \n i' },
]
for (const { content } of cases) {
it(`Parse "${showWhitespaceGlyph(content)}"`, () => {
Expand Down

0 comments on commit 5b41b76

Please sign in to comment.