Simple example of custom language that demos autocomplete

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Simple example of custom language that demos autocomplete

Postby Bryan » Mon Mar 25, 2013 9:19 pm

First of all Robert thank you very much for this wonderfully designed libary. I'll be using the SyntaxTextArea/Autocomplete to build an editor for a simple scripting dsl. A JFlex generated scanner would be total overkill for this project so I am using the WindowsBatchTokenMaker as a starting point. Are there any simple examples out there of a totally custom language which ties all the autocompletion pieces together (context awareness, etc). I'm looking for a very simple example (a made up language of under 10 keywords and just a few functions etc. would do just fine) that use and demonstrate the various CompletionProvider implementations. Thanks again for the wonderful work!
Bryan
 
Posts: 3
Joined: Mon Mar 25, 2013 8:25 pm

Re: Simple example of custom language that demos autocomplet

Postby robert » Sun Mar 31, 2013 11:54 pm

The simplest example I have is here:

http://fifesoft.com/rsyntaxtextarea/examples/example5.php

It shows adding code completion for Java keywords.

I'm working on some straightforward guides that explain how to add custom syntax highlighting, code folding, and code completion for languages, but it's not ready yet. I'm too lazy to complete them! They'll hopefully be available soon.

One good example that may be worth exploring is the C code completion in the RSTALanguageSupport project. It's "simple" in that it loads all of its completions from XML, so the amount of actual Java code written for it is very small. It doesn't really do any parsing; rather, based on the RSTA token it's in (comment, string, or "code" - e.g., everything else), it surfaces a different list of possible completions and lets the machinery do all the work. The heart of it all is the CCompletionProvider class, which mostly loads the completions from XML. The XML is expected to follow this DTD found in the AutoComplete project, then everything should "just work." You should be able to follow the simple example above, but load your completions from XML instead of hard-coded BasicCompletions.

Again, I hope to have a simple tutorial for this stuff in the near future, but hopefully this is enough to help you get started. Let me know if you have further questions.
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: Simple example of custom language that demos autocomplet

Postby Bryan » Wed Apr 03, 2013 9:12 pm

Thanks Robert! I have a bit of an unusual usecase in that I am looking into extending the LanguageAwareCompletionProvider because I need to implement completion context based on nesting, for example if my simple language is structured in a manner similiar to:

java code:

command1
{
command2
{

}
}


Depending on where I am in the text and hit ctrl-space I want a different set of completions to appear based on whether I am in the context of command1 or command2, etc. so I have to look beyond the current line in order to determine context. To do this I was getting the tokens from the start of the document to the cursor position, then moving backwards to get the current context I am "in". Maybe there is a better way to do this. Also I am struggling with adding Java style single line and multiline comment support to my TokenMaker class (which started based on WindowsBatchTokenMaker). I don't see any examples of doing this from a non-JFlex generated class, any tips would be appreciated. Thank you Robert!
Bryan
 
Posts: 3
Joined: Mon Mar 25, 2013 8:25 pm

Re: Simple example of custom language that demos autocomplet

Postby robert » Thu Apr 04, 2013 1:16 pm

In order to implement context-sensitive completions, you have two choices.

  • Work through all tokens from the document start to figure it out when the user presses Ctrl+space, like you're doing.
  • Create an AST-style construct for your language, write a parser for it with RSTA's parser API, and query that when the user presses Ctrl+space. This is what the Java and JavaScript code completion do in [url=http://fifesoft.com/blog/?cat=9]RSTALanguageSupport.

Obviously, the latter approach is much more work, so for simpler cases it's probably better to do #1. That's what the Perl language support does, for example, for code completion of variable names.

I will eventually have a tutorial on writing a Parser if you do want to explore that route however.

As for how to do single- and multi-line comments with a hand-made TokenMaker, again, I have a simple tutorial in the works that should demo that. I'll try to update this post with how to do it as it might be a little bit before that demo gets done.
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: Simple example of custom language that demos autocomplet

Postby adam » Mon May 20, 2013 10:46 pm

robert wrote:I will eventually have a tutorial on writing a Parser if you do want to explore that route however.

I would be very interested in such a tutorial!
adam
 


Return to Help

Who is online

Users browsing this forum: No registered users and 2 guests

cron