Skip to content
This repository was archived by the owner on Aug 29, 2021. It is now read-only.

Commit 2053e6b

Browse files
bors[bot]Levertion
andcommitted
Merge #125
125: Fix NBT paths r=Levertion a=Levertion @MrYurihi? Fixes #105. Fixes #106. Note that this only filters duplicate errors, and doesn't delete errors which were present in e.g. all but one entity. Co-authored-by: Levertion <[email protected]>
2 parents 0b0789b + a3f0a4c commit 2053e6b

File tree

12 files changed

+759
-9586
lines changed

12 files changed

+759
-9586
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ out
22
node_modules
33
.cache
44
dist/index.map
5+
package-lock.json

.prettierignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
out
21
node_modules
32
.cache
43
dist

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ node_js:
1414
before_install:
1515
- npm install -g npm@6
1616
install:
17-
- npm ci
17+
- npm install
1818
script:
1919
- npm run check
2020
- npm test

dist/index.js

+258-125
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

-9,168
This file was deleted.

src/brigadier/string-reader.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ const EXCEPTIONS = {
5353
)
5454
};
5555

56-
export const QUOTE = '"';
56+
const QUOTE = '"';
57+
const SINGLE_QUOTE = "'";
5758
const ESCAPE = "\\";
5859
export type QuotingKind = "both" | "yes" | RegExp;
5960

@@ -74,8 +75,12 @@ export class StringReader {
7475
quote: true,
7576
unquoted: StringReader.charAllowedInUnquotedString
7677
};
78+
public static isQuotedStringStart(char: string): boolean {
79+
return char === QUOTE || char === SINGLE_QUOTE;
80+
}
7781

7882
private static readonly bools = { true: true, false: false };
83+
7984
public cursor = 0;
8085
public readonly string: string;
8186

@@ -317,7 +322,8 @@ export class StringReader {
317322
if (!this.canRead()) {
318323
return helper.succeed("");
319324
}
320-
if (this.peek() !== QUOTE) {
325+
const terminator = this.peek();
326+
if (!StringReader.isQuotedStringStart(terminator)) {
321327
return helper.fail(
322328
EXCEPTIONS.EXPECTED_START_OF_QUOTE.create(
323329
this.cursor,
@@ -331,7 +337,7 @@ export class StringReader {
331337
this.skip();
332338
const char: string = this.peek();
333339
if (escaped) {
334-
if (char === QUOTE || char === ESCAPE) {
340+
if (char === terminator || char === ESCAPE) {
335341
result += char;
336342
escaped = false;
337343
} else {
@@ -346,15 +352,15 @@ export class StringReader {
346352
}
347353
} else if (char === ESCAPE) {
348354
escaped = true;
349-
} else if (char === QUOTE) {
355+
} else if (char === terminator) {
350356
this.skip();
351357
return helper.succeed(result);
352358
} else {
353359
result += char;
354360
}
355361
}
356362
return helper
357-
.addSuggestion(this.cursor, QUOTE) // Always cannot read at this point
363+
.addSuggestion(this.cursor, terminator) // Always cannot read at this point
358364
.addErrors(
359365
EXCEPTIONS.EXPECTED_END_OF_QUOTE.create(
360366
start,
@@ -371,7 +377,7 @@ export class StringReader {
371377
unquotedRegex: RegExp = StringReader.charAllowedInUnquotedString
372378
): ReturnedInfo<string, CE, string | undefined> {
373379
const helper = new ReturnHelper();
374-
if (this.canRead() && this.peek() === QUOTE) {
380+
if (this.canRead() && StringReader.isQuotedStringStart(this.peek())) {
375381
return helper.return(this.readQuotedString());
376382
} else {
377383
if (!this.canRead()) {

src/data/noncached.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const textComponentSchema =
1818
export async function loadNonCached(): Promise<NonCacheable> {
1919
const schemas: { [key: string]: string } = {
2020
[textComponentSchema]: JSON.stringify(
21-
// FIXME: prettier breaks require.resolve so we need to use plain require to get the correct path
21+
// FIXME: parcel breaks require.resolve so we need to use plain require to get the correct path
2222
// tslint:disable-next-line:no-require-imports
2323
require("minecraft-json-schemas/java/shared/text_component")
2424
)

src/parsers/get-parser.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import * as itemParsers from "./minecraft/item";
1111
import * as listParsers from "./minecraft/lists";
1212
import { messageParser } from "./minecraft/message";
1313
import * as namespaceParsers from "./minecraft/namespace-list";
14-
import { nbtPathParser } from "./minecraft/nbt-path";
14+
import { pathParser } from "./minecraft/nbt-path";
1515
import { nbtParser } from "./minecraft/nbt/nbt";
16-
import { floatRange, intRange } from "./minecraft/range";
16+
import { intRange } from "./minecraft/range";
1717
import { functionParser, resourceParser } from "./minecraft/resources";
1818
import {
1919
criteriaParser,
@@ -43,7 +43,6 @@ const implementedParsers: { [id: string]: Parser } = {
4343
"minecraft:entity": entityParser.entity,
4444
"minecraft:entity_anchor": listParsers.entityAnchorParser,
4545
"minecraft:entity_summon": namespaceParsers.summonParser,
46-
"minecraft:float_range": floatRange,
4746
"minecraft:function": functionParser,
4847
"minecraft:game_profile": entityParser.gameProfile,
4948
"minecraft:int_range": intRange,
@@ -53,11 +52,8 @@ const implementedParsers: { [id: string]: Parser } = {
5352
"minecraft:item_stack": itemParsers.stack,
5453
"minecraft:message": messageParser,
5554
"minecraft:mob_effect": namespaceParsers.mobEffectParser,
56-
"minecraft:nbt": nbtParser,
57-
// TODO: determine if nbt-path is ever used
58-
"minecraft:nbt-path": nbtPathParser,
5955
"minecraft:nbt_compound_tag": nbtParser,
60-
"minecraft:nbt_path": nbtPathParser,
56+
"minecraft:nbt_path": pathParser,
6157
"minecraft:nbt_tag": nbtParser,
6258
"minecraft:objective": objectiveParser,
6359
"minecraft:objective_criteria": criteriaParser,

0 commit comments

Comments
 (0)