[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    Re: syntax highlighting
From:       Anders Lund <anders () alweb ! dk>
Date:       2002-04-02 21:28:47
[Download RAW message or body]

On Tuesday 02 April 2002 11:23, E.L. Willighagen wrote:
> Hi Kate-developer,
>
> I am having a a few problems/questions about syntax hightlighting
> with this code for R scripts (http://www.r-project.org/) at the end of this
> email...
>
> I would like to get it to work properly so that I can donate it to the Kate
> library... But I do not know the proper place to ask this question, so I
> send it to you in the hope you can answer it or forward to someone
> (person/list) where it can be answered...
>
> This is the problem: in general R scripts contain procedure calls, with two
> kinds of parameters: named and unnamed. The latter is dealt with in order,
> like in most programming languages, but the former is more like attributes
> in XML/SGML/HTML.
>
> For example:
> > plot(x,y, main="title")
>
> which plots a data set with x and y coordinates in a figure with a title...
>
> I read some stuff about contexes and looked into some of the highlighting
> definitions in $KDE_home/share/apps/kate/syntax, but do not get a
> definition to work to have something to work with the above syntax for R...
> the three parameters x, y and "title" all have the same context again, like
> plot... i.e. all three are again expressions and procedure calls can be
> nested.

Hi, new syntax files are allways wellcome.
I will suggest that you upgrade KDE to 3.0, as the capability of the hl system 
has improved. The manual in Kate for KDE 3 also contains a description of how 
it works.

Note the workings of #pop and #stay.

If you want to review samples of detailed parsing, look at the latest version 
of the perl.xml file. What you want to do is basically to go to a context 
when you detect the method call, and then parse the contents of the parens in 
there.

Please let me know it this helps, and if I can be of more help.


-anders

> For now, I have the highlighting code which does not do this, but that does
> recognize the precedure names:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <language name="R Script" section="Sources" extensions="*.R"
> mimetype="application/x-R">
>   <highlighting>
>     <list name="keywords">
>       <item> break </item>
>       <item> else </item>
>       <item> for </item>
>       <item> if </item>
>       <item> in </item>
>       <item> repeat </item>
>       <item> while </item>
>     </list>
>     <list name="commands">
>       <item> c </item>
>       <item> dev </item>
>       <item> dim </item>
>       <item> grey </item>
>       <item> library </item>
>       <item> lines </item>
>       <item> lm </item>
>       <item> log </item>
>       <item> matrix </item>
>       <item> max </item>
>       <item> mean </item>
>       <item> min </item>
>       <item> outer </item>
>       <item> persp </item>
>       <item> plot </item>
>       <item> postscript </item>
>       <item> print </item>
>       <item> rep </item>
>       <item> scan </item>
>       <item> seq </item>
>       <item> sort </item>
>       <item> t </item>
>     </list>
>     <contexts>
>       <context attribute="0" lineEndContext="0">
>         <keyword attribute="1" context="0" String="keywords"/>
>         <keyword attribute="1" context="0" String="commands"/>
>         <RegExpr attribute="2" context="0" String="#.*$" />
>         <RangeDetect attribute="3" context="0" char="&quot;"
> char1="&quot;"/> </context>
>     </contexts>
>     <itemDatas>
>       <itemData name="Normal Text" defStyleNum="dsNormal"/>
>       <itemData name="Keyword" defStyleNum="dsKeyword"/>
>       <itemData name="Comment" defStyleNum="dsComment"/>
>       <itemData name="String"  defStyleNum="dsString"/>
>       <itemData name="Attribute" defStyleNum="dsNormal" italic="1"/>
>     </itemDatas>
>   </highlighting>
>   <general>
>     <comments>
>       <comment name="singleLine" start="#" />
>     </comments>
>   </general>
> </language>
>
> kind regards,
>
> Egon Willighagen

_______________________________________________
kwrite-devel mailing list
kwrite-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/kwrite-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic