きのう勢いだけで実装したシンタックスハイライト記法についてちょっと整理。
ハイライト対象のサンプルは 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";
とか?