Scala enhancements

General Discussion on RSyntaxTextArea.

Moderator: robert

Re: Scala enhancements

Postby robert » Tue Nov 20, 2012 2:59 am

That one might have to wait until after the upcoming 2.0.5 release this week, unfortunately.
User avatar
robert
 
Posts: 779
Joined: Sat May 10, 2008 5:16 pm

Re: Scala enhancements

Postby Lalit Pant » Wed Nov 21, 2012 5:20 pm

No worries.

I have been playing with a few different ideas for trying to get XML support to work, and have made interesting progress by hooking up a Scala Lexer with (a slightly hacked version of) RSTA:
https://gist.github.com/4126069

This seems to work correctly (with multilple levels of XML inside Scala inside XML inside Scala)! The downside is that it is pretty inefficient (although it seems to work fine for sub-1000 line scripts).

Next steps: test this a lot more, and then think about ways to optimize this approach (currently the whole document till the current line is scanned to find the tokens for a line).
Lalit Pant
 

Re: Scala enhancements

Postby Lalit Pant » Fri Nov 23, 2012 6:57 pm

Next steps: test this a lot more, and then think about ways to optimize this approach (currently the whole document till the current line is scanned to find the tokens for a line).


Quick Update:
I have a much more performant version now: http://code.google.com/p/kojolite/sourc ... aker.scala

There are many ways to optimize this further, but performance seems to be at a point where it is good enough (with no noticeable issues). I'm seriously thinking about taking this into production!

Hacks to RSTA to get this working:
Code: Select all
Index: src/org/fife/ui/rsyntaxtextarea/TokenMakerBase.java
===================================================================
--- src/org/fife/ui/rsyntaxtextarea/TokenMakerBase.java   (revision 720)
+++ src/org/fife/ui/rsyntaxtextarea/TokenMakerBase.java   (working copy)
@@ -9,6 +9,7 @@
 package org.fife.ui.rsyntaxtextarea;
 
 import javax.swing.Action;
+import javax.swing.event.DocumentEvent;
 import javax.swing.text.Segment;
 
 
@@ -132,7 +133,10 @@
 
    }
 
-
+    // Doc change hooks added by Lalit
+    public void onInsert(DocumentEvent e) {}   
+    public void onRemove(DocumentEvent e) {} 
+   
    /**
     * Returns whether this programming language uses curly braces
     * ('<tt>{</tt>' and '<tt>}</tt>') to denote code blocks.<p>
Index: src/org/fife/ui/rsyntaxtextarea/TokenMaker.java
===================================================================
--- src/org/fife/ui/rsyntaxtextarea/TokenMaker.java   (revision 720)
+++ src/org/fife/ui/rsyntaxtextarea/TokenMaker.java   (working copy)
@@ -10,6 +10,7 @@
 package org.fife.ui.rsyntaxtextarea;
 
 import javax.swing.Action;
+import javax.swing.event.DocumentEvent;
 import javax.swing.text.Segment;
 
 
@@ -135,7 +136,11 @@
    public Token getTokenList(Segment text, int initialTokenType,
                                  int startOffset);
 
-
+   
+   // Doc change hooks added by Lalit
+    public void onInsert(DocumentEvent e);   
+    public void onRemove(DocumentEvent e);   
+   
    /**
     * Returns whether this language is a markup language.
     *
Index: src/org/fife/ui/rsyntaxtextarea/RSyntaxDocument.java
===================================================================
--- src/org/fife/ui/rsyntaxtextarea/RSyntaxDocument.java   (revision 720)
+++ src/org/fife/ui/rsyntaxtextarea/RSyntaxDocument.java   (working copy)
@@ -114,7 +114,8 @@
     * @param e The change.
     */
    protected void fireInsertUpdate(DocumentEvent e) {
-
+      
+       tokenMaker.onInsert(e);
       /*
        * Now that the text is actually inserted into the content and
        * element structure, we can update our token elements and "last
@@ -187,6 +188,8 @@
     */
    protected void fireRemoveUpdate(DocumentEvent chng) {
 
+       tokenMaker.onRemove(chng);
+      
       Element lineMap = getDefaultRootElement();
       int numLines = lineMap.getElementCount();
 


Feedback welcome...
Lalit Pant
 

Re: Scala enhancements

Postby Lalit Pant » Mon Nov 26, 2012 2:53 pm

FYI...

Another round of optimizations, and this thing is in production now:
http://www.kogics.net/webkojo

The TokenMaker source:
http://code.google.com/p/kojolite/source/browse/src/main/scala/net/kogics/kojo/lexer/ScalariformTokenMaker.scala
Lalit Pant
 

Previous

Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron