Skip to content

Commit

Permalink
Merge pull request #63 from rycont/implement-monaco-dalbityaksok-lang…
Browse files Browse the repository at this point in the history
…uage

feat: implement monaco language provider
  • Loading branch information
rycont authored Jan 11, 2025
2 parents 042206c + b475109 commit 495c7f8
Show file tree
Hide file tree
Showing 65 changed files with 1,699 additions and 553 deletions.
2 changes: 1 addition & 1 deletion core/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
},
"name": "@dalbit-yaksok/core",
"exports": "./mod.ts",
"version": "0.2.0-alpha.10+20241217.nightly"
"version": "0.2.0-alpha.13+20250104.nightly"
}
3 changes: 3 additions & 0 deletions core/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { ValueType, ObjectValue, PrimitiveValue } from './value/base.ts'
export { ListValue } from './value/list.ts'

export { CodeFile } from './type/code-file.ts'
export type { Position } from './type/position.ts'
export { yaksok, Runtime } from './runtime/index.ts'

export { Scope } from './executer/scope.ts'
Expand All @@ -11,6 +12,8 @@ export * from './node/index.ts'
export { tokenize } from './prepare/tokenize/index.ts'
export * from './prepare/tokenize/token.ts'

export { parse } from './prepare/parse/index.ts'

export type { RuntimeConfig } from './runtime/runtime-config.ts'
export type { FunctionInvokingParams } from './constant/type.ts'
export type { FEATURE_FLAG } from './constant/feature-flags.ts'
Expand Down
7 changes: 4 additions & 3 deletions core/node/IfStatement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Block } from './block.ts'
import { isTruthy } from '../executer/internal/isTruthy.ts'
import { CallFrame } from '../executer/callFrame.ts'
import type { Scope } from '../executer/scope.ts'
import type { Token } from '../prepare/tokenize/token.ts'

interface Case {
condition?: Evaluable
Expand All @@ -13,7 +14,7 @@ interface Case {
export class IfStatement extends Executable {
static override friendlyName = '조건문(만약)'

constructor(public cases: Case[]) {
constructor(public cases: Case[], public override tokens: Token[]) {
super()
}

Expand Down Expand Up @@ -46,15 +47,15 @@ export class IfStatement extends Executable {
export class ElseStatement extends Executable {
static override friendlyName = '조건문(아니면)'

constructor(public body: Block) {
constructor(public body: Block, public override tokens: Token[]) {
super()
}
}

export class ElseIfStatement extends Executable {
static override friendlyName = '조건문(아니면 만약)'

constructor(public elseIfCase: Case) {
constructor(public elseIfCase: Case, public override tokens: Token[]) {
super()
}
}
25 changes: 17 additions & 8 deletions core/node/base.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { CallFrame } from '../executer/callFrame.ts'
import type { Scope } from '../executer/scope.ts'
import { NotDefinedIdentifierError } from '../error/variable.ts'
import { Position } from '../type/position.ts'
import { ValueType } from '../value/base.ts'
import { Token } from '../prepare/tokenize/token.ts'

export class Node {
[key: string]: unknown
position?: Position
tokens?: Token[]

static friendlyName = '노드'

toJSON(): object {
Expand Down Expand Up @@ -44,7 +45,7 @@ export class Evaluable<T extends ValueType = ValueType> extends Executable {
export class Identifier extends Evaluable {
static override friendlyName = '식별자'

constructor(public value: string, override position?: Position) {
constructor(public value: string, public override tokens: Token[]) {
super()
}

Expand All @@ -57,34 +58,42 @@ export class Identifier extends Evaluable {
return Promise.resolve(scope.getVariable(this.value))
} catch (e) {
if (e instanceof NotDefinedIdentifierError) {
e.position = this.position
e.position = this.tokens?.[0].position
}

throw e
}
}
}

export class Operator extends Node {
export class Operator extends Node implements OperatorNode {
static override friendlyName = '연산자'

constructor(public value?: string, public override position?: Position) {
constructor(public value: string | null, public override tokens: Token[]) {
super()
}

override toPrint(): string {
return this.value ?? 'unknown'
return 'unknown'
}

call(..._operands: ValueType[]): ValueType {
throw new Error(`${this.constructor.name} has no call method`)
}
}

export interface OperatorNode {
call(...operands: ValueType[]): ValueType
}

export type OperatorClass ={
new (...args: any[]): OperatorNode
}

export class Expression extends Node {
static override friendlyName = '표현식'

constructor(public value: string, public override position?: Position) {
constructor(public value: string, public override tokens: Token[]) {
super()
}

Expand Down
10 changes: 6 additions & 4 deletions core/node/block.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { CallFrame } from '../executer/callFrame.ts'
import { CannotParseError } from '../error/index.ts'
import type { Scope } from '../executer/scope.ts'
import { EOL } from './misc.ts'
import { Executable, type Node } from './base.ts'
import { EOL } from './misc.ts'

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

export class Block extends Executable {
static override friendlyName = '코드 덩어리'

children: Node[]

constructor(content: Node[]) {
constructor(content: Node[], public override tokens: Token[]) {
super()
this.children = content
}
Expand All @@ -24,7 +26,7 @@ export class Block extends Executable {
continue
} else {
throw new CannotParseError({
position: child.position,
position: child.tokens?.[0].position,
resource: {
part: child,
},
Expand Down
16 changes: 10 additions & 6 deletions core/node/calculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import {
OrOperator,
PlusOperator,
PowerOperator,
RangeOperator,
} from './operator.ts'
import { Evaluable, Operator } from './base.ts'
import { RangeOperator } from './list.ts'
import { Evaluable, Operator, OperatorClass } from './base.ts'
import { ValueType } from '../value/base.ts'
import type { Token } from '../prepare/tokenize/token.ts'

const OPERATOR_PRECEDENCES: Array<(typeof Operator)[]> = [
const OPERATOR_PRECEDENCES: OperatorClass[][] = [
[AndOperator, OrOperator],
[
EqualOperator,
Expand All @@ -38,7 +39,7 @@ const OPERATOR_PRECEDENCES: Array<(typeof Operator)[]> = [
export class ValueWithParenthesis extends Evaluable {
static override friendlyName = '괄호로 묶인 값'

constructor(public value: Evaluable) {
constructor(public value: Evaluable, public override tokens: Token[]) {
super()
}

Expand All @@ -55,7 +56,10 @@ export class ValueWithParenthesis extends Evaluable {
export class Formula extends Evaluable {
static override friendlyName = '계산식'

constructor(public terms: (Evaluable | Operator)[]) {
constructor(
public terms: (Evaluable | Operator)[],
public override tokens: Token[],
) {
super()
}

Expand Down Expand Up @@ -95,7 +99,7 @@ export class Formula extends Evaluable {

const isOperator = term instanceof Operator
const isCurrentPrecedence = currentOperators.includes(
term.constructor as typeof Operator,
term.constructor as OperatorClass,
)

if (!isOperator || !isCurrentPrecedence) continue
Expand Down
18 changes: 11 additions & 7 deletions core/node/ffi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { Executable, Node } from './base.ts'

import type { Scope } from '../executer/scope.ts'
import type { Position } from '../type/position.ts'
import type { Token } from '../prepare/tokenize/token.ts'

export class FFIBody extends Node {
static override friendlyName = '번역할 내용'

constructor(public code: string, public override position?: Position) {
constructor(public code: string, public override tokens: Token[]) {
super()
}
}
Expand All @@ -19,12 +20,15 @@ export class DeclareFFI extends Executable {
public body: string
public runtime: string

constructor(props: {
name: string
body: string
runtime: string
position?: Position
}) {
constructor(
props: {
name: string
body: string
runtime: string
position?: Position
},
public override tokens: Token[],
) {
super()
this.name = props.name
this.body = props.body
Expand Down
13 changes: 10 additions & 3 deletions core/node/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import type { Block } from './block.ts'
import { FunctionObject } from '../value/function.ts'
import { FFIResultTypeIsNotForYaksokError } from '../error/ffi.ts'
import { ValueType } from '../value/base.ts'
import type { Token } from '../prepare/tokenize/token.ts'

export class DeclareFunction extends Executable {
static override friendlyName = '새 약속 만들기'

name: string
body: Block

constructor(props: { body: Block; name: string }) {
constructor(
props: { body: Block; name: string },
public override tokens: Token[],
) {
super()

this.name = props.name
Expand All @@ -35,7 +39,10 @@ export class FunctionInvoke extends Evaluable {
public name: string
public params: Record<string, Evaluable>

constructor(props: { name: string; params: Record<string, Evaluable> }) {
constructor(
props: { name: string; params: Record<string, Evaluable> },
public override tokens: Token[],
) {
super()

this.name = props.name!
Expand Down Expand Up @@ -85,6 +92,6 @@ function assertValidReturnValue(node: FunctionInvoke, returnValue: ValueType) {
throw new FFIResultTypeIsNotForYaksokError({
ffiName: node.name,
value: returnValue,
position: node.position,
position: node.tokens?.[0].position,
})
}
1 change: 1 addition & 0 deletions core/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './variable.ts'
export * from './return.ts'
export * from './mention.ts'
export * from './ffi.ts'
export * from './listLoop.ts'
Loading

0 comments on commit 495c7f8

Please sign in to comment.