build: update dist files with named tuple support
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
23ee60bc20
commit
9adce3d45e
|
|
@ -114,13 +114,13 @@ var Parser = class {
|
||||||
this.consume();
|
this.consume();
|
||||||
throw new ParseError("Empty array/tuple not allowed", this.pos);
|
throw new ParseError("Empty array/tuple not allowed", this.pos);
|
||||||
}
|
}
|
||||||
elements.push(this.parseSchema());
|
elements.push(this.parseNamedSchema());
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
if (this.consumeStr(";")) {
|
if (this.consumeStr(";")) {
|
||||||
const remainingElements = [];
|
const remainingElements = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
remainingElements.push(this.parseSchema());
|
remainingElements.push(this.parseNamedSchema());
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
if (!this.consumeStr(";")) {
|
if (!this.consumeStr(";")) {
|
||||||
break;
|
break;
|
||||||
|
|
@ -137,13 +137,13 @@ var Parser = class {
|
||||||
if (!this.consumeStr("]")) {
|
if (!this.consumeStr("]")) {
|
||||||
throw new ParseError("Expected ]", this.pos);
|
throw new ParseError("Expected ]", this.pos);
|
||||||
}
|
}
|
||||||
if (elements.length === 1) {
|
if (elements.length === 1 && !elements[0].name) {
|
||||||
return { type: "array", element: elements[0] };
|
return { type: "array", element: elements[0].schema };
|
||||||
}
|
}
|
||||||
return { type: "array", element: { type: "tuple", elements } };
|
return { type: "array", element: { type: "tuple", elements } };
|
||||||
}
|
}
|
||||||
if (elements.length === 1) {
|
if (elements.length === 1 && !elements[0].name) {
|
||||||
return { type: "array", element: elements[0] };
|
return { type: "array", element: elements[0].schema };
|
||||||
}
|
}
|
||||||
return { type: "tuple", elements };
|
return { type: "tuple", elements };
|
||||||
}
|
}
|
||||||
|
|
@ -163,6 +163,28 @@ var Parser = class {
|
||||||
}
|
}
|
||||||
throw new ParseError(`Unexpected character: ${this.peek()}`, this.pos);
|
throw new ParseError(`Unexpected character: ${this.peek()}`, this.pos);
|
||||||
}
|
}
|
||||||
|
parseNamedSchema() {
|
||||||
|
this.skipWhitespace();
|
||||||
|
const startpos = this.pos;
|
||||||
|
let identifier = "";
|
||||||
|
while (this.pos < this.input.length && /[a-zA-Z0-9\-_]/.test(this.peek())) {
|
||||||
|
identifier += this.consume();
|
||||||
|
}
|
||||||
|
if (identifier.length === 0) {
|
||||||
|
throw new ParseError("Expected schema or named schema", this.pos);
|
||||||
|
}
|
||||||
|
this.skipWhitespace();
|
||||||
|
if (this.consumeStr(":")) {
|
||||||
|
this.skipWhitespace();
|
||||||
|
const name = identifier;
|
||||||
|
const schema = this.parseSchema();
|
||||||
|
return { name, schema };
|
||||||
|
} else {
|
||||||
|
this.pos = startpos;
|
||||||
|
const schema = this.parseSchema();
|
||||||
|
return { schema };
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
function parseSchema(schemaString) {
|
function parseSchema(schemaString) {
|
||||||
const parser = new Parser(schemaString.trim());
|
const parser = new Parser(schemaString.trim());
|
||||||
|
|
@ -270,7 +292,15 @@ var ValueParser = class {
|
||||||
const result = [];
|
const result = [];
|
||||||
for (let i = 0; i < schema.elements.length; i++) {
|
for (let i = 0; i < schema.elements.length; i++) {
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
result.push(this.parseValue(schema.elements[i], false));
|
const elementSchema = schema.elements[i];
|
||||||
|
if (elementSchema.name) {
|
||||||
|
this.skipWhitespace();
|
||||||
|
if (!this.consumeStr(`${elementSchema.name}:`)) {
|
||||||
|
throw new ParseError(`Expected ${elementSchema.name}:`, this.pos);
|
||||||
|
}
|
||||||
|
this.skipWhitespace();
|
||||||
|
}
|
||||||
|
result.push(this.parseValue(elementSchema.schema, false));
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
if (i < schema.elements.length - 1) {
|
if (i < schema.elements.length - 1) {
|
||||||
if (!this.consumeStr(";")) {
|
if (!this.consumeStr(";")) {
|
||||||
|
|
@ -352,7 +382,7 @@ function createValidator(schema) {
|
||||||
if (!Array.isArray(value)) return false;
|
if (!Array.isArray(value)) return false;
|
||||||
if (value.length !== schema.elements.length) return false;
|
if (value.length !== schema.elements.length) return false;
|
||||||
return schema.elements.every(
|
return schema.elements.every(
|
||||||
(elementSchema, index) => createValidator(elementSchema)(value[index])
|
(elementSchema, index) => createValidator(elementSchema.schema)(value[index])
|
||||||
);
|
);
|
||||||
case "array":
|
case "array":
|
||||||
if (!Array.isArray(value)) return false;
|
if (!Array.isArray(value)) return false;
|
||||||
|
|
@ -376,12 +406,12 @@ function schemaToTypeString(schema) {
|
||||||
return "boolean";
|
return "boolean";
|
||||||
case "array":
|
case "array":
|
||||||
if (schema.element.type === "tuple") {
|
if (schema.element.type === "tuple") {
|
||||||
const tupleElements2 = schema.element.elements.map(schemaToTypeString);
|
const tupleElements2 = schema.element.elements.map((el) => schemaToTypeString(el.schema));
|
||||||
return `[${tupleElements2.join(", ")}]`;
|
return `[${tupleElements2.join(", ")}]`;
|
||||||
}
|
}
|
||||||
return `${schemaToTypeString(schema.element)}[]`;
|
return `${schemaToTypeString(schema.element)}[]`;
|
||||||
case "tuple":
|
case "tuple":
|
||||||
const tupleElements = schema.elements.map(schemaToTypeString);
|
const tupleElements = schema.elements.map((el) => schemaToTypeString(el.schema));
|
||||||
return `[${tupleElements.join(", ")}]`;
|
return `[${tupleElements.join(", ")}]`;
|
||||||
default:
|
default:
|
||||||
return "unknown";
|
return "unknown";
|
||||||
|
|
|
||||||
|
|
@ -80,13 +80,13 @@ var Parser = class {
|
||||||
this.consume();
|
this.consume();
|
||||||
throw new ParseError("Empty array/tuple not allowed", this.pos);
|
throw new ParseError("Empty array/tuple not allowed", this.pos);
|
||||||
}
|
}
|
||||||
elements.push(this.parseSchema());
|
elements.push(this.parseNamedSchema());
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
if (this.consumeStr(";")) {
|
if (this.consumeStr(";")) {
|
||||||
const remainingElements = [];
|
const remainingElements = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
remainingElements.push(this.parseSchema());
|
remainingElements.push(this.parseNamedSchema());
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
if (!this.consumeStr(";")) {
|
if (!this.consumeStr(";")) {
|
||||||
break;
|
break;
|
||||||
|
|
@ -103,13 +103,13 @@ var Parser = class {
|
||||||
if (!this.consumeStr("]")) {
|
if (!this.consumeStr("]")) {
|
||||||
throw new ParseError("Expected ]", this.pos);
|
throw new ParseError("Expected ]", this.pos);
|
||||||
}
|
}
|
||||||
if (elements.length === 1) {
|
if (elements.length === 1 && !elements[0].name) {
|
||||||
return { type: "array", element: elements[0] };
|
return { type: "array", element: elements[0].schema };
|
||||||
}
|
}
|
||||||
return { type: "array", element: { type: "tuple", elements } };
|
return { type: "array", element: { type: "tuple", elements } };
|
||||||
}
|
}
|
||||||
if (elements.length === 1) {
|
if (elements.length === 1 && !elements[0].name) {
|
||||||
return { type: "array", element: elements[0] };
|
return { type: "array", element: elements[0].schema };
|
||||||
}
|
}
|
||||||
return { type: "tuple", elements };
|
return { type: "tuple", elements };
|
||||||
}
|
}
|
||||||
|
|
@ -129,6 +129,28 @@ var Parser = class {
|
||||||
}
|
}
|
||||||
throw new ParseError(`Unexpected character: ${this.peek()}`, this.pos);
|
throw new ParseError(`Unexpected character: ${this.peek()}`, this.pos);
|
||||||
}
|
}
|
||||||
|
parseNamedSchema() {
|
||||||
|
this.skipWhitespace();
|
||||||
|
const startpos = this.pos;
|
||||||
|
let identifier = "";
|
||||||
|
while (this.pos < this.input.length && /[a-zA-Z0-9\-_]/.test(this.peek())) {
|
||||||
|
identifier += this.consume();
|
||||||
|
}
|
||||||
|
if (identifier.length === 0) {
|
||||||
|
throw new ParseError("Expected schema or named schema", this.pos);
|
||||||
|
}
|
||||||
|
this.skipWhitespace();
|
||||||
|
if (this.consumeStr(":")) {
|
||||||
|
this.skipWhitespace();
|
||||||
|
const name = identifier;
|
||||||
|
const schema = this.parseSchema();
|
||||||
|
return { name, schema };
|
||||||
|
} else {
|
||||||
|
this.pos = startpos;
|
||||||
|
const schema = this.parseSchema();
|
||||||
|
return { schema };
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
function parseSchema(schemaString) {
|
function parseSchema(schemaString) {
|
||||||
const parser = new Parser(schemaString.trim());
|
const parser = new Parser(schemaString.trim());
|
||||||
|
|
@ -236,7 +258,15 @@ var ValueParser = class {
|
||||||
const result = [];
|
const result = [];
|
||||||
for (let i = 0; i < schema.elements.length; i++) {
|
for (let i = 0; i < schema.elements.length; i++) {
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
result.push(this.parseValue(schema.elements[i], false));
|
const elementSchema = schema.elements[i];
|
||||||
|
if (elementSchema.name) {
|
||||||
|
this.skipWhitespace();
|
||||||
|
if (!this.consumeStr(`${elementSchema.name}:`)) {
|
||||||
|
throw new ParseError(`Expected ${elementSchema.name}:`, this.pos);
|
||||||
|
}
|
||||||
|
this.skipWhitespace();
|
||||||
|
}
|
||||||
|
result.push(this.parseValue(elementSchema.schema, false));
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
if (i < schema.elements.length - 1) {
|
if (i < schema.elements.length - 1) {
|
||||||
if (!this.consumeStr(";")) {
|
if (!this.consumeStr(";")) {
|
||||||
|
|
@ -318,7 +348,7 @@ function createValidator(schema) {
|
||||||
if (!Array.isArray(value)) return false;
|
if (!Array.isArray(value)) return false;
|
||||||
if (value.length !== schema.elements.length) return false;
|
if (value.length !== schema.elements.length) return false;
|
||||||
return schema.elements.every(
|
return schema.elements.every(
|
||||||
(elementSchema, index) => createValidator(elementSchema)(value[index])
|
(elementSchema, index) => createValidator(elementSchema.schema)(value[index])
|
||||||
);
|
);
|
||||||
case "array":
|
case "array":
|
||||||
if (!Array.isArray(value)) return false;
|
if (!Array.isArray(value)) return false;
|
||||||
|
|
@ -342,12 +372,12 @@ function schemaToTypeString(schema) {
|
||||||
return "boolean";
|
return "boolean";
|
||||||
case "array":
|
case "array":
|
||||||
if (schema.element.type === "tuple") {
|
if (schema.element.type === "tuple") {
|
||||||
const tupleElements2 = schema.element.elements.map(schemaToTypeString);
|
const tupleElements2 = schema.element.elements.map((el) => schemaToTypeString(el.schema));
|
||||||
return `[${tupleElements2.join(", ")}]`;
|
return `[${tupleElements2.join(", ")}]`;
|
||||||
}
|
}
|
||||||
return `${schemaToTypeString(schema.element)}[]`;
|
return `${schemaToTypeString(schema.element)}[]`;
|
||||||
case "tuple":
|
case "tuple":
|
||||||
const tupleElements = schema.elements.map(schemaToTypeString);
|
const tupleElements = schema.elements.map((el) => schemaToTypeString(el.schema));
|
||||||
return `[${tupleElements.join(", ")}]`;
|
return `[${tupleElements.join(", ")}]`;
|
||||||
default:
|
default:
|
||||||
return "unknown";
|
return "unknown";
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,13 @@ type SchemaType = 'string' | 'number' | 'boolean';
|
||||||
interface PrimitiveSchema {
|
interface PrimitiveSchema {
|
||||||
type: SchemaType;
|
type: SchemaType;
|
||||||
}
|
}
|
||||||
|
interface NamedSchema {
|
||||||
|
name?: string;
|
||||||
|
schema: Schema;
|
||||||
|
}
|
||||||
interface TupleSchema {
|
interface TupleSchema {
|
||||||
type: 'tuple';
|
type: 'tuple';
|
||||||
elements: Schema[];
|
elements: NamedSchema[];
|
||||||
}
|
}
|
||||||
interface ArraySchema {
|
interface ArraySchema {
|
||||||
type: 'array';
|
type: 'array';
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,13 @@ type SchemaType = 'string' | 'number' | 'boolean';
|
||||||
interface PrimitiveSchema {
|
interface PrimitiveSchema {
|
||||||
type: SchemaType;
|
type: SchemaType;
|
||||||
}
|
}
|
||||||
|
interface NamedSchema {
|
||||||
|
name?: string;
|
||||||
|
schema: Schema;
|
||||||
|
}
|
||||||
interface TupleSchema {
|
interface TupleSchema {
|
||||||
type: 'tuple';
|
type: 'tuple';
|
||||||
elements: Schema[];
|
elements: NamedSchema[];
|
||||||
}
|
}
|
||||||
interface ArraySchema {
|
interface ArraySchema {
|
||||||
type: 'array';
|
type: 'array';
|
||||||
|
|
|
||||||
|
|
@ -107,13 +107,13 @@ var Parser = class {
|
||||||
this.consume();
|
this.consume();
|
||||||
throw new ParseError("Empty array/tuple not allowed", this.pos);
|
throw new ParseError("Empty array/tuple not allowed", this.pos);
|
||||||
}
|
}
|
||||||
elements.push(this.parseSchema());
|
elements.push(this.parseNamedSchema());
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
if (this.consumeStr(";")) {
|
if (this.consumeStr(";")) {
|
||||||
const remainingElements = [];
|
const remainingElements = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
remainingElements.push(this.parseSchema());
|
remainingElements.push(this.parseNamedSchema());
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
if (!this.consumeStr(";")) {
|
if (!this.consumeStr(";")) {
|
||||||
break;
|
break;
|
||||||
|
|
@ -130,13 +130,13 @@ var Parser = class {
|
||||||
if (!this.consumeStr("]")) {
|
if (!this.consumeStr("]")) {
|
||||||
throw new ParseError("Expected ]", this.pos);
|
throw new ParseError("Expected ]", this.pos);
|
||||||
}
|
}
|
||||||
if (elements.length === 1) {
|
if (elements.length === 1 && !elements[0].name) {
|
||||||
return { type: "array", element: elements[0] };
|
return { type: "array", element: elements[0].schema };
|
||||||
}
|
}
|
||||||
return { type: "array", element: { type: "tuple", elements } };
|
return { type: "array", element: { type: "tuple", elements } };
|
||||||
}
|
}
|
||||||
if (elements.length === 1) {
|
if (elements.length === 1 && !elements[0].name) {
|
||||||
return { type: "array", element: elements[0] };
|
return { type: "array", element: elements[0].schema };
|
||||||
}
|
}
|
||||||
return { type: "tuple", elements };
|
return { type: "tuple", elements };
|
||||||
}
|
}
|
||||||
|
|
@ -156,6 +156,28 @@ var Parser = class {
|
||||||
}
|
}
|
||||||
throw new ParseError(`Unexpected character: ${this.peek()}`, this.pos);
|
throw new ParseError(`Unexpected character: ${this.peek()}`, this.pos);
|
||||||
}
|
}
|
||||||
|
parseNamedSchema() {
|
||||||
|
this.skipWhitespace();
|
||||||
|
const startpos = this.pos;
|
||||||
|
let identifier = "";
|
||||||
|
while (this.pos < this.input.length && /[a-zA-Z0-9\-_]/.test(this.peek())) {
|
||||||
|
identifier += this.consume();
|
||||||
|
}
|
||||||
|
if (identifier.length === 0) {
|
||||||
|
throw new ParseError("Expected schema or named schema", this.pos);
|
||||||
|
}
|
||||||
|
this.skipWhitespace();
|
||||||
|
if (this.consumeStr(":")) {
|
||||||
|
this.skipWhitespace();
|
||||||
|
const name = identifier;
|
||||||
|
const schema = this.parseSchema();
|
||||||
|
return { name, schema };
|
||||||
|
} else {
|
||||||
|
this.pos = startpos;
|
||||||
|
const schema = this.parseSchema();
|
||||||
|
return { schema };
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
function parseSchema(schemaString) {
|
function parseSchema(schemaString) {
|
||||||
const parser = new Parser(schemaString.trim());
|
const parser = new Parser(schemaString.trim());
|
||||||
|
|
@ -263,7 +285,15 @@ var ValueParser = class {
|
||||||
const result = [];
|
const result = [];
|
||||||
for (let i = 0; i < schema.elements.length; i++) {
|
for (let i = 0; i < schema.elements.length; i++) {
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
result.push(this.parseValue(schema.elements[i], false));
|
const elementSchema = schema.elements[i];
|
||||||
|
if (elementSchema.name) {
|
||||||
|
this.skipWhitespace();
|
||||||
|
if (!this.consumeStr(`${elementSchema.name}:`)) {
|
||||||
|
throw new ParseError(`Expected ${elementSchema.name}:`, this.pos);
|
||||||
|
}
|
||||||
|
this.skipWhitespace();
|
||||||
|
}
|
||||||
|
result.push(this.parseValue(elementSchema.schema, false));
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
if (i < schema.elements.length - 1) {
|
if (i < schema.elements.length - 1) {
|
||||||
if (!this.consumeStr(";")) {
|
if (!this.consumeStr(";")) {
|
||||||
|
|
@ -345,7 +375,7 @@ function createValidator(schema) {
|
||||||
if (!Array.isArray(value)) return false;
|
if (!Array.isArray(value)) return false;
|
||||||
if (value.length !== schema.elements.length) return false;
|
if (value.length !== schema.elements.length) return false;
|
||||||
return schema.elements.every(
|
return schema.elements.every(
|
||||||
(elementSchema, index) => createValidator(elementSchema)(value[index])
|
(elementSchema, index) => createValidator(elementSchema.schema)(value[index])
|
||||||
);
|
);
|
||||||
case "array":
|
case "array":
|
||||||
if (!Array.isArray(value)) return false;
|
if (!Array.isArray(value)) return false;
|
||||||
|
|
|
||||||
|
|
@ -77,13 +77,13 @@ var Parser = class {
|
||||||
this.consume();
|
this.consume();
|
||||||
throw new ParseError("Empty array/tuple not allowed", this.pos);
|
throw new ParseError("Empty array/tuple not allowed", this.pos);
|
||||||
}
|
}
|
||||||
elements.push(this.parseSchema());
|
elements.push(this.parseNamedSchema());
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
if (this.consumeStr(";")) {
|
if (this.consumeStr(";")) {
|
||||||
const remainingElements = [];
|
const remainingElements = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
remainingElements.push(this.parseSchema());
|
remainingElements.push(this.parseNamedSchema());
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
if (!this.consumeStr(";")) {
|
if (!this.consumeStr(";")) {
|
||||||
break;
|
break;
|
||||||
|
|
@ -100,13 +100,13 @@ var Parser = class {
|
||||||
if (!this.consumeStr("]")) {
|
if (!this.consumeStr("]")) {
|
||||||
throw new ParseError("Expected ]", this.pos);
|
throw new ParseError("Expected ]", this.pos);
|
||||||
}
|
}
|
||||||
if (elements.length === 1) {
|
if (elements.length === 1 && !elements[0].name) {
|
||||||
return { type: "array", element: elements[0] };
|
return { type: "array", element: elements[0].schema };
|
||||||
}
|
}
|
||||||
return { type: "array", element: { type: "tuple", elements } };
|
return { type: "array", element: { type: "tuple", elements } };
|
||||||
}
|
}
|
||||||
if (elements.length === 1) {
|
if (elements.length === 1 && !elements[0].name) {
|
||||||
return { type: "array", element: elements[0] };
|
return { type: "array", element: elements[0].schema };
|
||||||
}
|
}
|
||||||
return { type: "tuple", elements };
|
return { type: "tuple", elements };
|
||||||
}
|
}
|
||||||
|
|
@ -126,6 +126,28 @@ var Parser = class {
|
||||||
}
|
}
|
||||||
throw new ParseError(`Unexpected character: ${this.peek()}`, this.pos);
|
throw new ParseError(`Unexpected character: ${this.peek()}`, this.pos);
|
||||||
}
|
}
|
||||||
|
parseNamedSchema() {
|
||||||
|
this.skipWhitespace();
|
||||||
|
const startpos = this.pos;
|
||||||
|
let identifier = "";
|
||||||
|
while (this.pos < this.input.length && /[a-zA-Z0-9\-_]/.test(this.peek())) {
|
||||||
|
identifier += this.consume();
|
||||||
|
}
|
||||||
|
if (identifier.length === 0) {
|
||||||
|
throw new ParseError("Expected schema or named schema", this.pos);
|
||||||
|
}
|
||||||
|
this.skipWhitespace();
|
||||||
|
if (this.consumeStr(":")) {
|
||||||
|
this.skipWhitespace();
|
||||||
|
const name = identifier;
|
||||||
|
const schema = this.parseSchema();
|
||||||
|
return { name, schema };
|
||||||
|
} else {
|
||||||
|
this.pos = startpos;
|
||||||
|
const schema = this.parseSchema();
|
||||||
|
return { schema };
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
function parseSchema(schemaString) {
|
function parseSchema(schemaString) {
|
||||||
const parser = new Parser(schemaString.trim());
|
const parser = new Parser(schemaString.trim());
|
||||||
|
|
@ -233,7 +255,15 @@ var ValueParser = class {
|
||||||
const result = [];
|
const result = [];
|
||||||
for (let i = 0; i < schema.elements.length; i++) {
|
for (let i = 0; i < schema.elements.length; i++) {
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
result.push(this.parseValue(schema.elements[i], false));
|
const elementSchema = schema.elements[i];
|
||||||
|
if (elementSchema.name) {
|
||||||
|
this.skipWhitespace();
|
||||||
|
if (!this.consumeStr(`${elementSchema.name}:`)) {
|
||||||
|
throw new ParseError(`Expected ${elementSchema.name}:`, this.pos);
|
||||||
|
}
|
||||||
|
this.skipWhitespace();
|
||||||
|
}
|
||||||
|
result.push(this.parseValue(elementSchema.schema, false));
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
if (i < schema.elements.length - 1) {
|
if (i < schema.elements.length - 1) {
|
||||||
if (!this.consumeStr(";")) {
|
if (!this.consumeStr(";")) {
|
||||||
|
|
@ -315,7 +345,7 @@ function createValidator(schema) {
|
||||||
if (!Array.isArray(value)) return false;
|
if (!Array.isArray(value)) return false;
|
||||||
if (value.length !== schema.elements.length) return false;
|
if (value.length !== schema.elements.length) return false;
|
||||||
return schema.elements.every(
|
return schema.elements.every(
|
||||||
(elementSchema, index) => createValidator(elementSchema)(value[index])
|
(elementSchema, index) => createValidator(elementSchema.schema)(value[index])
|
||||||
);
|
);
|
||||||
case "array":
|
case "array":
|
||||||
if (!Array.isArray(value)) return false;
|
if (!Array.isArray(value)) return false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue