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
5 changes: 5 additions & 0 deletions docs/parity-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ and skips the upstream raw-text fallback. Native and Melange editor tests cover
the option; the delimiter producers are covered in the standalone
[native catalog](../integrations/logseq-native-modes/README.md).

The [Clojure provider](../packages/lang-clojure/README.md) widens the
Nextjournal grammar's symbol and keyword character range for Logseq Web
parity. Its shared Native and Melange fixture verifies UTF-16 spans for BMP
and supplementary symbols and Unicode separators.

### Language data

`packages/language-data` exposes `codemirror-ml.language_data` and the
Expand Down
5 changes: 5 additions & 0 deletions packages/lang-clojure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ escaped-string fix. The highlighting configuration draws on
[@nextjournal/lang-clojure 1.0.0][highlighting]. See
[`LICENSE.nextjournal`](LICENSE.nextjournal).

The generator widens Nextjournal's symbol and keyword rules beyond U+10FF
to match Logseq's Web token boundaries for names such as `全map` and `🚀map`.
Unicode whitespace still separates tokens, including U+FEFF as in the Web
mode. Reader tags and Java constructor names use the original rules.

## Regenerate

Run from the repository root with Node 24.21.0 and npm. Use a disposable
Expand Down
10 changes: 9 additions & 1 deletion packages/lang-clojure/generate_parser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ const {buildParserFile} = npmRequire("@lezer/generator");
const grammar = readFileSync(grammarPath);
assert.equal(createHash("sha256").update(grammar).digest("hex"), digest);

// Symbols and keywords accept Unicode beyond Nextjournal's U+10FF cutoff.
// Keep the non-ASCII std.whitespace characters and U+FEFF as separators.
const symbolCharacters = String.raw`\u{a1}-\u{167f}\u{1681}-\u{1fff}\u{200b}-\u{2027}\u{202a}-\u{202e}\u{2030}-\u{205e}\u{2060}-\u{2fff}\u{3001}-\u{fefe}\u{ff00}-\u{10ffff}`;

// The upstream editor uses custom node props for structural editing. The
// reader parser needs only Lezer's built-in delimiter props.
const source = grammar.toString()
.replace(/^@external prop \w+ from "\.\/props"\r?\n/gm, "")
.replace(/\[(prefixColl|coll|prefixEdge|prefixContainer)\]/g, "")
.replace(/\[sameEdge, /g, "[");
.replace(/\[sameEdge, /g, "[")
.replace(/^ identStart \{.*\}$/m, line =>
line.replace(String.raw`\u{a1}-\u{10ff}`, symbolCharacters))
.replace('whitespace { (std.whitespace | ",")+ }',
String.raw`whitespace { (std.whitespace | "," | "\u{feff}")+ }`);
const {parser} = buildParserFile(source, {fileName: "clojure.grammar"});
const [{tables, bindings}, ...extra] = extractParsers(
input => parse(input, {ecmaVersion: "latest", sourceType: "module", locations: true}),
Expand Down
2 changes: 1 addition & 1 deletion packages/lang-clojure/parser_data.ml

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion packages/lang-clojure/test/test_lang_clojure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ module Highlight = Codemirror_ml_lezer_highlight.Highlight
let () =
let source =
Utf16.of_utf8
{|(defn render [x] {:emoji "🚀" :value #?(:cljs 42 :clj nil)}) ; note
({|(defn render [x] {:emoji "🚀" :value #?(:cljs 42 :clj nil)}) ; note
#_[:ignored 7] #inst "2026" #js {:ok true}|}
^ "\n(全map\u{3000}:色 42) (🚀map\u{feff}nil)")
in
let state =
Editor_state.create ~doc:(Change_set.String source)
Expand Down Expand Up @@ -54,6 +55,11 @@ let () =
(96, 99, "#js", "meta");
(101, 104, ":ok", "atom");
(105, 109, "true", "bool");
(112, 116, "全map", "keyword");
(117, 119, ":色", "atom");
(120, 122, "42", "number");
(125, 130, "🚀map", "keyword");
(131, 134, "nil", "null");
]
in
let actual = List.rev !spans in
Expand Down
Loading