Options for creating an extension for a very simple language

I am hoping to create an extension to let me edit and autocomplete mods for a game. It has a fairly small list of commands and a very simple format.

It is so simple that even creating a Regex Grammar for it is overkill. Tree Sitter would be overkill in a Mortal Combat sense of the word.

Are there any options in Nova for adding autocomplete and theming without building an entire language extension?

As an example here is a small sample for a mod

level 1
levelreq 1
levelup 2
newrit 2
promotion 1
rebateterr20 -1102
soundfx 57
cost 12 60
terr -1
free

The game has no console tools or feedback so if you have a typo in the mod it just won’t work and you don’t know why. Hence the need for some for of autocompletion.

Anyone have any ideas or perhaps a link to a language extension for a similarly simple language?

Thanks

Hey @pixelgeek is this an actual documented language if so can we have a link to it? what is the file extension and syntax usually?
Thanks
Emran :slight_smile:

“Language” might be a stretch. The sample I posted is typically how the code looks. They are lists of features and values for a game item or event.

The docs are available in PDF format

The file extension is .c5m

I am looking at a Language Syntax extension for assembly language that might be useful as a starting point

Well I have a very basis file working(ish)

CleanShot 2023-08-17 at 16.17.37

So, in terms of theming/syntax highlighting you are out of luck without tree-sitter grammar.

If you ever decide to create a grammar, definately avoid the RegEx. That one is certainly dead and soon will be totally removed from Nova :coffin:. Would just be a waste of your time

However for autcompletion…
It all depends. So the simplest, which might be very well fit for purpose for you, considering you managed to create a Syntax that recognizes the CoE5 is creating a Clips extension.

Option 1 Clips Extension:

  1. Head over to menubar > extensions > create new extension > Clips
  2. Now this will create a dummy Clips file
{
  "clips" : [
    {
      "content" : "$AUTHOR_NAME",
      "name" : "User Signature",
      "trigger" : "usersig"
    },
    {
      "name" : "Group Name",
      "children" : [
        {
          "content" : "console.log(${:message})",
          "name" : "Console Log",
          "scope" : "editor",
          "shortcut" : "cmd-alt-shift-l",
          "syntax" : "javascript",
          "trigger" : "log"
        }
      ]
    }
  ]
}

  1. I would say just add a Clips.json in the project you managed to get the syntax.xml working, and you will be good to go filling it up.
  2. You can see you can organise your syntax into groups
  3. Also set the "syntax" : "CoE5" so that in only shows in that file.

The only problem is that Clips is not documented at all :expressionless: However it is sort of self explanatory using the template. Just activate extension and play around in an HTML and JS file to get an idea. You can also head to sidebar to see the snippets, appearing in the clip under the extension tab. The snippet formating are documented here

image

Option 2 XML based Completion:

As you have managed to get Nova recognise the CoE5. You could simply create XML based completions. Now this one is a bit more involved.

  1. You would just need to worry about sorting
    • <syntax>
    • maybe <trigger>
    • <expression>
  2. Then write your static completion
  3. Request them using <set> in the <provider>

Problem with both approach:

I initially I thought you could have a flexibility with the XML based one, but I should say both are pretty similar if you do not use any grammar. What I mean by that is context aware completion. I thought you could maybe use Lookarounds in the <expression> for the XML completion and only provide values that are specific to a command. Unfortunately that is not supported. (I did not know that myself!)

//Example
init <nbr>
Initiative value for the weapon, default is 2. Some common
initiative values are these 1=spell, 2=fist/dagger/bow,
3=club/axe, 4=sword, 6=spear

For example only providing 1,2,3,4,5,6 as values for the init command. I personally dont see a way for you to restrict the values. Maybe you could just create snippets, and associate a name for them to fill for you. ie, init1 and it just expands to init 1 and so forth? I think Clips will be a better option with no grammar.

Tree-Sitter

This is a very simple command value syntax, with no injection no nothing. writing a tree-sitter for it would be a piece of cake. The only problem is the tree-sitter docs learning curve. I personally did not find it friendly at all when I was writing a grammar myself. lots of tears and pulling hair! but in your case it should be super easy! :+1:

There would be two benefits

  1. you can sort the syntax highlighting
  2. You can target a node and provide a completion just for that node! I played around with it and it for my project and it is very cool. You could just write a simple grammer that recognises command value.
  3. After that, all you have to do, is to name your nodes and then target them inside the <query> see docs, then filter the completions sets, provided based on the string value of the typed command using the predicates and captures! Now that would be cool eh? [:warning:rabbit hole warning :warning:] :eyes:

I hope that was helpful!
I personally would just keep the current working syntax.xml and add the Clips.json targeting CoE5, then see how you get on before going for anything overkill! good luck!

1 Like

Wow! That was all very useful. Thanks.

I will have a look at how simple it is to create a tree-sitter grammar. As you mentioned, it is extensively documented but really lacks a few “how-to” articles that walk you through the process.