EScript 语法大概样子

可以对如下文本做解析:
<!-- CS: delnext -->
dfdfdfd
#CS: replace a {
dfdfdf
helloc
#CS:}

现在没有头绪的是STRING定义,如果这个能做好,那基本上可以着手开发代码了

后期支持嵌套,或者if,表达式等,辅助函数等觉得不太难,现在没有想铺的太大,做起来费劲。毕竟没有这么多时间

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

grammar T2;
options {backtrack=true;}
txt: (commandLine|contentLine|comment)*;
commandLine
scope {
boolean  isSingleLine;
boolean  hasEnd;
}
@init{
$commandLine::isSingleLine = true;
$commandLine::hasEnd = false;
}
:  commentChar 'CS:' key (csbegin {$commandLine::isSingleLine=false;})? commentCharEnd? NEWLINE  parasLine  (csend )?  ;
csbegin
: '{';
csend
: commentChar 'CS:}' commentCharEnd   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

: '#'
| '//'
| '/*' {$commandLine::hasEnd = true;}
| '<!-- '{$commandLine::hasEnd = true;}
;
commentCharEnd
: {$commandLine::hasEnd}?=>'*/'
| {$commandLine::hasEnd}?=>'-->'
|
;

WS  :   (' '|'\t')+ {skip();} ;

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






你可能感兴趣的:(script)