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

Commit

Permalink
Merge #125
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bors[bot] and Levertion committed Feb 26, 2019
2 parents 0b0789b + a3f0a4c commit 2053e6b
Show file tree
Hide file tree
Showing 12 changed files with 759 additions and 9,586 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ out
node_modules
.cache
dist/index.map
package-lock.json
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
out
node_modules
.cache
dist
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ node_js:
before_install:
- npm install -g npm@6
install:
- npm ci
- npm install
script:
- npm run check
- npm test
Expand Down
383 changes: 258 additions & 125 deletions dist/index.js

Large diffs are not rendered by default.

9,168 changes: 0 additions & 9,168 deletions package-lock.json

This file was deleted.

18 changes: 12 additions & 6 deletions src/brigadier/string-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const EXCEPTIONS = {
)
};

export const QUOTE = '"';
const QUOTE = '"';
const SINGLE_QUOTE = "'";
const ESCAPE = "\\";
export type QuotingKind = "both" | "yes" | RegExp;

Expand All @@ -74,8 +75,12 @@ export class StringReader {
quote: true,
unquoted: StringReader.charAllowedInUnquotedString
};
public static isQuotedStringStart(char: string): boolean {
return char === QUOTE || char === SINGLE_QUOTE;
}

private static readonly bools = { true: true, false: false };

public cursor = 0;
public readonly string: string;

Expand Down Expand Up @@ -317,7 +322,8 @@ export class StringReader {
if (!this.canRead()) {
return helper.succeed("");
}
if (this.peek() !== QUOTE) {
const terminator = this.peek();
if (!StringReader.isQuotedStringStart(terminator)) {
return helper.fail(
EXCEPTIONS.EXPECTED_START_OF_QUOTE.create(
this.cursor,
Expand All @@ -331,7 +337,7 @@ export class StringReader {
this.skip();
const char: string = this.peek();
if (escaped) {
if (char === QUOTE || char === ESCAPE) {
if (char === terminator || char === ESCAPE) {
result += char;
escaped = false;
} else {
Expand All @@ -346,15 +352,15 @@ export class StringReader {
}
} else if (char === ESCAPE) {
escaped = true;
} else if (char === QUOTE) {
} else if (char === terminator) {
this.skip();
return helper.succeed(result);
} else {
result += char;
}
}
return helper
.addSuggestion(this.cursor, QUOTE) // Always cannot read at this point
.addSuggestion(this.cursor, terminator) // Always cannot read at this point
.addErrors(
EXCEPTIONS.EXPECTED_END_OF_QUOTE.create(
start,
Expand All @@ -371,7 +377,7 @@ export class StringReader {
unquotedRegex: RegExp = StringReader.charAllowedInUnquotedString
): ReturnedInfo<string, CE, string | undefined> {
const helper = new ReturnHelper();
if (this.canRead() && this.peek() === QUOTE) {
if (this.canRead() && StringReader.isQuotedStringStart(this.peek())) {
return helper.return(this.readQuotedString());
} else {
if (!this.canRead()) {
Expand Down
2 changes: 1 addition & 1 deletion src/data/noncached.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const textComponentSchema =
export async function loadNonCached(): Promise<NonCacheable> {
const schemas: { [key: string]: string } = {
[textComponentSchema]: JSON.stringify(
// FIXME: prettier breaks require.resolve so we need to use plain require to get the correct path
// FIXME: parcel breaks require.resolve so we need to use plain require to get the correct path
// tslint:disable-next-line:no-require-imports
require("minecraft-json-schemas/java/shared/text_component")
)
Expand Down
10 changes: 3 additions & 7 deletions src/parsers/get-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import * as itemParsers from "./minecraft/item";
import * as listParsers from "./minecraft/lists";
import { messageParser } from "./minecraft/message";
import * as namespaceParsers from "./minecraft/namespace-list";
import { nbtPathParser } from "./minecraft/nbt-path";
import { pathParser } from "./minecraft/nbt-path";
import { nbtParser } from "./minecraft/nbt/nbt";
import { floatRange, intRange } from "./minecraft/range";
import { intRange } from "./minecraft/range";
import { functionParser, resourceParser } from "./minecraft/resources";
import {
criteriaParser,
Expand Down Expand Up @@ -43,7 +43,6 @@ const implementedParsers: { [id: string]: Parser } = {
"minecraft:entity": entityParser.entity,
"minecraft:entity_anchor": listParsers.entityAnchorParser,
"minecraft:entity_summon": namespaceParsers.summonParser,
"minecraft:float_range": floatRange,
"minecraft:function": functionParser,
"minecraft:game_profile": entityParser.gameProfile,
"minecraft:int_range": intRange,
Expand All @@ -53,11 +52,8 @@ const implementedParsers: { [id: string]: Parser } = {
"minecraft:item_stack": itemParsers.stack,
"minecraft:message": messageParser,
"minecraft:mob_effect": namespaceParsers.mobEffectParser,
"minecraft:nbt": nbtParser,
// TODO: determine if nbt-path is ever used
"minecraft:nbt-path": nbtPathParser,
"minecraft:nbt_compound_tag": nbtParser,
"minecraft:nbt_path": nbtPathParser,
"minecraft:nbt_path": pathParser,
"minecraft:nbt_tag": nbtParser,
"minecraft:objective": objectiveParser,
"minecraft:objective_criteria": criteriaParser,
Expand Down
Loading

0 comments on commit 2053e6b

Please sign in to comment.