-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from rycont/fix-identifier-as-parameter-parse-…
…error Fix identifier as parameter parse error
- Loading branch information
Showing
9 changed files
with
159 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,38 @@ | ||
import { FunctionParams } from './src/mod.ts' | ||
import { NumberValue } from './src/mod.ts' | ||
import { yaksok } from './src/mod.ts' | ||
|
||
yaksok( | ||
` | ||
번역(JavaScript), (A)와 (B) 사이 랜덤 수 | ||
*** | ||
return Math.floor(Math.random() * (B - A) + A) | ||
*** | ||
약속, 회전설정 (회전) | ||
결과: "rotate:" + 회전 | ||
(1)와 (10) 사이 랜덤 수 보여주기 | ||
`, | ||
{ | ||
runFFI: (runtime, code, params) => { | ||
if (runtime !== 'JavaScript') { | ||
throw new Error('지원하지 않는 런타임입니다') | ||
} | ||
|
||
const runnableCode = buildCodeFromCodeAndParams(code, params) | ||
const resultInJS = eval(runnableCode) | ||
|
||
if (typeof resultInJS !== 'number') { | ||
throw new Error('결과값은 숫자여야 합니다') | ||
} | ||
|
||
return new NumberValue(resultInJS) | ||
}, | ||
}, | ||
) | ||
약속, 시간설정 (시간) | ||
결과: "time:" + 시간 | ||
약속, (A) 합 (B) | ||
결과: A + "<join>" + B | ||
약속, (각도)도 회전하기 | ||
회전설정 각도 보여주기 | ||
약속, (시간)초 동안 (각도)도 회전하기 | ||
(시간설정 시간) 합 (회전설정 각도) 보여주기 | ||
function buildCodeFromCodeAndParams(code: string, params: FunctionParams) { | ||
const paramNames = Object.keys(params) | ||
const paramsInJS = Object.fromEntries( | ||
Object.entries(params).map(([key, value]) => [key, value.value]), | ||
) | ||
각도: 45 | ||
시간: 30 | ||
return `((${paramNames.join(', ')}) => {${code}})(${Object.values( | ||
paramsInJS, | ||
).join(', ')})` | ||
} | ||
(3)초 동안 (90)도 회전하기 | ||
3 초 동안 90 도 회전하기 | ||
(3)초 동안 90 도 회전하기 | ||
3 초 동안 (90)도 회전하기 | ||
시간 초 동안 각도 도 회전하기 | ||
(시간)초 동안 (각도)도 회전하기 | ||
(시간)초 동안 각도 도 회전하기 | ||
시간 초 동안 (각도)도 회전하기 | ||
(90)도 회전하기 | ||
90 도 회전하기 | ||
각도 도 회전하기 | ||
(각도)도 회전하기 | ||
`, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
약속, 회전설정 (회전) | ||
결과: "rotate:" + 회전 | ||
|
||
약속, 시간설정 (시간) | ||
결과: "time:" + 시간 | ||
|
||
약속, (A) 합 (B) | ||
결과: A + "<join>" + B | ||
|
||
약속, (각도)도 회전하기 | ||
회전설정 각도 보여주기 | ||
|
||
약속, (시간)초 동안 (각도)도 회전하기 | ||
(시간설정 시간) 합 (회전설정 각도) 보여주기 | ||
|
||
각도: 45 | ||
시간: 30 | ||
|
||
(3)초 동안 (90)도 회전하기 | ||
3 초 동안 90 도 회전하기 | ||
(3)초 동안 90 도 회전하기 | ||
3 초 동안 (90)도 회전하기 | ||
|
||
시간 초 동안 각도 도 회전하기 | ||
(시간)초 동안 (각도)도 회전하기 | ||
(시간)초 동안 각도 도 회전하기 | ||
시간 초 동안 (각도)도 회전하기 | ||
|
||
(90)도 회전하기 | ||
90 도 회전하기 | ||
각도 도 회전하기 | ||
(각도)도 회전하기 |
12 changes: 12 additions & 0 deletions
12
test/codes/call-function-with-variable-as-argument.yak.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
time:3<join>rotate:90 | ||
time:3<join>rotate:90 | ||
time:3<join>rotate:90 | ||
time:3<join>rotate:90 | ||
time:30<join>rotate:45 | ||
time:30<join>rotate:45 | ||
time:30<join>rotate:45 | ||
time:30<join>rotate:45 | ||
rotate:90 | ||
rotate:90 | ||
rotate:45 | ||
rotate:45 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters