Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix score holders starting with * #1692

Merged
Merged
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
26 changes: 14 additions & 12 deletions packages/core/src/source/Source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ export class ReadonlySource {
return this.string.slice(this.innerCursor + offset, this.innerCursor + offset + length)
}

canRead(length = 1) {
const needed = this.innerCursor + length
const available = this.string.length
return this.innerCursor + length <= this.string.length
}

canReadInLine() {
return this.canRead() && this.peek() !== CR && this.peek() !== LF
}

/**
* If the `expectedValue` is right after the cursor, returns `true`. Otherwise returns `false`.
*
Expand Down Expand Up @@ -109,12 +119,12 @@ export class ReadonlySource {
return this.peekUntil(CR, LF)
}

peekRemaining(): string {
return this.string.slice(this.innerCursor)
peekRemaining(offset = 0): string {
return this.string.slice(this.innerCursor + offset)
}

matchPattern(regex: RegExp): boolean {
return regex.test(this.peekRemaining())
matchPattern(regex: RegExp, offset = 0): boolean {
return regex.test(this.peekRemaining(offset))
}

/**
Expand Down Expand Up @@ -172,14 +182,6 @@ export class Source extends ReadonlySource {
return ans
}

canRead(length = 1) {
return this.innerCursor + length <= this.string.length
}

canReadInLine() {
return this.canRead() && this.peek() !== CR && this.peek() !== LF
}

read() {
return this.string.charAt(this.innerCursor++)
}
Expand Down
1 change: 1 addition & 0 deletions packages/java-edition/src/mcfunction/completer/argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ const scoreHolder: Completer<ScoreHolderNode> = (node, ctx) => {
ctx,
)
ans.push(
...completer.literal(LiteralNode.mock(node, { pool: ['*'] }), ctx),
...selector(
EntitySelectorNode.mock(node, { pool: EntitySelectorAtVariable.filterAvailable(ctx) }),
ctx,
Expand Down
8 changes: 6 additions & 2 deletions packages/java-edition/src/mcfunction/parser/argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1406,8 +1406,12 @@ export function scoreHolder(
): core.Parser<ScoreHolderNode> {
return core.map<core.LiteralNode | core.SymbolNode | EntitySelectorNode, ScoreHolderNode>(
core.select([
// Technically score holders can start with *, but this doesn't account for it
{ prefix: '*', parser: core.literal('*') },
{
predicate: (src) =>
src.peek() === '*'
&& (!src.canRead(2) || src.matchPattern(/^\s/, 1)),
parser: core.literal('*'),
},
{ prefix: '@', parser: selector() },
{ parser: scoreHolderFakeName(usageType) },
]),
Expand Down
Loading