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: raise error when newline in string #77

Merged
merged 5 commits into from
Mar 7, 2025
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
2 changes: 1 addition & 1 deletion core/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
},
"name": "@dalbit-yaksok/core",
"exports": "./mod.ts",
"version": "0.2.0-RC.9"
"version": "0.2.0"
}
12 changes: 12 additions & 0 deletions core/error/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ export class UnexpectedCharError extends YaksokError<UnexpectedCharErrorResource
}
}

export class UnexpectedNewlineError extends UnexpectedCharError {
constructor(props: { parts: string; position?: Position }) {
super({
resource: {
char: '줄바꿈',
parts: props.parts,
},
})
this.message = `${bold(blue(props.parts))}엔 줄바꿈을 사용할 수 없어요.`
}
}

export class UnexpectedEndOfCodeError extends YaksokError {
constructor(props: {
resource?: {
Expand Down
10 changes: 10 additions & 0 deletions core/prepare/tokenize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NotAcceptableSignal } from './signal.ts'
import { RULES } from './rules.ts'

import { TOKEN_TYPE, type Token } from './token.ts'
import { YaksokError } from '../../error/common.ts'

class Tokenizer {
private tokens: Token[] = []
Expand Down Expand Up @@ -72,6 +73,15 @@ class Tokenizer {
if (e instanceof NotAcceptableSignal) {
continue
}

if (e instanceof YaksokError && !e.tokens) {
e.position = {
column: columnCheckpoint,
line: lineCheckpoint,
}
}

throw e
}
}

Expand Down
7 changes: 7 additions & 0 deletions core/prepare/tokenize/rules.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NotAcceptableSignal } from './signal.ts'
import { Token, TOKEN_TYPE } from './token.ts'
import { UnexpectedNewlineError } from '../../error/prepare.ts'

const OPERATORS = [
'+',
Expand Down Expand Up @@ -246,6 +247,12 @@ export const RULES: {
return value
}

if (view() === '\n') {
throw new UnexpectedNewlineError({
parts: '문자열',
})
}

value += shift()!
}

Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"test",
"monaco-language-provider"
],
"version": "0.2.0-RC.9",
"version": "0.2.0",
"tasks": {
"apply-version": "deno run --allow-read --allow-write apply-version.ts",
"publish": "deno task --recursive test && deno publish --allow-dirty"
Expand Down
2 changes: 1 addition & 1 deletion monaco-language-provider/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
},
"name": "@dalbit-yaksok/monaco-language-provider",
"exports": "./mod.ts",
"version": "0.2.0-RC.9"
"version": "0.2.0"
}
2 changes: 1 addition & 1 deletion quickjs/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"check-deploy": "deno publish --dry-run --allow-dirty",
"test": "deno test --quiet --allow-net --allow-read --parallel & deno lint & deno task check-deploy"
},
"version": "0.2.0-RC.9"
"version": "0.2.0"
}
11 changes: 3 additions & 8 deletions runtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ import { yaksok } from '@dalbit-yaksok/core'

await yaksok(
`
약속, 물어보기
결과: "성공"

약속, (질문) 물어보기
결과: "이건 아님"

(물어보기) + 물어보기 * 3 보여주기
("뭐라도" 물어보기) + ("뭐라도" 물어보기) * 3 보여주기
결과: "줄
바꿈이
나왔어요"
`,
// {
// runFFI(runtime, bodyCode, args) {
Expand Down
17 changes: 16 additions & 1 deletion test/errors/unexpected-eol.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { assertIsError } from 'assert'
import { yaksok } from '../../core/mod.ts'
import { UnexpectedEndOfCodeError } from '../../core/error/index.ts'
import {
UnexpectedEndOfCodeError,
UnexpectedNewlineError,
} from '../../core/error/index.ts'

Deno.test('예상치 못한 줄바꿈', async () => {
try {
Expand All @@ -10,3 +13,15 @@ Deno.test('예상치 못한 줄바꿈', async () => {
console.log(error)
}
})

Deno.test('문자열 내 줄바꿈', async () => {
try {
await yaksok(`
"줄바꿈이
있는 문자열"
`)
} catch (error) {
assertIsError(error, UnexpectedNewlineError)
console.log(error)
}
})