わいえむねっと

Contents
Categories
Calendar
2010/07
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Monthly Archives
~2000/01
Recent Entries
RSS1.0
Templates
Information
Processed: 0.048 sec
Chashed: -
2010/07/07 Wed
きのう勢いだけで実装したシンタックスハイライト記法についてちょっと整理。

ハイライト対象のサンプルは perlintro から拝借。



shebang 自動認識

Source:
|#!/usr/bin/perl
|use strict;
|use warnings;
|
|# This is a comment
|my $animal = "camel";
|my $answer = 42;
|
|print "The animal is $animal\n";
|print "The square of $answer is ", $answer * $answer, "\n";

Result:
#!/usr/bin/perl
use strict;
use warnings;

# This is a comment
my $animal = "camel";
my $answer = 42;

print "The animal is $animal\n";
print "The square of $answer is ", $answer * $answer, "\n";

略記

Source:
|#!perl
|use strict;
|use warnings;
|
|# This is a comment
|my $animal = "camel";
|my $answer = 42;
|
|print "The animal is $animal\n";
|print "The square of $answer is ", $answer * $answer, "\n";

Result:
use strict;
use warnings;

# This is a comment
my $animal = "camel";
my $answer = 42;

print "The animal is $animal\n";
print "The square of $answer is ", $answer * $answer, "\n";

行ハイライト

Source:
|#!perl[5,8]
|use strict;
|use warnings;
|
|# This is a comment
|my $animal = "camel";
|my $answer = 42;
|
|print "The animal is $animal\n";
|print "The square of $answer is ", $answer * $answer, "\n";

Result:
use strict;
use warnings;

# This is a comment
my $animal = "camel";
my $answer = 42;

print "The animal is $animal\n";
print "The square of $answer is ", $answer * $answer, "\n";

開始行指定

Source:
|#!perl[5,8]#5
|my $animal = "camel";
|my $answer = 42;
|
|print "The animal is $animal\n";
|print "The square of $answer is ", $answer * $answer, "\n";

Result:
my $animal = "camel";
my $answer = 42;

print "The animal is $animal\n";
print "The square of $answer is ", $answer * $answer, "\n";



行ハイライトと開始行指定については暫定。もう少し直感的にしたいところ。

    |#!perl
  *5|my $animal = "camel";
    |my $answer = 42;
    |
   *|print "The animal is $animal\n";
    |print "The square of $answer is ", $answer * $answer, "\n";

とか?