@codincod/codemirror-lang-julia
v0.1.1
Published
Julia language support for the CodeMirror code editor
Maintainers
Readme
@codincod/codemirror-lang-julia
This package implements Julia language support for the CodeMirror code editor, using the Lezer grammar Andrey Popp and the Pluto.jl contributors wrote for @plutojl/lezer-julia, with the parse fixes below on top of it. The editor half comes from @plutojl/lang-julia; the two are merged here so that one package holds the grammar and the language support that has to move with it.
Written in part for CodinCod, a competitive coding platform, where it colours the editor people solve puzzles in.
This code is released under an MIT license.
Usage
import {EditorView, basicSetup} from "codemirror"
import {julia} from "@codincod/codemirror-lang-julia"
const view = new EditorView({
parent: document.body,
doc: `function collatz(n::Int)
steps = 0
while n != 1
n = iseven(n) ? n ÷ 2 : 3n + 1
steps += 1
end
return steps
end
`,
extensions: [basicSetup, julia()],
})API Reference
- julia(config?: {enableKeywordCompletion?: boolean}) → LanguageSupport
- juliaLanguage: Language
- keywordCompletion: Extension
- parser: LRParser
What changed
On 19549 files of published Julia from 2947 repositories, sieved by Julia's
own parser, the share parsing with no error node goes from 94.71% under
@plutojl/lezer-julia 1.2.0 to 99.20%. On the 1197 files Julia 1.12 ships
in base, stdlib, Compiler and test, it goes from 84.13% to
98.08%. None of the corpus ships here; it is other people's code.
The parse fixes, each found by measuring against that corpus and against Julia's
own base and stdlib, are listed in the changelog. Besides them:
- A block folds, from the end of the line it opens on to the line of its
end. Upstream had no folding. - A call's name is coloured as a function. The rule upstream named a node the grammar never produces.
Measuring it
The grammar is measured against real Julia with
lezer-survey, which has to sit
beside this directory, and against a corpus at ../julia-corpus:
npm run harvest # build the corpus: code search, clone, sieve with JuliaSyntax
npm run clean # sieve an existing corpus again
npm run measure # the share of files with no error node
npm run stdlib # the same over the Julia installed here: base, stdlib, Compiler, test
npm run gaps # what is left, grouped by shapeThe sieve is tools/read.jl, which hands each file to JuliaSyntax.parseall
and evaluates nothing. A file Julia will not parse is not a file the grammar
should be measured on.
