npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@exercism/codemirror-lang-yamlscript

v1.0.2

Published

YAMLScript language support for CodeMirror

Readme

YAMLScript language support for CodeMirror

NPM Version

This repo contains the CodeMirror 6 language support for YAMLScript (YS), the language taught on Exercism's YAMLScript track. It has a Lezer grammar, highlighting, indentation, folding and autocomplete.

How the grammar works

A YAMLScript file is a YAML document in which the keys and values are code, as in defn score(x y): or if x > 0: 'positive'. So the grammar has two layers:

  • The external tokenizers in src/tokens.ts handle the YAML layer. They track indentation, decide which lines are mapping keys (a line with : outside quotes and brackets), and read block scalars and data-mode text.
  • src/syntax.grammar describes the YAMLScript code inside keys and values: calls, . and : chains, infix operators, operator-first lists such as (+ a b), literals and collections.

After :: (or =::), a value is data, and plain text such as north is a string. Another :: inside data switches back to code.

The rules follow Exercism's tree-sitter grammar for YAMLScript, which is used by the representer.

Autocomplete

The completion offers:

  • the functions in YAMLScript's ys::std library, and the clojure.core names that can be called from YAMLScript.
  • snippets for defn, defn-, fn, if, when, cond, each, for, loop and =:, and the !YS-v0 header at the start of a file.
  • the functions and bindings defined in the file, where they are in scope. Top-level defn names and bindings are offered everywhere. A function's parameters, the bindings in a block, and the names bound by loop, for, each, let and fn are offered inside them.

Completion switches off inside strings, comments, regular expressions and data-mode text, and while a new function name or parameter is being typed.

What it doesn't parse yet

  • YAML flow mappings with : inside braces, such as {a: 1}.
  • YAML anchors, aliases and document markers (---, ...).
  • Tags such as !code and !data parse as tags, and leave the mode as it is. Only :: switches between code and data.
  • String interpolation ("$name") is part of the string, so names inside strings aren't completed or highlighted.

⚠️ To ensure that the package can be integrated on the Exercism website, don't change the packages' versions:

"@codemirror/language": "^6.10.1",
"@lezer/highlight": "^1.2.0",
"@lezer/lr": "^1.4.0"

Install

  • NPM: npm install @exercism/codemirror-lang-yamlscript
  • Yarn: yarn add @exercism/codemirror-lang-yamlscript
  • Bun: bun add @exercism/codemirror-lang-yamlscript

Usage

import { EditorView, basicSetup } from "codemirror";
import { yamlscript } from "@exercism/codemirror-lang-yamlscript";

new EditorView({
  doc: "!YS-v0\n\ndefn square(x): x * x\n",
  extensions: [basicSetup, yamlscript()],
  parent: document.querySelector("#editor"),
});

Prerequisites

Resources

Structure

The repo's source files are written in TypeScript.

The repo is structured as follows:

.
├── src
│   ├── index.ts (the main plugin)
│   ├── complete.ts (the completion sources)
│   ├── builtins.ts (the ys::std and clojure.core names)
│   ├── tokens.ts (the tokenizers for the YAML layer)
│   ├── syntax.grammar (the Lezer grammar)
│   ├── syntax.grammar.d.ts (the grammar typings)
│   └── syntax.grammar.terms.d.ts (the typings for the grammar's terms)
├── test
│   ├── cases (test cases)
│   │   └ *.txt (test case)
│   ├── grammar.test.ts (the grammar tests)
│   ├── editor.test.ts (the highlighting, indentation and folding tests)
│   └── completion.test.ts (the completion tests)
├── index.html (dev server file)
├── rollup.config.js (bundling config)
├── tsconfig.json (TypeScript config)
└── vite.config.js (vite dev server config)

Setup

Run bun install to install all dependencies.

Developing

To help with development, run bun run dev. This starts a Vite dev server (usually at http://localhost:5173/) that renders the index.html file. The #editor element holds some sample source code of your choosing, which the grammar in src/syntax.grammar highlights. Any changes to the grammar will auto-refresh the dev server's rendered contents.

Building

Run bun run prepare to build the package into dist. bun install also runs this script.

Testing

The test/cases directory contains the grammar's test files. The grammar uses the tokenizers in src/tokens.ts, so the tests use the built parser in dist/. Run bun run test to build the package and run the tests.

Note: test (case) files should be relatively small and focus on a single aspect of a grammar.

Publishing

To publish a new version, set version in package.json and commit it. Then push a git tag named v followed by that version, such as v1.0.1 for version 1.0.1. The publish workflow builds and tests the package, then publishes it to npm.