Author Topic: cload() vs manually importing a lexer  (Read 4487 times)

IanG

  • Community Member
  • Posts: 18
  • Hero Points: 0
cload() vs manually importing a lexer
« on: March 17, 2014, 03:28:52 AM »
When working to define a language via a macro language definition, we are encouraged to use cload() to load a specific lexer to accompany our specification.

cload() without a filename yields a dialog box titled "Open Color Lexer File", but going through the menu options Tools -> Options -> Languages -> <Language> -> Color Coding -> Import yields a dialog box titled "Select VLX File".

What's the difference between these, and how do I get the latter in Slick-C code? I have created language definitions and color lexers as per the old tutorial but the lexer only seems to load if I use the options dialog to load it. If I use cload() the function returns 0 indicating success but the lexer does not get loaded and is not available.

(the "old tutorial" is this one: http://blog.slickedit.com/2008/05/tutorial-adding-language-support-to-slickedit/ )

Thanks for any help. - Ian.

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: cload() vs manually importing a lexer
« Reply #1 on: March 18, 2014, 01:18:11 PM »
When working to define a language via a macro language definition, we are encouraged to use cload() to load a specific lexer to accompany our specification.

(the "old tutorial" is this one: http://blog.slickedit.com/2008/05/tutorial-adding-language-support-to-slickedit/ )

What do you mean "we are encouraged to use cload"  ??

From looking at step 5 in the tutorial you linked to it seems you should be calling import_lexer_file as shown below ??

What do you mean by the "old tutorial"  - is there a new one?  I feel I'm missing something here.

If cload doesn't work maybe you haven't gone through all the steps described in the help file under "Creating a Lexer Name and a New VLX File"   - but it's a bit confusing and I don't really follow it at first glance.

Code: [Select]
#define LOGO_MODE_NAME "Logo"
#define LOGO_EXTENSION1 "logo"
#define LOGO_EXTENSION2 "lgo"

// This function is called when the module is loaded.
// It configures the "logo" and "lgo" file extensions.
void defload()
{
_str setup_info="MN="LOGO_MODE_NAME",TABS=+3,MA=1 74 1,":+
"KEYTAB=ext-keys,WW=1,IWT=0,ST=0,IN=2,":+
"WC=A-Za-z0-9_$,LN="LOGO_MODE_NAME",CF=1";
_str compile_info="0 logo32 *";
_str syntax_info="3 1 2 1 0 1 0";
_str be_info="(to)|(end);i";
int kt_index=0;
_CreateLanguage(kt_index, LOGO_MODE_NAME,
setup_info, compile_info, syntax_info, be_info);
_CreateExtension("logo", LOGO_MODE_NAME);
_CreateExtension("lgo", LOGO_MODE_NAME);

_str logo_vlx = _config_path() :+ FILESEP :+ "logo.vlx";
if (file_exists(logo_vlx)) {
import_lexer_file(logo_vlx);
}
}

IanG

  • Community Member
  • Posts: 18
  • Hero Points: 0
Re: cload() vs manually importing a lexer
« Reply #2 on: March 18, 2014, 02:24:38 PM »
Thanks for the sanity check. You are right - it should be using import_lexer_file(). The confusion is because in the zip file attached to the post, it uses cload():
Code: [Select]
   _str logo_vlx = _config_path() :+ FILESEP :+ "logo.vlx";
   if (file_exists(logo_vlx)) {
      cload(logo_vlx);
   }
So the text is correct but the attachment wrong in this case. It may have been corrected/discussed in the comments.

As for calling it "the old tutorial" - sorry for the confusion - this is just a conscious attempt to emphasize that it is old. It contains numerous errors/inconsistencies including the one we just found. I am not aware of a new one but would like to write one eventually, or at least pull together all the help people have given each other here regarding custom language definitions. Of course to do that I need to get it working myself.

Initial tests indicate that import_lexer_file() works so I'll proceed with that.

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: cload() vs manually importing a lexer
« Reply #3 on: March 18, 2014, 03:13:40 PM »
Ah, I see.  Did you see this post by Ryan
http://community.slickedit.com/index.php/topic,3276.msg13587.html#msg13587

Did you also see that in the comments on the tutorial page, someone reported that for step 5, the zip file was correct but the orange text on the web page was wrong.  I think the text on the web page is wrong when it passes zero as the first argument to _CreateLanguage  - it should be a piece of text e.g. "logo" as in the zip file.