Skip to content

Commit

Permalink
Merge pull request #48 from rycont/separate-tokenizer-and-nodes
Browse files Browse the repository at this point in the history
Refactor: separate tokenizer and nodes
  • Loading branch information
rycont authored Nov 17, 2024
2 parents c1c0eaa + a0cf356 commit 3f0f1f8
Show file tree
Hide file tree
Showing 83 changed files with 2,200 additions and 1,898 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ jobs:
with:
deno-version: v2.x

- name: Run linter
run: deno lint

- name: Run tests
run: deno task test

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,5 @@ jobs:
with:
deno-version: v2.x

- name: Run linter
run: deno lint

- name: Run tests
run: deno task test
6 changes: 4 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.8",
"@std/fs": "jsr:@std/fs@^1.0.5",
"@vue/runtime-dom": "npm:@vue/runtime-dom@^3.5.12",
"@vueuse/core": "npm:@vueuse/core@^11.2.0",
"ansi-to-html": "npm:ansi-to-html@^0.7.2",
Expand All @@ -14,7 +16,7 @@
"tasks": {
"coverage": "rm -rf ./cov && deno test --allow-read --parallel --coverage=cov && deno coverage --detailed ./cov && rm -rf ./cov",
"coverage-list": "rm -rf ./cov && deno test --allow-read --parallel --coverage=cov && deno coverage ./cov && rm -rf ./cov",
"test": "deno run -A npm:madge --circular --extensions ts ./ && deno test --allow-read --parallel && deno publish --dry-run",
"test": "deno run -A npm:madge --circular --extensions ts ./ && deno test --allow-read --parallel && deno publish --dry-run && deno lint",
"typedoc": "deno run --allow-read --allow-write --allow-env --allow-run ./create-docs.ts",
"vitepress-dev": "deno run -A npm:vitepress dev docs",
"vitepress-build": "deno run -A npm:vitepress build docs",
Expand All @@ -33,7 +35,7 @@
}
},
"name": "@yaksok-ts/core",
"version": "0.1.17",
"version": "0.2.0-alpha.1+20241117",
"exports": "./src/mod.ts",
"nodeModulesDir": "auto",
"workspace": [
Expand Down
20 changes: 20 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/library/2. 런타임에서 변수 가져오기.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const code = `
`

const result = yaksok(code)
console.log(result.getFileRunner().scope.getVariable('내_이름').value)
console.log(result.scope.getVariable('내_이름').value)
```

자세히 알아보려면 다음 문서를 참조하세요:

- [Runtime 클래스](/api/classes/Runtime)
- [FileRunner 클래스](/api/classes/FileRunner)
- [CodeFile 클래스](/api/classes/CodeFile)
- [Scope 클래스](/api/classes/Scope)
2 changes: 1 addition & 1 deletion quickjs/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"quickjs-emscripten": "npm:quickjs-emscripten@^0.31.0",
"quickjs-emscripten-core": "npm:quickjs-emscripten-core@^0.31.0"
},
"version": "0.1.17"
"version": "0.2.0-alpha.1+20241117"
}
26 changes: 7 additions & 19 deletions quickjs/quickjs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Deno.test('QuickJS passed number', async () => {
},
)

assertEquals(result.getFileRunner().scope.getVariable('숫자').value, 20)
assertEquals(result.scope.getVariable('숫자').value, 20)
})

Deno.test('QuickJS passed Array<number>', async () => {
Expand Down Expand Up @@ -118,10 +118,7 @@ Deno.test('QuickJS passed Array<number>', async () => {
},
)

assertEquals(
result.getFileRunner().scope.getVariable('숫자').toPrint(),
'[20, 30]',
)
assertEquals(result.scope.getVariable('숫자').toPrint(), '[20, 30]')
})

Deno.test('JavaScript bridge function passed object', async () => {
Expand Down Expand Up @@ -184,21 +181,12 @@ Deno.test('JavaScript bridge function passed object', async () => {
},
)

assertEquals(result.scope.getVariable('학생').toPrint(), '홍길동')
assertEquals(result.scope.getVariable('이름').toPrint(), '홍길동')
assertEquals(result.scope.getVariable('나이').value, 20)
assertEquals(result.scope.getVariable('더한_결과').value, 30)
assertEquals(
result.getFileRunner().scope.getVariable('학생').toPrint(),
'홍길동',
)
assertEquals(
result.getFileRunner().scope.getVariable('이름').toPrint(),
'홍길동',
)
assertEquals(result.getFileRunner().scope.getVariable('나이').value, 20)
assertEquals(
result.getFileRunner().scope.getVariable('더한_결과').value,
30,
)
assertEquals(
result.getFileRunner().scope.getVariable('모든_이름').toPrint(),
result.scope.getVariable('모든_이름').toPrint(),
'[홍길동, 임꺽정, 김철수]',
)
})
42 changes: 6 additions & 36 deletions runtest.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,8 @@
import { yaksok } from './src/mod.ts'
import { yaksok } from '@yaksok-ts/core'

yaksok(
`
약속, 회전설정 (회전)
결과: "rotate:" + 회전
const code = `
내_이름: "영희"
`

약속, 시간설정 (시간)
결과: "time:" + 시간
약속, (A) 합 (B)
결과: A + "<join>" + B
약속, (각도)도 회전하기
회전설정 각도 보여주기
약속, (시간)초 동안 (각도)도 회전하기
(시간설정 시간) 합 (회전설정 각도) 보여주기
각도: 45
시간: 30
(3)초 동안 (90)도 회전하기
3 초 동안 90 도 회전하기
(3)초 동안 90 도 회전하기
3 초 동안 (90)도 회전하기
시간 초 동안 각도 도 회전하기
(시간)초 동안 (각도)도 회전하기
(시간)초 동안 각도 도 회전하기
시간 초 동안 (각도)도 회전하기
(90)도 회전하기
90 도 회전하기
각도 도 회전하기
(각도)도 회전하기
`,
)
const result = yaksok(code)
console.log(result.scope.getVariable('내_이름').value)
4 changes: 3 additions & 1 deletion src/error/calculation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Evaluable, Operator, Position } from '../node/base.ts'
import { Evaluable, Operator } from '../node/base.ts'
import { evaluableToText, operatorToText, YaksokError } from './common.ts'

import type { Position } from '../type/position.ts'

export class InvalidTypeForCompareError extends YaksokError {
constructor(props: {
position?: Position
Expand Down
6 changes: 5 additions & 1 deletion src/error/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import type { Evaluable, Operator, Position } from '../node/base.ts'
import type { Evaluable, Operator } from '../node/base.ts'
import type { CodeFile } from '../type/code-file.ts'
import type { Position } from '../type/position.ts'

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

constructor(props: { position?: Position; resource?: T }) {
super()
Expand Down
7 changes: 5 additions & 2 deletions src/error/ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Position } from '../node/base.ts'
import type { Position } from '../type/position.ts'
import { YaksokError, blue, bold, dim } from './common.ts'

export class FFIResultTypeIsNotForYaksokError extends YaksokError {
Expand All @@ -11,7 +11,10 @@ export class FFIResultTypeIsNotForYaksokError extends YaksokError {
stringValue = 'undefined'
} else if (typeof props.value === 'string') {
stringValue = props.value
} else if (props.value.__proto__ && props.value.__proto__.toString) {
} else if (
props.value.constructor &&
props.value.constructor.toString
) {
stringValue = props.value.toString()
} else {
stringValue = JSON.stringify(props.value)
Expand Down
4 changes: 2 additions & 2 deletions src/error/function.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Position } from '../node/base.ts'
import type { Position } from '../type/position.ts'
import { YaksokError } from './common.ts'

export class CannotReturnOutsideFunctionError extends YaksokError {
Expand All @@ -11,6 +11,6 @@ export class CannotReturnOutsideFunctionError extends YaksokError {
export class FunctionMustHaveOneOrMoreStringPartError extends YaksokError {
constructor(props: { position?: Position }) {
super(props)
this.message = `함수를 선언할 때엔 적어도 하나의 고정되는 부분이 있어야 해요.`
this.message = `약속(번역)을 선언할 때엔 적어도 하나의 고정되는 부분이 있어야 해요.`
}
}
3 changes: 2 additions & 1 deletion src/error/list.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Position, Evaluable } from '../node/base.ts'
import type { Evaluable } from '../node/base.ts'
import type { Position } from '../type/position.ts'
import { YaksokError, evaluableToText } from './common.ts'

export class ListIndexOutOfRangeError extends YaksokError {
Expand Down
2 changes: 1 addition & 1 deletion src/error/loop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Position } from '../node/base.ts'
import type { Position } from '../type/position.ts'
import { YaksokError } from './common.ts'

export class BreakNotInLoopError extends YaksokError {
Expand Down
4 changes: 3 additions & 1 deletion src/error/mention.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Position } from '../node/index.ts'
import type { Position } from '../type/position.ts'
import { YaksokError, blue, bold } from './common.ts'

export class ErrorInModuleError extends YaksokError {
Expand All @@ -7,8 +7,10 @@ export class ErrorInModuleError extends YaksokError {
resource: {
fileName: string
}
child: YaksokError
}) {
super(props)
this.child = props.child

this.message = `다른 약속 파일 ${blue(
bold(props.resource.fileName),
Expand Down
Loading

0 comments on commit 3f0f1f8

Please sign in to comment.