Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
FineArchs committed Nov 12, 2023
1 parent c345e9b commit 608e485
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 74 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
過去バージョンのAiScriptに対応したAiScript Playground。
ページ上部のバージョン名部分をクリックすることで切り替えられる。
ページ上部のバージョン名部分をクリックすることで切り替えられる。

## for developers

`git clone`の後、`npm install`の前に`npm run submodules`を実行すること。
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "vue-tsc && vite build",
"serve": "vite preview",
"preinstall": "npm run build-develop && npm run build-next",
"prettier": "npx prettier . --write",
"submodules": "git submodule update --init --depth=1",
"build-develop": "cd develop && npm ci && npm run build",
"build-next": "cd next && npm ci && npm run build",
Expand Down
30 changes: 15 additions & 15 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<template>
<div id='wrapper'>
<h1>
AiScript (
<MenuButton id="version" :options="menu" @select="onVersionSelect">{{
version
}}</MenuButton>
) Playground
</h1>
<div v-for='v in versions'>
<MainArea :ver='v' v-if='v==version'/>
</div>
</div>
<div id="wrapper">
<h1>
AiScript (
<MenuButton id="version" :options="menu" @select="onVersionSelect">{{
version
}}</MenuButton>
) Playground
</h1>
<div v-for="v in versions">
<MainArea :ver="v" v-if="v == version" />
</div>
</div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import MainArea, { versions, latest } from './MainArea.vue';
import MainArea, { versions, latest } from "./MainArea.vue";
import MenuButton from "@common/MenuButton.vue";
const version = ref(window.localStorage.getItem("version") ?? latest);
Expand All @@ -41,7 +41,7 @@ function onVersionSelect(v: string) {
Menlo,
Courier,
monospace;
box-sizing: border-box;
box-sizing: border-box;
}
html {
Expand All @@ -58,7 +58,7 @@ body {

<style scoped>
#wrapper {
padding: 16px;
padding: 16px;
}
h1 {
font-size: 1.5em;
Expand Down
66 changes: 38 additions & 28 deletions src/MainArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@
</template>

<script lang="ts">
export const versions = ["next", "develop", "0.16.0", "0.15.0", "0.14.1"] as const;
export const versions = [
"next",
"develop",
"0.16.0",
"0.15.0",
"0.14.1",
] as const;
export const latest = "0.16.0" as const;
export type Log = {
id: number;
type?: string;
text?: string;
print?: boolean;
}
id: number;
type?: string;
text?: string;
print?: boolean;
};
</script>
<script setup lang="ts">
import { ref, watch } from "vue";
Expand All @@ -56,22 +62,22 @@ import * as V0_15_0 from "@/versions/0.15.0/index.ts";
import * as V0_14_1 from "@/versions/0.14.1/index.ts";
const props = defineProps<{
ver: typeof versions[number];
ver: (typeof versions)[number];
}>();
const { parse, exec, version, samples } = {
'next': Next,
'develop': Develop,
'0.16.0': V0_16_0,
'0.15.0': V0_15_0,
'0.14.1': V0_14_1,
next: Next,
develop: Develop,
"0.16.0": V0_16_0,
"0.15.0": V0_15_0,
"0.14.1": V0_14_1,
}[props.ver];
const script = ref(
window.localStorage.getItem(version) ?? '<: "Hello, AiScript!"',
);
const logs = ref<Log[]>([]);
const ast = ref<string>('');
const ast = ref<string>("");
const syntaxErrorMessage = ref<string | null>(null);
watch(
Expand All @@ -87,23 +93,25 @@ watch(
console.error("info" in err ? err.info : err);
return;
}
}, { immediate: true, }
},
{ immediate: true },
);
function run() {
logs.value = [];
exec({
in: (q: string) => new Promise((ok) => {
const res = window.prompt(q);
ok(res ?? "");
}),
out: (l: Log) => logs.value.push(l),
end: (l: Log) => logs.value.push(l),
err: (e: any) => {
console.error(e);
window.alert(`{e}`);
}
});
exec({
in: (q: string) =>
new Promise((ok) => {
const res = window.prompt(q);
ok(res ?? "");
}),
out: (l: Log) => logs.value.push(l),
end: (l: Log) => logs.value.push(l),
err: (e: any) => {
console.error(e);
window.alert(`{e}`);
},
});
}
</script>

Expand All @@ -119,14 +127,16 @@ pre {
gap: 16px;
}
#grid1, #grid2 {
#grid1,
#grid2 {
box-sizing: border-box;
flex: 1;
display: grid;
gap: 16px;
min-height: 0;
}
#grid1 > *, #grid2 > * {
#grid1 > *,
#grid2 > * {
min-height: 0;
}
#grid1 {
Expand Down
20 changes: 10 additions & 10 deletions src/versions/0.14.1/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { Interpreter, Parser, values, utils, Ast } from "./version.ts";
import { version, samples } from "./version.ts";
import type { Log } from '@/MainArea.vue';
import type { Log } from "@/MainArea.vue";

export { version, samples };

let ast: Ast.Node[] = [];
let interpreter: Interpreter | null = null;

export function parse(code: string): string {
ast = Parser.parse(code);
return JSON.stringify(ast, null, "\t");
ast = Parser.parse(code);
return JSON.stringify(ast, null, "\t");
}

export async function exec(io: {
in: (q: string) => Promise<string>;
out: (l: Log) => void;
end: (l: Log) => void;
err: (e: any) => void;
in: (q: string) => Promise<string>;
out: (l: Log) => void;
end: (l: Log) => void;
err: (e: any) => void;
}): Promise<void> {
interpreter?.abort();
interpreter = new Interpreter(
{},
{
in: io.in,
in: io.in,
out: (value: values.Value) => {
io.out({
id: Math.random(),
Expand Down Expand Up @@ -50,6 +50,6 @@ export async function exec(io: {
try {
await interpreter.exec(ast);
} catch (e) {
io.err(e);
io.err(e);
}
};
}
20 changes: 10 additions & 10 deletions src/versions/0.15.0/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { Interpreter, Parser, values, utils, Ast } from "./version.ts";
import { version, samples } from "./version.ts";
import type { Log } from '@/MainArea.vue';
import type { Log } from "@/MainArea.vue";

export { version, samples };

let ast: Ast.Node[] = [];
let interpreter: Interpreter | null = null;

export function parse(code: string): string {
ast = Parser.parse(code);
return JSON.stringify(ast, null, "\t");
ast = Parser.parse(code);
return JSON.stringify(ast, null, "\t");
}

export async function exec(io: {
in: (q: string) => Promise<string>;
out: (l: Log) => void;
end: (l: Log) => void;
err: (e: any) => void;
in: (q: string) => Promise<string>;
out: (l: Log) => void;
end: (l: Log) => void;
err: (e: any) => void;
}): Promise<void> {
interpreter?.abort();
interpreter = new Interpreter(
{},
{
in: io.in,
in: io.in,
out: (value: values.Value) => {
io.out({
id: Math.random(),
Expand Down Expand Up @@ -50,6 +50,6 @@ export async function exec(io: {
try {
await interpreter.exec(ast);
} catch (e) {
io.err(e);
io.err(e);
}
};
}
20 changes: 10 additions & 10 deletions src/versions/0.16.0/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { Interpreter, Parser, values, utils, Ast } from "./version.ts";
import { version, samples } from "./version.ts";
import type { Log } from '@/MainArea.vue';
import type { Log } from "@/MainArea.vue";

export { version, samples };

let ast: Ast.Node[] = [];
let interpreter: Interpreter | null = null;

export function parse(code: string): string {
ast = Parser.parse(code);
return JSON.stringify(ast, null, "\t");
ast = Parser.parse(code);
return JSON.stringify(ast, null, "\t");
}

export async function exec(io: {
in: (q: string) => Promise<string>;
out: (l: Log) => void;
end: (l: Log) => void;
err: (e: any) => void;
in: (q: string) => Promise<string>;
out: (l: Log) => void;
end: (l: Log) => void;
err: (e: any) => void;
}): Promise<void> {
interpreter?.abort();
interpreter = new Interpreter(
{},
{
in: io.in,
in: io.in,
out: (value: values.Value) => {
io.out({
id: Math.random(),
Expand Down Expand Up @@ -51,6 +51,6 @@ export async function exec(io: {
try {
await interpreter.exec(ast);
} catch (e) {
io.err(e);
io.err(e);
}
};
}

0 comments on commit 608e485

Please sign in to comment.