Author Topic: Adding new language to SE  (Read 1422 times)

asandler

  • Senior Community Member
  • Posts: 289
  • Hero Points: 25
Adding new language to SE
« on: May 12, 2018, 06:07:20 pm »
I am trying to add support for TLA+. I found this:
http://blog.slickedit.com/2008/05/tutorial-adding-language-support-to-slickedit/
How accurate this information, today? For example Step 5 refers to _CreateLanguage(), but I don't see this function used anywhere else. I've modified the code a little, leaving only defload(). It did add new language and new file extension, but Color Coding information is empty? Am I doing something wrong?
Thanks

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4558
  • Hero Points: 352
Re: Adding new language to SE
« Reply #1 on: May 13, 2018, 01:56:47 am »
If you want to add a language and color coding for the language, it’s easier to just use the GUI for both of these. You only need to write macro code for tagging and smart indenting.

I haven’t checked the _CreateLanguage function to see if it correctly converts the language options string. The color coding dialog has an import button which supports loading the old VLX profiles if you have one. That format is no where near as powerful as the new color coding XML format.

asandler

  • Senior Community Member
  • Posts: 289
  • Hero Points: 25
Re: Adding new language to SE
« Reply #2 on: May 13, 2018, 12:34:20 pm »
Two follow up questions:
1. What is the most convenient way to export (and import) new language that I added via UI?
2. Is there a simple language that I can reverse engineer to understand how to add new language programmatically (for the sake of tagging and smart indenting)? Presumably if I look at how C or C++ is implemented, it would have too many details, so I need something more compact that I can read.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4558
  • Hero Points: 352
Re: Adding new language to SE
« Reply #3 on: May 13, 2018, 03:11:54 pm »
Use export and choose to export just your new language settings. Importing your support will take two steps. First use import to import what you exported. Then load your macro file support. In the future, you will be able to package this stuff as a plugin and load them in one step.

Adding really good smart editing support is pretty difficult. There isn’t a perfect sample that’s right for all languages for sure. For example, a language like scala where statements are rarely terminated with a semicolon are almost impossible to implement smart indenting without a full statement parser. With a full statement parser, it’s easy. Easier than C++. Writing a full parser like this is a large task even for us.

Is this language very similar to any other language SlickEdit already has support for?

asandler

  • Senior Community Member
  • Posts: 289
  • Hero Points: 25
Re: Adding new language to SE
« Reply #4 on: May 13, 2018, 11:54:59 pm »
Quote
Is this language very similar to any other language SlickEdit already has support for?

To some extent. It's a weird mixture of TeX, some very special set of operators and a bunch of key words like VARIABLE, CONSTANT.
Here's a short example: https://github.com/tlaplus/Examples/blob/master/specifications/SpecifyingSystems/FIFO/Channel.tla
There are many other examples in this repository.
It might be interesting to be able to navigate to predicates defined with '==' operator. I.e. in the example above, to be able to go from inside of Next to Send(d).

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4558
  • Hero Points: 352
Re: Adding new language to SE
« Reply #5 on: May 14, 2018, 01:15:10 am »
This language is quite a bit different. Looks like it’s two languages (PlusCal and TLA+). I think you need to define support for two languages to do this right. That way PlusCal is simply an embedded language referenced by your TLA+ color coding profile. The color coding for this isn’t hard to do once you know this trick. Define two color coding profiles and have TLA+ reference the other. If you get that far, I can give you pictures of the GUI color coding settings for defining “(* —“ ... ”*)” which will reference the PlusCal color coding profile.

I think the pascal smart indenting may be the best example for PlusCal (see pascal_enter and pascal_space). Since TLA+ doesn’t have an easy statement terminator, there really won’t be any sample code that will help a lot. You could do nothing or gut the pascal code and search for an operator to indent when you press enter.

For tagging, it’s definitely possible to pick up some symbols with regex searches in a proc_search function. You’ve got two languages here though.

asandler

  • Senior Community Member
  • Posts: 289
  • Hero Points: 25
Re: Adding new language to SE
« Reply #6 on: May 15, 2018, 12:23:04 am »
I am not particularly interested in PlusCal. It is more programmer friendly language than TLA+, but all it allows you to do is to generate TLA+ spec for your model. I am writing in TLA+ directly.

If you were ever to officially support TLA+, you'd probably have to support PlusCal as well.

Thanks for the tip regarding Pascal. I'll take a look.

b

  • Senior Community Member
  • Posts: 261
  • Hero Points: 24
Re: Adding new language to SE
« Reply #7 on: July 25, 2018, 06:04:35 pm »
I'm looking to add support for the MIPS assembler.  It appears that there are already references to the assembler, but there is no direct document type.  The xc compiler (Microchip/gcc derivative) on Windows uses the .S extension, which can run through the gcc preprocessor.  Is there an existing type that correctly handles the tagging and preprocessing?  If I need to derive a new document type (to add the keywords and other settings), how do I link the existing assembler tagging macro to the new type?

Playing around with the new SE 23.0.0.2 beta

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4558
  • Hero Points: 352
Re: Adding new language to SE
« Reply #8 on: July 25, 2018, 08:41:14 pm »
I'm looking to add support for the MIPS assembler.  It appears that there are already references to the assembler, but there is no direct document type.  The xc compiler (Microchip/gcc derivative) on Windows uses the .S extension, which can run through the gcc preprocessor.  Is there an existing type that correctly handles the tagging and preprocessing?  If I need to derive a new document type (to add the keywords and other settings), how do I link the existing assembler tagging macro to the new type?

Playing around with the new SE 23.0.0.2 beta

There's a color coding definition for "Unix Assembler MIPS". The easiest thing to try is to use the Unix Assembly language definition and tweak it. Set the color coding profile to "Unix Assembler MIPS" and add the extensions you need to General/File Extensions.

You could also create a new language and copy/inherit everything from "Unix Assembly" and make the same changes but it takes an extra step.

b

  • Senior Community Member
  • Posts: 261
  • Hero Points: 24
Re: Adding new language to SE
« Reply #9 on: July 25, 2018, 10:04:47 pm »
There's a color coding definition for "Unix Assembler MIPS". The easiest thing to try is to use the Unix Assembly language definition and tweak it. Set the color coding profile to "Unix Assembler MIPS" and add the extensions you need to General/File Extensions.

You could also create a new language and copy/inherit everything from "Unix Assembly" and make the same changes but it takes an extra step.

I had discovered the former, but as I am switching between architectures, I needed the finer control over the profile (ARM, MIPS, PPC, etc.).

I've tried various different items to import, but I've run into the coloring doesn't appear to fully carry over or is supported (e.g., labels, variables, etc.).  Either I can't carry over the color profile, or I lose the tagging feature.

I'd love to clone Unix Assembly and just tweak it for the new language, but it appears that there is more on the back end that I need to be do (macro support?)

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4558
  • Hero Points: 352
Re: Adding new language to SE
« Reply #10 on: July 25, 2018, 10:17:12 pm »
I'd love to clone Unix Assembly and just tweak it for the new language, but it appears that there is more on the back end that I need to be do (macro support?)
Hmm...that should have worked. Looks like you checked the right boxes when creating the MIPS language. You also set the color coding profile which should have taken care of coloring.

Please post some sample code. Tell me what mistakes to look for (sounds like it could be obvious though). That way I can test some things out myself.

b

  • Senior Community Member
  • Posts: 261
  • Hero Points: 24
Re: Adding new language to SE
« Reply #11 on: July 25, 2018, 10:57:48 pm »
Attached is a bare bones workspace/project/file.

All should tag.

_reset should be colored a global function.
__reset_micromips_isa and  __reset_switch_isa should color as function labels.
_startup should color as symbol not found.

If the source is set as Unix Assembly, which has Color Coding of Unix Assembler MIPS, it works.   But when attempting to create a clone as Language MIPS (as described earlier), the tagging no longer works.


Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4558
  • Hero Points: 352
Re: Adding new language to SE
« Reply #12 on: July 25, 2018, 11:48:31 pm »
There's only one source file (scratch.c). I'm not seeing an assembly file.
« Last Edit: July 25, 2018, 11:56:16 pm by Clark »

b

  • Senior Community Member
  • Posts: 261
  • Hero Points: 24
Re: Adding new language to SE
« Reply #13 on: July 26, 2018, 12:05:24 am »
My bad, selected the wrong file when I created the zip.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4558
  • Hero Points: 352
Re: Adding new language to SE
« Reply #14 on: July 26, 2018, 01:03:20 am »
After you clone "Unix Assembly", did you manually set the mode of the already open .s files? (Document>Select Mode). After adding/moving the .s extension, the Options dialog isn't smart enough to set the mode.

Also, after the clone, does the "Defs" tool window display any symbols?

I'm seeing _point(), _reset(), _reset, __reset_micromips_isa, and __reset_switch_isa in the Defs tool window using the clone of the language (I called "Unix Assembly MIPS").