Syntax highlighting?

cm5 is plain old JavaScript, easy peasy, whereas cm6 is es6 module based, and I found it completely impossible to set up a development environment for that.
The exercism site has recently upgraded to cm6 - cm5 code may still be usable on that via “legacy mode”, or it may need changing such that rather than start as it does now with

(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
    mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
    define(["../../lib/codemirror"], mod);
else // Plain browser env
    mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

CodeMirror.defineMode("phix", function(config) {...

to something a bit more like

import { parser } from '@lezer/phix';
import { EditorSelection } from '@codemirror/state';
import { EditorView } from '@codemirror/view';
export const phixLanguage = LRLanguage.define({...

presumably bundled and published on npm, but someone else would have to do that.

(For clarity, we’ve always been CM6 :slight_smile:)

@dem4ron @ErikSchierboom Maybe you could chime in about how we can use the CM5 parsers pls as I’m pretty sure we do that elsewhere?

@iHiD I think we can just wrap it into something like:

const { vb } = await import('@codemirror/legacy-modes/mode/vb')
return compartment.of(StreamLanguage.define(vb))

@petelomax if you manage to publish an NPM package, I’ll be happy to check it out.

1 Like

Unfortunately that is way beyond my abilities. I have published precisely one npm package and that took me 13 months (by which I mean after the “it all works here, what now” moment), without even involving rollup/webpack or whatever, and all I can remember is the final steps are something like “npm run prepare” followed by “npm publish” but there are so many many many steps missing before that.

The only thing I can offer is this one file (and probably far less usefully the cm5\test.htm linked above)

PS: At the very end of that file I’ve commented out 3 lines that might want un-commenting for the benefit of the online exercism editor. They didn’t do any harm, but didn’t seem to help, though I mave have missed something on the “interactive” side, and for Euphoria the lineComment should be “–” (two minuses) instead of “//”, which makes no difference to Phix. (those changes have now been made to the repo below)

Oh, I don’t know if I’ll have the time to work on that (probably not). Maybe someone else from the community can help?

If you just copy/paste an existing repo it should be quite straight-forward.

e.g. Take GitHub - ianwalter/codemirror-mode-elixir: A CodeMirror mode for the Elixir language and replace the word elixir with euphoria etc, and update codemirror-mode-elixir/index.js at master · ianwalter/codemirror-mode-elixir · GitHub with exercism-phix/phix.js at main · petelomax/exercism-phix · GitHub with your

We can then host/publish it for you.

OK, GitHub - petelomax/codemirror-mode-phix: A CodeMirror mode for the Phix language created, good luck :smile:.

UPDATE: probably incompatible with v6, see below

1 Like

Thanks! @ErikSchierboom Could you create a copy of this under the Exercism org and then publish from there to NPM please?

Copy created: GitHub - exercism/codemirror-lang-phix
Note: I’ve change the name to codemirror-lang-phix, to align with existing repo names: Repositories · GitHub

I’m trying to fix some package issues.

@petelomax BTW, you mentioned you hard a hard time with CodeMirror 6. Did you see this repo: GitHub - exercism/codemirror-lang-elixir: CodeMirror 6 mode for Elixir? It’s index.js file looks very similar to yours and that one is using CodeMirror 6.

First version has been pushed:

npm notice Publishing to https://registry.npmjs.org/ with tag latest and public access
+ @exercism/codemirror-mode-phix@0.1.0

Now I have to do some testing.

edit: it’s hard to test without any actual exercises :)

Try it on euphoria. The languages are very closely related

I did see that, but struggled to test it. However it looks much simpler (no vue) and that readme suggests the one above is not compatible with v6, so I’ve quickly knocked up GitHub - petelomax/codemirror-lang-phix: A CodeMirror mode for the Phix language. I’ll try and copy over some exercises today. I’ve just pushed hello-world.

1 Like

(nevermind !) - hello-world and acronym now all seem fine.

Once I got ci working I uploaded them in batches and they’re all up now, apart from two broken (/multithreading) ones which were immediately yanked.

1 Like