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')+;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值