CotEditorの正規表現スクリプトメモ(property->synthesize)

synthesizeが省略できる今となっては無用の長物ですが、
@propertyから@synthesizeを自動生成するCotEditor用のperlスクリプトを書いてあったので、
一応記載しておきます。


・対象のobjc

@property(nonatomic) BOOL isRun;
@property(nonatomic) BOOL isFinished;
@property(nonatomic) NSInteger repeatCount;
@property(nonatomic, strong) NSString *currentWorkTitle;



perlスクリプト

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

# 全てのテキストを標準入力へ入れる
# %%%{CotEditorXInput=AllText}%%%

# 結果は現在のテキストと置換する
# %%%{CotEditorXOutput= ReplaceAllText}%%%

my @text = <STDIN>;
foreach my $line ( @text ) {
	# 先頭の@propertyを削除    A=~s/B/C/gは、A内を正規表現Bで検索してCで置換
	$line =~ s/\@property\(.+\)\s?//g;
	# 型の部分を削除
	$line =~ s/[A-Z[\w]+\s?\*?[\s|*]//g;
	# ;を削除
	$line =~ s/;//g;
	# 変数名を@synthesizeの形式に置換
	$line =~ s/([a-z|A-Z]+)\n?/\@synthesize $1 = _$1;\n/g;
	print $line;
}

・結果

@synthesize isRun = _isRun;
@synthesize isFinished = _isFinished;
@synthesize repeatCount = _repeatCount;
@synthesize currentWorkTitle = _currentWorkTitle;



あと、メソッド宣言から空実装を生成するスクリプトです。
取り敢えず引数なしのみで、空実装側に戻り値は記載されません...
・対象のメソッド宣言(objc)

- (void)start;
- (BOOL)isRun;
- (NSString *)updateSetCount;

perlスクリプト

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

# %%%{CotEditorXInput=AllText}%%%
# %%%{CotEditorXOutput= ReplaceAllText}%%%

my @text = <STDIN>;
foreach my $line ( @text ) {
		$line =~ s/;//g;
		$line =~ s/([\-|\+]\s?\([a-zA-Z\s\*]+\)[a-zA-Z]+)\n?/$1\{\n\t\n\}\n\n/g;
		print $line;
}

・結果

- (void)start{
	
}

- (BOOL)isRun{
	
}

- (NSString *)updateSetCount{
	
}