读书人

思前想后还是决定开工做EScript

发布时间: 2012-12-22 12:05:07 作者: rapoo

前思后想,还是决定开工做EScript
虽然有些忙,但觉得 CommentScriipt想法还是很不错的,决定开工做了

支持的语法现在考虑如下:

/*CS.replace(log.dir=@@kkkkkk@@)*/
//CS:util.smartReeplace(@@kkkkkk@@)
//CS:util.deleteNextLine

//CS:util.delete


//CS:util.end-delete


//CS:com.yourcorp.mergejs(<script src="utp-all.js>)

如有帮手一起来完成,更好啊。可以联系我 1 楼 javamonkey 2010-11-27 用antlr做,些技术含量。

用antlr定义语言容易,但现在还不能确定是否能用上antlr来定义普通文件,研究中 2 楼 javamonkey 2010-11-28 grammar T2;
txt:(line|others)*;
line: string NEWLINE others{System.out.println("get Content "+$others.text+"by command "+$string.text);};
string
: '#' ID
;
others
:ID NEWLINE;
WS : (' '|'\t')+ {skip();} ;
ID:('a'..'z')*;
NEWLINE: ('\r'? '\n')+;

补充一个原型

对如下文本解析
dfdfdfdfdfdfd
#hello
dfdfdfd
#cccccddfdf
fdfdfdf
3 楼 javamonkey 2010-12-05 再次完善了脚本语法,但离目标还很远,主要是还不熟习antlr,只能看他参考文档慢慢做了。
语法能解析如下输入文本

#CS: delnext
dfdfdfd
#CS: replace a {
dfdfdf
hello c
#CS:}


///////////////////////////////////////////////////////////

grammar T2;
options {backtrack=true;}
txt:(commandLine|contentLine|comment)*;
commandLine
scope {
boolean isSingleLine;
}
@init{
$commandLine::isSingleLine = true;
}
: commentChar 'CS:' key (csbegin {$commandLine::isSingleLine=false;System.out.println("mutipleLine found");})? NEWLINE parasLine (csend )? ;
csbegin
:'{';
csend
:commentChar 'CS:}' NEWLINE;
parasLine
:{$commandLine::isSingleLine}?=>singleLine{System.out.println("single line");}
|mutilLine{System.out.println("mutilple line");}
;
singleLine
:contentLine;
mutilLine
:contentLine+;

key
: replace
| 'delnext'
;
replace
:'replace a'
|'replace b'
;
contentLine
:STRING NEWLINE;
comment
:commentChar contentLine
;
commentChar
:'#'
|'//'
|'/*'
;
WS : (' '|'\t')+ {skip();} ;

STRING
:('a'..'z')*
;
NEWLINE: ('\r'? '\n')+;


读书人网 >编程

热点推荐