如何检测代码的空间范围
代码的空间范围需要限制。例如:行数、列数等等。使用jrscript脚本可以简单的对代码的空间范围进行检测和标注。
脚本实现如下 (语法规范参考jrscript.cn:
#include "java.h"
#include "sys.h"
#include "style.h"
var JCMAXLIN = 200;
string checkJCLineNumber() hooks tk : @"JC" {
if(tk == null) return null;
string warning = null;
symbol [] symList=tk.values;
if(symList.length>0){
symbol lastSym=symList[symList.length-1];
if(JCMAXLIN<lastSym.line){
warning = "The lines of the code file is more than the scope.";
}
}
if(warning != null) {
string content = "// The lines of the code file is more than the scope by jrscript.cn";
log(content);
symbol [] symList = toSymbolList(content);
char [] styp = {'L'};
token ctk = createUnitToken(COMMONS, symList, styp);
insertToken(tk, ctk, 1, false);
}
return warning;
}
#include "java.h”表示hooks函数支持的编程语言。
hooks 方法定义 string checkJCLineNumber() hooks tk : @“JC” 表示该脚本将对检测的所有代码文件进行检测。根据检测结果,如果不符合规范的情况下 return “The lines of the code file is more than the scope.”。hooks函数返回非空时将对检测的文件根据结果进行标注。