Own syntax schemes

Post a reply

Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review
   

Expand view Topic review: Own syntax schemes

Re: Own syntax schemes

Post by bax » Fri Nov 30, 2012 7:35 am

Hi, guess this is the right thread to propose a new language to be supported.
Drools.
There are a few keywords to highlight : [ 'import', 'dialect', 'rule', 'when', 'then', 'end', 'global' '$<var_name>'].
The folding should be straightforward as the file consists of imports, global declarations and a lot of rules, every rule having a well determined structure :
rule "rule name"
when
// preconditions
then
// do smth
end

Of course the entire language reference has a lot of other details about language structure.
Language reference

It's a language that gains popularity our days.
Thank you.

Re: Own syntax schemes

Post by omadawn » Fri Sep 28, 2012 6:26 am

Yeah there's a few things that I want to set as options. I need to add a separate preferences section for them. Things like auto close braces, etc.


So I was messing around trying to 'figure out how to get this to work.' and I found setAutoActivation(boolean). I thought I had seen a thread say this wasn't yet supported. It must have been old. You were probably assuming I had tried that already.
Needless to say it works now. ^_^

Re: Own syntax schemes

Post by robert » Thu Sep 27, 2012 1:30 pm

On your CompletionProvider, try calling:

java code:

public void setAutoActivationRules(boolean letters, String others);


This determines what characters will automatically display the completion popup. You'll want to pass "true" for the "letters" parameter, and can add anything else (such as "_", ":", etc.) in the "others" parameter. I believe all characters in "others" will have to be accepted by your isValidChar() override of course, for everything to work properly.

You can also tweak the delay after which the popup appears, by calling AutoCompletion.setAutoActivationDelay(int ms) on your AutoCompletion instance. You can set it to 0 to have the popup display automatically, if folks want that as well. I personally find that really annoying, but I know Visual Studio does it (at least, it used to do it). It might be more useful if the completion popup displays as you're typing any character. Ideally it would be an option the users could set in your application. :)

Hope this helps!

Re: Own syntax schemes

Post by omadawn » Thu Sep 27, 2012 3:03 am

So I published my editor out to my company's community resource as well as sending it to a bunch (read everyone I could talk into trying it) of my coworkers. To my surprise the single most common request was automatic (no ctrl+space) autocomplete. In fact it's one of the very few questions I've even ever gotten twice but it's come back from about a quarter to a third of my testers.

I already have a document listener implemented. I needed it for one of the features but can't remember which. ^_^ It seems like I should be able to just call whatever mechanism gets called by ctrl+space in the doc listener but even though I've peeked through the javadocs and code this magical mechanism still remains illusive. Do you have any advice on how I can make autocomplete happen without requiring ctrl+space?

Also if this is a feature that you would like to have available in the RSTA source itself (optionally of course) then let me know and I'll see if I can hack it into the RSTA source instead of implementing it myself.

Re: Own syntax schemes

Post by omadawn » Tue Sep 11, 2012 6:37 am

Copied, paste, added '_', done.

It works it was just as simple as it seemed. Thank you again.

Re: Own syntax schemes

Post by omadawn » Wed Aug 22, 2012 2:11 am

Actually I'm not extending it for this. I just instantiated an instance of DefaultCompletionProvider then ran a whole bunch of:
provider.addCompletion(new BasicCompletion(provider, word));


That seems pretty straight forward thought. i've added your notes to my bug list and extend it when it becomes more of an issue. TY again.

Re: Own syntax schemes

Post by robert » Tue Aug 21, 2012 1:02 pm

The completion provider is having a similar issue. If I type HT and hit ctrl+space it comes up with a list of my samples. Including things like HTTP::respond however if I continue to type it closes the list once I get to HTTP if I try and hit crtl+space again it starts over.


Are you extending DefaultCompletionProvider? If so, be sure to extend the isValidChar(char) method to include ':'. That method dictates what characters are considered "word" characters as far as code completion is concerned.

java code:

protected boolean isValidChar(char ch) {
return ch==':' || super.isValidChar(ch);
}

Re: Own syntax schemes

Post by omadawn » Tue Aug 21, 2012 4:28 am

Alrightythen

Modified the .jlex file per directions and it's working. Now I need to figure out what my colors should be for various components.

Thanks again for the assistance and the beautiful library it is pretty awesome.


I even implemented a completion provider which was also pretty darned simple.

The completion provider is having a similar issue. If I type HT and hit ctrl+space it comes up with a list of my samples. Including things like HTTP::respond however if I continue to type it closes the list once I get to HTTP if I try and hit crtl+space again it starts over.

I'm not terribly worried about this particular issue. I can select the correct component from the pull down list. Now that syntax highlighting is fully featured I'm pretty much ready to start giving it to other people in my organization who will use it.

Re: Own syntax schemes

Post by omadawn » Tue Aug 07, 2012 9:32 pm

It seems like it is based on this list of tcl commands http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm (see http://www.tcl.tk/man/tcl8.4/TclCmd/packagens.htm for a specific example)
Though it is a little uncommon. More common are commands with underscores in them.

I'm not terribly well versed in TCL specifically myself. ^_^ But the syntax is quite common in iRules.

I'll take a look at the flex file and try and rebuild that with an updated list for my own usage. It seems like this is another way to extend the list of keywords and since I'm doing this I could probably get rid of the extended tokenMaker class I have created to get this far? In fact I might be able to get very specific. iRule commands all use a common UPPERCASE::lowercase format that I could probably check for.

Not sure when I'll get a chance to work on this again I'm pretty busy this week. I'll test and post back as soon as I can.

Re: Own syntax schemes

Post by robert » Mon Aug 06, 2012 3:03 am

Yes, the TCL token maker assumes a word starts with a letter, underscore, or '$' sign, followed by any of those character types again or digits. Unfortunately there's no way to override that without modifying the TclTokenMaker.flex file and regenerating it.

I have no idea what constitutes a valid TCL token. If that type of syntax ("Something::else") is valid in TCL, I'll be happy to update the built-in TclTokenMaker for you, after which you'll be able to do what you're doing without issue. Otherwise, if you wish to do this yourself, look at the class comment at the top of TclTokenMaker.flex and follow its instructions - make your changes, regenerate via JFlex, and make the few required changes by hand on the generated .java file (which I really should get around to automating...).

Top

cron