Skip to content

Commit

Permalink
Merge pull request #68 from rycont/implement-underline-error-rendering
Browse files Browse the repository at this point in the history
feat: implement regional error token accent
rycont authored Jan 12, 2025
2 parents 0e47d27 + abb19d9 commit 86b8763
Showing 33 changed files with 316 additions and 165 deletions.
2 changes: 1 addition & 1 deletion core/deno.json
Original file line number Diff line number Diff line change
@@ -6,5 +6,5 @@
},
"name": "@dalbit-yaksok/core",
"exports": "./mod.ts",
"version": "0.2.0-RC.2"
"version": "0.2.0-RC.3"
}
2 changes: 2 additions & 0 deletions core/error/calculation.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { operatorToText, valueTypeToText, YaksokError } from './common.ts'

import type { Position } from '../type/position.ts'
import { ValueType } from '../value/base.ts'
import { Token } from '../prepare/tokenize/token.ts'

export class InvalidTypeForCompareError extends YaksokError {
constructor(props: {
@@ -24,6 +25,7 @@ export class InvalidTypeForCompareError extends YaksokError {
export class InvalidTypeForOperatorError extends YaksokError {
constructor(props: {
position?: Position
tokens?: Token[]
resource: {
operator: Operator
operands: ValueType[]
12 changes: 11 additions & 1 deletion core/error/common.ts
Original file line number Diff line number Diff line change
@@ -6,15 +6,21 @@ import { ValueType } from '../value/base.ts'

export class YaksokError<T = unknown> extends Error {
position?: Position
tokens?: Token[]
resource?: T
codeFile?: CodeFile
child?: YaksokError

constructor(props: { position?: Position; resource?: T }) {
constructor(props: {
position?: Position
resource?: T
tokens?: Token[]
}) {
super()

this.position = props.position
this.resource = props.resource
this.tokens = props.tokens
}
}

@@ -66,3 +72,7 @@ export function blue(text: string | number) {
export function dim(text: string | number) {
return `\x1b[2m${text}\x1b[0m`
}

export function underline(text: string | number) {
return `\x1b[4m${text}\x1b[24m`
}
5 changes: 3 additions & 2 deletions core/error/ffi.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Position } from '../type/position.ts'
import type { Token } from '../prepare/tokenize/token.ts'

import { YaksokError, blue, bold, dim } from './common.ts'

export class FFIResultTypeIsNotForYaksokError extends YaksokError {
constructor(props: { position?: Position; value: any; ffiName: string }) {
constructor(props: { value: any; ffiName: string; tokens: Token[] }) {
super(props)

let stringValue = ''
7 changes: 4 additions & 3 deletions core/error/function.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { Position } from '../type/position.ts'
import type { Token } from '../prepare/tokenize/token.ts'

import { YaksokError } from './common.ts'

export class CannotReturnOutsideFunctionError extends YaksokError {
constructor(props: { position?: Position }) {
constructor(props: { tokens: Token[] }) {
super(props)
this.message = `"약속 그만"은 약속 안에서만 사용할 수 있어요.`
}
}

export class FunctionMustHaveOneOrMoreStringPartError extends YaksokError {
constructor(props: { position?: Position }) {
constructor(props: { tokens: Token[] }) {
super(props)
this.message = `약속(번역)을 선언할 때엔 적어도 하나의 고정되는 부분이 있어야 해요.`
}
12 changes: 6 additions & 6 deletions core/error/indexed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Evaluable } from '../node/base.ts'
import type { Token } from '../prepare/tokenize/token.ts'
import type { Position } from '../type/position.ts'
import { ValueType } from '../value/base.ts'
import { YaksokError, evaluableToText, valueTypeToText } from './common.ts'
@@ -10,6 +11,7 @@ export class IndexOutOfRangeError extends YaksokError {
index: string
target: string
}
tokens?: Token[]
}) {
super(props)
this.message = `${props.resource.target}에는 ${props.resource.index}라는 값이 없어요`
@@ -18,7 +20,7 @@ export class IndexOutOfRangeError extends YaksokError {

export class NotEnumerableValueForListLoopError extends YaksokError {
constructor(props: {
position?: Position
tokens: Token[]
resource: {
value: ValueType
}
@@ -72,22 +74,20 @@ export class RangeStartMustBeLessThanEndError extends YaksokError {

export class ListIndexTypeError extends YaksokError {
constructor(props: {
position?: Position

tokens?: Token[]
resource: {
index: string | number
}
}) {
super(props)

this.message = `목록의 인덱스는 정수여야 해요. ${props.resource.index}는 정수가 아니에요.`
}
}

export class RangeStartMustBeNumberError extends YaksokError {
constructor(props: {
position?: Position

tokens?: Token[]
resource: {
start: ValueType
}
@@ -101,7 +101,7 @@ export class RangeStartMustBeNumberError extends YaksokError {

export class TargetIsNotIndexedValueError extends YaksokError {
constructor(props: {
position?: Position
tokens: Token[]

resource: {
target: Evaluable
5 changes: 3 additions & 2 deletions core/error/loop.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Position } from '../type/position.ts'
import { YaksokError } from './common.ts'

import type { Token } from '../prepare/tokenize/token.ts'

export class BreakNotInLoopError extends YaksokError {
constructor(props: { position?: Position }) {
constructor(props: { tokens: Token[]; resource?: unknown }) {
super(props)
this.message = `"반복 그만"은 반복문 안에서만 사용할 수 있어요.`
}
4 changes: 2 additions & 2 deletions core/error/mention.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Position } from '../type/position.ts'
import type { Token } from '../prepare/tokenize/token.ts'
import { YaksokError, blue, bold } from './common.ts'

export class ErrorInModuleError extends YaksokError<{
fileName: string
}> {
constructor(props: {
position?: Position
tokens?: Token[]
resource: {
fileName: string
}
19 changes: 12 additions & 7 deletions core/error/prepare.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { YaksokError, blue, bold, dim, tokenToText } from './common.ts'

export class CannotParseError extends YaksokError {
constructor(props: {
position?: Position
tokens: Token[]
resource: {
part: Node
}
@@ -30,7 +30,7 @@ export class CannotParseError extends YaksokError {

export class IndentIsNotMultipleOf4Error extends YaksokError {
constructor(props: {
position?: Position
tokens: Token[]
resource: {
indent: number
}
@@ -43,17 +43,20 @@ export class IndentIsNotMultipleOf4Error extends YaksokError {
export class IndentLevelMismatchError extends YaksokError {
constructor(props: {
position?: Position
tokens?: Token[]
resource: {
expected?: number
}
}) {
super(props)
this.message = `들여쓰기가 잘못되었어요.`

if (props.resource.expected !== undefined) {
if (props.resource.expected === 0) {
this.message += ` 여기선 들여쓰기를 할 필요가 없어요.`
} else if (props.resource.expected !== undefined) {
this.message += ` 여기서는 ${bold(
`"${props.resource.expected}"`,
)}만큼 들여쓰기를 해야해요.`
props.resource.expected * 4 + '칸',
)}${dim(`(또는 탭 ${props.resource.expected}번)`)} 띄어써야 해요.`
}
}
}
@@ -94,14 +97,16 @@ export class UnexpectedEndOfCodeError extends YaksokError {
export class UnexpectedTokenError extends YaksokError {
constructor(props: {
resource: {
token: Token
parts: string
}
tokens: Token[]
position?: Position
}) {
super(props)

this.message = `${tokenToText(props.resource.token)}${bold(props.resource.parts)}에 사용할 수 없어요.`
this.message = `${tokenToText(props.tokens[0])}${bold(
props.resource.parts,
)}에 사용할 수 없어요.`
}
}

61 changes: 0 additions & 61 deletions core/error/printError.ts

This file was deleted.

Loading

0 comments on commit 86b8763

Please sign in to comment.