diff --git a/docs/.vitepress/components/CodeSampleSelector.vue b/docs/.vitepress/components/CodeSampleSelector.vue new file mode 100644 index 0000000..434b28a --- /dev/null +++ b/docs/.vitepress/components/CodeSampleSelector.vue @@ -0,0 +1,68 @@ + + + + + \ No newline at end of file diff --git a/docs/.vitepress/components/Console.vue b/docs/.vitepress/components/Console.vue new file mode 100644 index 0000000..d3ece3d --- /dev/null +++ b/docs/.vitepress/components/Console.vue @@ -0,0 +1,30 @@ + + + + + \ No newline at end of file diff --git a/docs/.vitepress/components/Editor.vue b/docs/.vitepress/components/Editor.vue index ca87890..30426e2 100644 --- a/docs/.vitepress/components/Editor.vue +++ b/docs/.vitepress/components/Editor.vue @@ -1,6 +1,6 @@ + + + + \ No newline at end of file diff --git a/docs/.vitepress/data/playground/PlaygroundSamples.data.ts b/docs/.vitepress/data/playground/PlaygroundSamples.data.ts new file mode 100644 index 0000000..958201c --- /dev/null +++ b/docs/.vitepress/data/playground/PlaygroundSamples.data.ts @@ -0,0 +1,62 @@ +import {defineLoader} from 'vitepress' +import {readFile} from 'node:fs/promises' +import {basename, parse} from 'node:path' + +interface SampleData { + chapter: string, + name: string, + code: string, +} + +interface Sample { + name: string, + code: string, +} + +interface Chapter { + name: string + samples: Sample[] +} + +export interface Data { + chapters: Chapter[] +} + +declare const data: Data +export {data} + +export default defineLoader({ + watch: ['./samples/**/*.fk'], + async load(watchedFiles): Promise { + const sampleData = await Promise.all(watchedFiles.map(loadSample)) + const chapterMap = new Map(); + for (const sd of sampleData) { + const key = sd.chapter + if (!chapterMap.has(key)) { + chapterMap.set(key, { + name: key, + samples: [] + }) + } + + const chapter = chapterMap.get(key)! + chapter.samples.push(sd) + } + + return {chapters: Array.from(chapterMap.values())} + } +}) + +async function loadSample(path: string): Promise { + const code = await readFile(path, 'utf-8') + + const parsedPath = parse(path) + const sampleName = parsedPath.name + const chapterName = basename(parsedPath.dir) + + return { + chapter: chapterName, + name: sampleName, + code + } +} \ No newline at end of file diff --git a/docs/.vitepress/data/playground/samples/function/closure.fk b/docs/.vitepress/data/playground/samples/function/closure.fk new file mode 100644 index 0000000..7683553 --- /dev/null +++ b/docs/.vitepress/data/playground/samples/function/closure.fk @@ -0,0 +1,12 @@ +let cnt = 0; + +let add = fn() { + cnt = cnt + 1; + cnt; +}; + +print(add()); +print("\n"); +print(add()); +print("\n"); +print(add()); \ No newline at end of file diff --git a/docs/.vitepress/data/playground/samples/hello-world/hello-world.fk b/docs/.vitepress/data/playground/samples/hello-world/hello-world.fk new file mode 100644 index 0000000..dfe80e8 --- /dev/null +++ b/docs/.vitepress/data/playground/samples/hello-world/hello-world.fk @@ -0,0 +1 @@ +print("Hello World"); \ No newline at end of file diff --git a/docs/.vitepress/data/playground/samples/loop/nine-nine-multiplication-table.fk b/docs/.vitepress/data/playground/samples/loop/nine-nine-multiplication-table.fk new file mode 100644 index 0000000..9f813d6 --- /dev/null +++ b/docs/.vitepress/data/playground/samples/loop/nine-nine-multiplication-table.fk @@ -0,0 +1,11 @@ +for (let i = 1; i < 10; i = i + 1) { + for (let j = 1; j <= i; j = j + 1) { + print(j); + print("*"); + print(i); + print("="); + print(j*i); + print(" "); + } + print("\n"); +} \ No newline at end of file