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: move errors #15

Merged
merged 1 commit into from
Nov 18, 2023
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
37 changes: 37 additions & 0 deletions packages/parse/src/parse-errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { toTokenType } from './utils/to-token-type';

export class UnexpectedTokenError extends Error {
constructor(type: string | null, position: number) {
super(
type
? `Unexpected ${toTokenType(type)} at position ${position}.`
: `Unexpected token at position ${position}.`
);
}
}

export class NoPropertyValueError extends Error {
constructor(propertyName: string | null) {
super(
propertyName
? `No property value specified for property '${propertyName}'.`
: 'No property value specified.'
);
}
}

export class NonMatchingArrayBracket extends Error {
constructor(position: number | null) {
super(
position
? `No closing bracket for array started at position ${position}.`
: 'No closing bracket for array.'
);
}
}

export class NonMatchingObjectBrace extends Error {
constructor(position: number) {
super(`No closing brace for object started at position ${position}.`);
}
}
43 changes: 6 additions & 37 deletions packages/parse/src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
import { isString } from '@utilz/types';
import { isWhitespace } from './utils/is-whitespace';
import { toTokenType } from './utils/to-token-type';
import { lexer } from './lexer';

class UnexpectedTokenError extends Error {
constructor(type: string | null, position: number) {
super(
type
? `Unexpected ${toTokenType(type)} at position ${position}.`
: `Unexpected token at position ${position}.`
);
}
}

class NoPropertyValueError extends Error {
constructor(propertyName: string | null) {
super(
propertyName
? `No property value specified for property '${propertyName}'.`
: 'No property value specified.'
);
}
}

class NonMatchingArrayBracket extends Error {
constructor(position: number | null) {
super(
position
? `No closing bracket for array started at position ${position}.`
: 'No closing bracket for array.'
);
}
}

class NonMatchingObjectBrace extends Error {
constructor(position: number) {
super(`No closing brace for object started at position ${position}.`);
}
}
import {
NoPropertyValueError,
NonMatchingArrayBracket,
NonMatchingObjectBrace,
UnexpectedTokenError,
} from './parse-errors';

const objectFactory = (position: number) => {
const result: Record<string, unknown> = {};
Expand Down
Loading