08-07-2006 15:26
There have been things added to LSL since I released my syntax file, so I decided to solve that problem once and for all. This is quick and dirty, so feel free to comment and criticize. I tested it a bit, and it seems to work.

Usage:
CODE

./gensyntax.pl < lsl-pattern.xml > lsl.xml


Or:
CODE

./gensyntax.pl "$HOME/sl_path" < lsl-pattern.xml > lsl.xml


Now, the required files, which should all be executable and in the same directory:

lsl-pattern.xml:
CODE

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<language name="LSL" version="1.1" kateversion="2.4" section="Sources" extensions="*.lsl" mimetype="" priority="5" license="GPL" author="Dale Glass">
<highlighting>
<list name="keywords">
<item> default </item>
<item> state </item>
<!--INI_EXTRACT: flow control keywords-->
</list>
<list name="types">
<!--INI_EXTRACT: data types-->
</list>
<list name="functions">
<!--GUIDE_EXTRACT-->
</list>
<list name="constants">
<!--INI_EXTRACT: integer constants-->
<!--INI_EXTRACT: string constants-->
<!--INI_EXTRACT: float constants-->
<!--INI_EXTRACT: compound constants-->
</list>
<list name="events">
<!--INI_EXTRACT: events-->
</list>
<contexts>
<context attribute="Normal Text" lineEndContext="#stay" name="Normal">
<DetectSpaces />
<RegExpr attribute="Preprocessor" context="Outscoped" String="#\s*if\s+0" beginRegion="Outscoped" firstNonSpace="true" />
<DetectChar attribute="Preprocessor" context="Preprocessor" char="#" firstNonSpace="true" />
<StringDetect attribute="Region Marker" context="Region Marker" String="//BEGIN" beginRegion="Region1" firstNonSpace="true" />
<StringDetect attribute="Region Marker" context="Region Marker" String="//END" endRegion="Region1" firstNonSpace="true" />
<keyword attribute="Keyword" context="#stay" String="keywords"/>
<keyword attribute="Function" context="#stay" String="functions"/>
<keyword attribute="Constant" context="#stay" String="constants"/>
<keyword attribute="Data Type" context="#stay" String="types"/>
<keyword attribute="Event" context="#stay" String="events"/>
<DetectIdentifier />
<DetectChar attribute="Symbol" context="#stay" char="{" beginRegion="Brace1" />
<DetectChar attribute="Symbol" context="#stay" char="}" endRegion="Brace1" />
<Float attribute="Float" context="#stay">
<AnyChar String="fF" attribute="Float" context="#stay"/>
</Float>
<HlCOct attribute="Octal" context="#stay"/>
<HlCHex attribute="Hex" context="#stay"/>
<Int attribute="Decimal" context="#stay" >
<StringDetect attribute="Decimal" context="#stay" String="ULL" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="LUL" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="LLU" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="UL" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="LU" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="LL" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="U" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="L" insensitive="TRUE"/>
</Int>
<HlCChar attribute="Char" context="#stay"/>
<DetectChar attribute="String" context="String" char="""/>
<IncludeRules context="##Doxygen" />
<Detect2Chars attribute="Comment" context="Commentar 1" char="/" char1="/"/>
<Detect2Chars attribute="Comment" context="Commentar 2" char="/" char1="*" beginRegion="Comment"/>
<AnyChar attribute="Symbol" context="#stay" String=":!%&()+,-/.*<=>?[]|~^;"/>
</context>
<context attribute="String" lineEndContext="#pop" name="String">
<LineContinue attribute="String" context="#stay"/>
<HlCStringChar attribute="String Char" context="#stay"/>
<DetectChar attribute="String" context="#pop" char="""/>
</context>
<context attribute="Region Marker" lineEndContext="#pop" name="Region Marker">
</context>
<context attribute="Comment" lineEndContext="#pop" name="Commentar 1">
<IncludeRules context="##Alerts" />
</context>
<context attribute="Comment" lineEndContext="#stay" name="Commentar 2">
<Detect2Chars attribute="Comment" context="#pop" char="*" char1="/" endRegion="Comment"/>
<IncludeRules context="##Alerts" />
</context>
<context attribute="Preprocessor" lineEndContext="#pop" name="Preprocessor">
<LineContinue attribute="Preprocessor" context="#stay"/>
<RegExpr attribute="Preprocessor" context="Define" String="define.*((?=\\))"/>
<RegExpr attribute="Preprocessor" context="#stay" String="define.*"/>
<RangeDetect attribute="Prep. Lib" context="#stay" char=""" char1="""/>
<RangeDetect attribute="Prep. Lib" context="#stay" char="<" char1=">"/>
<IncludeRules context="##Doxygen" />
<Detect2Chars attribute="Comment" context="Commentar/Preprocessor" char="/" char1="*" beginRegion="Comment2"/>
</context>
<context attribute="Preprocessor" lineEndContext="#pop" name="Define">
<LineContinue attribute="Preprocessor" context="#stay"/>
</context>
<context attribute="Comment" lineEndContext="#stay" name="Commentar/Preprocessor">
<Detect2Chars attribute="Comment" context="#pop" char="*" char1="/" endRegion="Comment2" />
</context>
<context attribute="Comment" lineEndContext="#stay" name="Outscoped" >
<DetectSpaces />
<IncludeRules context="##Alerts" />
<DetectIdentifier />
<DetectChar attribute="String" context="String" char="""/>
<IncludeRules context="##Doxygen" />
<Detect2Chars attribute="Comment" context="Commentar 1" char="/" char1="/"/>
<Detect2Chars attribute="Comment" context="Commentar 2" char="/" char1="*" beginRegion="Comment"/>
<RegExpr attribute="Comment" context="Outscoped intern" String="#\s*if" beginRegion="Outscoped" firstNonSpace="true" />
<RegExpr attribute="Preprocessor" context="#pop" String="#\s*(endif|else|elif)" endRegion="Outscoped" firstNonSpace="true" />
</context>
<context attribute="Comment" lineEndContext="#stay" name="Outscoped intern">
<DetectSpaces />
<IncludeRules context="##Alerts" />
<DetectIdentifier />
<DetectChar attribute="String" context="String" char="""/>
<IncludeRules context="##Doxygen" />
<Detect2Chars attribute="Comment" context="Commentar 1" char="/" char1="/"/>
<Detect2Chars attribute="Comment" context="Commentar 2" char="/" char1="*" beginRegion="Comment"/>
<RegExpr attribute="Comment" context="Outscoped intern" String="#\s*if" beginRegion="Outscoped" firstNonSpace="true" />
<RegExpr attribute="Comment" context="#pop" String="#\s*endif" endRegion="Outscoped" firstNonSpace="true" />
</context>
</contexts>
<itemDatas>
<itemData name="Normal Text" defStyleNum="dsNormal"/>
<itemData name="Keyword" defStyleNum="dsKeyword"/>
<itemData name="Data Type" defStyleNum="dsDataType"/>
<itemData name="Function" defStyleNum="dsFunction"/>
<itemData name="Constant" defStyleNum="dsConstant"/>
<itemData name="Decimal" defStyleNum="dsDecVal"/>
<itemData name="Event" defStyleNum="dsEvent"/>
<itemData name="Octal" defStyleNum="dsBaseN"/>
<itemData name="Hex" defStyleNum="dsBaseN"/>
<itemData name="Float" defStyleNum="dsFloat"/>
<itemData name="Char" defStyleNum="dsChar"/>
<itemData name="String" defStyleNum="dsString"/>
<itemData name="String Char" defStyleNum="dsChar"/>
<itemData name="Comment" defStyleNum="dsComment"/>
<itemData name="Symbol" defStyleNum="dsNormal"/>
<itemData name="Preprocessor" defStyleNum="dsOthers"/>
<itemData name="Prep. Lib" defStyleNum="dsOthers"/> <!--,Qt::darkYellow,Qt::yellow,false,false)); -->
<itemData name="Alert" defStyleNum="dsAlert" />
<itemData name="Region Marker" defStyleNum="dsRegionMarker" />
</itemDatas>
</highlighting>
<general>
<comments>
<comment name="singleLine" start="//" />
</comments>
<keywords casesensitive="1" />
</general>
</language>


extract_keywords.pl:
CODE

#!/usr/bin/perl -w
use strict;

my $section_found;
my $skip_next;
my $prefix = "\t\t\t";
my $wanted_section = $ARGV[0] || die "Syntax: $0 <section>";


# Fetch whole thing, replace windows CRLF with unix format
undef $/;
my $data = <STDIN>;
$data =~ s/\r\n/\n/g;

foreach my $line (split(/\n/, $data)) {
chomp $line;

if ( $section_found && ! $skip_next ) {
exit(0) if ( $line =~ /^\[/ ); # Exit if we found another section

if ( $line !~ /^(\[|#)/ ) {
my ($keyword) = split(/\s/, $line);
print "${prefix}<item> ${keyword} </item>\n" if defined($keyword);
}
}

undef $skip_next;
if ( $line eq "# $wanted_section" ) {
# Found the wanted section, ignore the next line, which begins with a [
# so that we don't recognize it as the end of a section.
$section_found = 1;
$skip_next = 1;
}

}


extract_guide.sh:
CODE

#!/bin/bash
grep -e '^>ll.*</A' | sed 's/^>/\t\t\t<item> /g; s/<\/A/ <\/item>/g;' | sort | uniq


gensyntax.pl:
CODE

#!/usr/bin/perl -w
use strict;
my $sl_path = $ARGV[0] || "$ENV{HOME}/.wine/drive_c/Program Files/SecondLife";

unless( -f "${sl_path}/app_settings/keywords.ini" ) {
die "Can't find SL at ${sl_path}, please specify the correct path as a command line argument.";
}

while( my $line = <STDIN> ) {
chomp $line;
if ( $line =~ m/<!--INI_EXTRACT: (.*?)-->/ ) {
print "\t\t\t<!-- Extracted from keywords.ini: $1 -->\n";
system("./extract_keywords.pl \"$1\" < \"${sl_path}/app_settings/keywords.ini\" | sort");
#print "$1\n";
} elsif ( $line =~ m/<!--GUIDE_EXTRACT-->/ ) {
print "\t\t\t<!-- Extracted from LSL guide -->\n";
system("./extract_guide.sh < \"${sl_path}/lsl_guide.html\" | sort");
} else {
print "$line\n";
}
}