Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ jobs:
runs-on: ubuntu-24.04
timeout-minutes: 45
# The wasm CI image: Rust stable 1.99.1 with the wasm32 targets,
# wasm-bindgen 0.2.127 and binaryen (wasm-opt), which is what
# `comline-simulator`'s `prepack` needs to build its WASM.
# wasm-bindgen 0.2.127, wasm-pack and binaryen (wasm-opt), which is what
# `comline-simulator`'s and `comline-web-kit`'s `prepack`s need to build
# their WASM.
container: ghcr.io/comlineproject/ci-wasm@sha256:74efbad4c8b06d554d28e8a1e486f12ae5b6b4bd15a15db21a0925e020caa40a
steps:
- name: Checkout
Expand All @@ -45,10 +46,11 @@ jobs:
- name: Yarn
run: corepack enable

# `comline-web-kit` (the playground's simulate view) is a git dependency,
# and so is its engine, `comline-simulator`, which compiles to WASM in
# its `prepack` (Rust to wasm-bindgen). The image has cargo, wasm-bindgen
# and wasm-opt; this caches the registry and git checkouts across runs.
# `comline-web-kit` (the playground's editor and simulate view) is a git
# dependency, and so is the sim's engine, `comline-simulator`. Both
# compile to WASM in their `prepack`: the kit builds the editor (the
# compiler and language server) with wasm-pack, the simulator with
# wasm-bindgen. This caches the registry and git checkouts across runs.
- name: Cache cargo
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
Expand All @@ -60,18 +62,19 @@ jobs:

# Yarn Berry's global cache holds the packed `comline-web-kit` and the
# built `comline-simulator` archives: a hit skips the Rust build entirely.
# (`yarn-editor-`: caches from before the tutorial used the editor hold a
# kit packed without it, so they're never restored.)
- name: Cache yarn
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.yarn/berry/cache
key: ${{ runner.os }}-${{ runner.arch }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-${{ runner.arch }}-yarn-
key: ${{ runner.os }}-${{ runner.arch }}-yarn-editor-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-${{ runner.arch }}-yarn-editor-

# Yarn's `npmMinimalAgeGate` (its default, one day) stays on.
- name: Install dependencies
env:
COMLINE_SIMULATOR_SCRIPT: '0' # the tutorial only needs the lean sim
COMLINE_KIT_EDITOR: '0' # and not the kit's editor WASM
run: yarn install

- name: build
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@
},
"type": "module",
"dependencies": {
"@codemirror/lang-javascript": "^6.2.5",
"@codemirror/lang-rust": "^6.0.2",
"@codemirror/language": "^6.10.0",
"@codemirror/state": "^6.4.0",
"@codemirror/view": "^6.34.0",
"@sveltejs/adapter-static": "^3.0.10",
"comline-web-kit": "git+https://github.com/ComlineProject/playground.git#workspace=comline-web-kit&commit=fe53d2edcd25cf8bcd77d9f52a3c2ec09d453136"
"comline-web-kit": "git+https://github.com/ComlineProject/playground.git#workspace=comline-web-kit&commit=f6077cc1a176f1cedd70225e804774e0ca4d00bc"
},
"resolutions": {
"cookie": "^0.7.2",
Expand Down
6 changes: 6 additions & 0 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- The reader's theme (ThemeToggle), applied before the first paint. -->
<script>
try {
if (localStorage.getItem('theme') === 'light') document.documentElement.dataset.theme = 'light';
} catch {}
</script>
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
Expand Down
72 changes: 72 additions & 0 deletions src/lib/editor/Code.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<script lang="ts" module>
type Kind = 'kw' | 'type' | 'str' | 'num' | 'ann' | 'comment' | null;

const KEYWORDS = new Set(['struct', 'enum', 'error', 'protocol', 'function', 'use', 'const']);
const BUILTINS = new Set([
'string', 'bool', 'bytes', 'u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'i32', 'i64', 'f32', 'f64'
]);
const TOKEN = /(\/\/.*$)|("(?:[^"\\]|\\.)*")|(@\w+)|(\b\d+\b)|([A-Za-z_]\w*)|(\s+|.)/gm;

/** Splits a schema snippet into runs, each with what it is. A fragment
* (`age: u8`) needn't parse, so this goes by the shape of each word, and
* a capitalised name counts as a type. */
function tokenize(src: string): { text: string; kind: Kind }[] {
const out: { text: string; kind: Kind }[] = [];
for (const m of src.matchAll(TOKEN)) {
const [text, comment, str, ann, num, word] = m;
let kind: Kind = null;
if (comment) kind = 'comment';
else if (str) kind = 'str';
else if (ann) kind = 'ann';
else if (num) kind = 'num';
else if (word && KEYWORDS.has(word)) kind = 'kw';
else if (word && (BUILTINS.has(word) || /^[A-Z]/.test(word))) kind = 'type';
out.push({ text, kind });
}
return out;
}
</script>

<script lang="ts">
// Inline Comline in lesson text, coloured as the schema editor colours it.
let { src }: { src: string } = $props();
const tokens = $derived(tokenize(src));
</script>

<code class="schema">{#each tokens as t, i (i)}<span class={t.kind ? `tok-${t.kind}` : undefined}
>{t.text}</span
>{/each}</code
>

<style>
/* The schema editor's colours (global.css's --tok-*). */
.schema {
padding: 1px 4px;
font-family: ui-monospace, monospace;
font-size: 0.9em;
color: var(--fg);
background: var(--panel-bg);
border: 1px solid var(--border);
border-radius: 3px;
white-space: nowrap;
}
.tok-kw {
color: var(--tok-kw);
}
.tok-type {
color: var(--tok-type);
}
.tok-str {
color: var(--tok-str);
}
.tok-num {
color: var(--tok-num);
}
.tok-ann {
color: var(--tok-ann);
}
.tok-comment {
color: var(--tok-comment);
font-style: italic;
}
</style>
Loading
Loading