Saturday, November 15, 2008

GNU Source-Highlight 2.11

Here's the new release of GNU Source-Highlight.

From the low level point of view, the algorithm for finding the best matching regular expression was optimized; The strategy used by source-highlight is to select the first matching rule

  • with empty prefix (or prefix containing only space characters, i.e., spaces or tabs) or
  • with the smallest prefix.
Thus, it does not inspect all the possible expressions, but it stops as soon as it finds one that satisfies the above conditions.

As for end-user stuff, in C++ and Java, types used in variable and parameter definitions are now highlighted, see the example below.

/*
This is a classical Hello program
to test source-highlight with Java programs.

to have an html translation type

source-highlight -s java -f html --input Hello.java --output Hello.html

source-highlight -s java -f html < Hello.java > Hello.html

or type source-highlight --help for the list of options

written by
Lorenzo Bettini

http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite
*/

package hello;

import java.io.* ;

/**
* <p>
* A simple Hello World class, used to demonstrate some
* features of Java source highlighting.
* </p>

* TODO: nothing, just to show an highlighted TODO or FIXME
*
* @author Lorenzo Bettini

* @version 2.0
*/
public class Hello {

int foo = 1998 ;
int hex_foo = 0xCAFEBABE;

boolean b = false;
Integer i = null ;

char c = '\'', d = 'n', e = '\\' ;

String xml = "<tag attr=\"value\">&auml;</tag>", foo2 = "\\" ;


public static void main( String args[] ) {

// just some greetings ;-) /*
System.out.println( "Hello from java2html :-)" ) ;

System.out.println( "\tby Lorenzo Bettini" ) ;
System.out.println( "\thttp://www.lorenzobettini.it" ) ;

if (argc > 0)
String param = argc[0];

//System.out.println( "bye bye... :-D" ) ; // see you soon
}
}

Probably the main novelty is the possibility of specifying a line range, or multiple line ranges: only the lines in the input source that are in that range are actually in the output (--line-range). It is also possible to specify the sorrounding "context", i.e., the number of lines not in range that are put in the output anyway (--range-context); the context itself can be formatted with its own style. Finally, a range separator string can be specified, e.g., "..." (--range-separator). For instance, the following command
source-highlight -s java -f html
--line-range="12-18","29-34" --line-number
--range-context=3 --range-separator="<...>"
-i test.java -o test_linerange_sep.html
generates the following output (note the gray lines of context)

<...>
00009:
00010: or type source-highlight --help for the list of options
00011:
00012: written by
00013: Lorenzo Bettini
00014: http://www.lorenzobettini.it
00015: http://www.gnu.org/software/src-highlite
00016: */
00017:
00018: package hello;
00019:
00020: import java.io.* ;
00021:
<...>
00026: * </p>
00027: * TODO: nothing, just to show an highlighted TODO or FIXME
00028: *
00029: * @author Lorenzo Bettini
00030: * @version 2.0
00031: */
00032: public class Hello {
00033: int foo = 1998 ;
00034: int hex_foo = 0xCAFEBABE;
00035: boolean b = false;
00036: Integer i = null ;
00037: char c = '\'', d = 'n', e = '\\' ;
<...>

Tiziano Muller wrote a configuration file for bash_completion, for source-highlight (thank you Tiziano).

Finally, two new language definitions were added: one for xorg configuration files, and one for the Scala programming language (thanks to Dean Wampler), here are some examples:

Xorg file


# xorg.conf (xorg X Window System server configuration file)
#
# This file was generated by dexconf, the Debian X Configuration tool, using
# values from the debconf database.
#
Section "Files"
EndSection
Section "InputDevice"
Identifier "Synaptics Touchpad"
Driver "synaptics"
Option "SendCoreEvents" "true"
Option "Device" "/dev/psaux"
Option "Protocol" "auto-dev"
Option "SHMConfig" "on"
Option "HorizEdgeScroll" "0"
Option "MinSpeed" "0.5" # touchpad speed when moving slowly
Option "MaxSpeed" "2.0" # touchpad speed when moving fast
Option "AccelFactor" "0.10"
Option "CircularScrolling" "on"
Option "EdgeMotionMinSpeed" "0.5"
EndSection
Section "InputDevice"
Driver "wacom"
Identifier "stylus"
Option "Device" "/dev/input/wacom"
Option "Type" "stylus"
Option "ForceDevice" "ISDV4" # Tablet PC ONLY
EndSection
Section "Device"
Identifier "Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller"
Driver "intel"
BusID "PCI:0:2:0"
# Option "NoDRI"
EndSection
Section "Screen"
Identifier "Default Screen"
Device "Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller"
Monitor "Generic Monitor"
DefaultDepth 24
SubSection "Display"
Modes "1440x900"
EndSubSection
EndSection
Section "ServerLayout"
Identifier "Default Layout"
Screen "Default Screen"
InputDevice "Generic Keyboard"
InputDevice "Configured Mouse"
# Uncomment if you have a wacom tablet
# InputDevice "stylus" "SendCoreEvents"
# InputDevice "cursor" "SendCoreEvents"
# InputDevice "eraser" "SendCoreEvents"
InputDevice "Synaptics Touchpad"
EndSection

Scala language


// Example Scala file for source-highlight.
case class Point(x: Double, y: Double)
abstract case class Shape { def draw(): Unit = println(this) }
case class Circle(center: Point, radius: Double) extends Shape
case class Rectangle(lowerLeft: Point, height: Double, width: Double) extends Shape
import scala.actors._
import scala.actors.Actor._
object ShapeDrawer extends Actor {
def act() {
loop {
receive {
case s: Shape => s.draw()
case "exit" => { println("exiting..."); exit }
case x: Any => println("Error: Unknown message! " + x)
}
}
}
}
ShapeDrawer.start()
ShapeDrawer ! Circle(Point(0.0,0.0), 1.0)
ShapeDrawer ! Rectangle(Point(0.0,0.0), 2, 5)
ShapeDrawer ! 3.14159
ShapeDrawer ! "exit"
// Output:
// => Circle(Point(0.0,0.0),1.0)
// => Rectangle(Point(0.0,0.0),2.0,5.0)
// => Error: Unknown message! 3.14159
// => exiting...

No comments: