codemirror / lang-example

Example/template repository for building a language package
MIT License
69 stars 43 forks source link

I am having trouble loading my language. I believe my language plugin is in error. #18

Closed StoneCypher closed 2 years ago

StoneCypher commented 2 years ago

I'm trying to create an FSL language plugin for CodeMirror.

I have a decent set of test cases that cover the basic common sense first steps of the language. It appears to parse happily, and the way that I expect.

> mocha test/test.js

  cases
    ✔ Simple arrow statements between atoms
    ✔ Simple arrow statements between strings
    ✔ Simple arrow statements mixed between atoms and strings
    ✔ Simple arrow statements using list spread
    ✔ Simple arrow statements over various arrow types
    ✔ Simple arrow chains
    ✔ Left Actions
    ✔ Right Actions
    ✔ Both Actions
    ✔ Empty state claim
    ✔ Active state claim
    ✔ Line Comment
    ✔ Machine Author attribute
    ✔ Machine Contributor attribute
    ✔ Machine Comment attribute
    ✔ Machine Definition attribute
    ✔ Machine Name attribute
    ✔ Machine Reference attribute
    ✔ Machine Version attribute
    ✔ Machine License attribute
    ✔ Machine Language attribute
    ✔ FSL Version attribute
    ✔ Theme attribute
    ✔ Hooks attribute
    ✔ DOT Preamble attribute
    ✔ Real program

  26 passing (20ms)

I was trying to add a demo editor. The editor itself works: it has the characteristic CodeMirror appearance, the line highlight moves with the cursor, braces and parentheses match, et cetera.

However, it's treating the text as if it was plain text. The language itself isn't being invoked.

I do not believe that it's a question of the language being recognized and going unstyled. In the browser inspector, in j mode, there are spans in common sense places to apply styling. There are none where I'd expect for my language; only rows.

I believe the editor invocation is correct because if I install the j language plugin and switch to that, J code highlights as expected.

image

It's not clear to me what I could do wrong, that the test cases would pass, but a working editor would not adopt my language plugin.

I've done my best to stay within the vanilla guidelines of your lang example. Most of the code is unchanged, and the grammar is currently very simple.

There are no errors in the console.

All three of these breakpoints land:

image

I was hoping to ask for help? I can't find a discord or an irc channel, and I'm not sure what to do next.

marijnh commented 2 years ago

I was hoping to ask for help? I can't find a discord or an irc channel, and I'm not sure what to do next.

There's a forum for this kind of thing.

Language tests tend to test for parse structure. In-editor highlighting also requires highlight tags to be set up correctly. Do the names in your styleTags call match the node names in the syntax tree? Are you actually using any of those styled nodes in your test editor?

StoneCypher commented 2 years ago

Do the names in your styleTags call match the node names in the syntax tree?

They do.

Are you actually using any of those styled nodes in your test editor?

Yes.

StoneCypher commented 2 years ago

In case someone else finds this, the problem was simple. CodeMirror only highlights the topmost, exposed rule.

Unfortunately, my language needs a superior rule to disambiguate between barewords and keywords, which in my highlighter is called "Chain," so I don't know how to highlight the things it's made from. If I assign a color to Chain it works as expected. The problem was that I was trying to highlight String, Atom, Arrow, and so on, and the editor isn't distinguishing those.

As far as I can tell, the things beneath the top level production aren't actually exposed, even if they're capitalized. I don't really understand how that can be the case; I would have expected it to highlight all the way down through the rule to its subordinate pieces, so that an expr could have strings and numbers inside, or what have you.

marijnh commented 2 years ago

Maybe the /... notation in styleTags is what you're looking for?

StoneCypher commented 2 years ago

Hm. It seems like it ought to be, but also, I'm not able to make that work out.

I did as you asked, and made a forum thread (although I see you responded there as well.) I'll consolidate there.

https://discuss.codemirror.net/t/novice-trying-to-write-a-highlighter-stuck-on-disambiguation-and-token-depth-possibly-misunderstanding/5044/2