COBOL NOT AND OR | 特殊处理
This commit is contained in:
@@ -34,11 +34,34 @@ public class LineExtUtils {
|
||||
}
|
||||
Map<String, Map<String, List<String>>> treeMap = ConfCache.treeMap(project, file);
|
||||
String text = document.getText(new TextRange(startOffset, endOffset));
|
||||
if ("cbl".equals(file.getExtension())) {
|
||||
text = cblNotAndOr(text);
|
||||
}
|
||||
String[] words = pattern.split(text);
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
return extDoc(keyMap, matcher, docMap, words, treeMap, project);
|
||||
}
|
||||
|
||||
private static final Pattern DICT_PATTERN = Pattern.compile("([\\w-]++) ?(NOT)? ?= ?'");
|
||||
private static final Pattern AND_OR_PATTERN = Pattern.compile("(AND|OR) ?'");
|
||||
|
||||
@NotNull
|
||||
private static String cblNotAndOr(String text) {
|
||||
// maybe faster than regexp
|
||||
if (!text.contains("=")) {
|
||||
return text;
|
||||
}
|
||||
Matcher matcher = DICT_PATTERN.matcher(text);
|
||||
if (!matcher.find()) {
|
||||
return text;
|
||||
}
|
||||
String key = matcher.group(1);
|
||||
// put NOT first
|
||||
text = matcher.replaceAll("$2 ( $1 = '");
|
||||
// add key after AND/OR
|
||||
return AND_OR_PATTERN.matcher(text).replaceAll("$1 "+ key + " = '");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String extDoc(@NotNull Map<String, Map<String, List<String>>> keyMap, @NotNull Matcher matcher,
|
||||
@NotNull Map<String, Map<String, List<String>>> docMap, @NotNull String[] words,
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
IF if
|
||||
有些程序 THEN 没有换行所以要加这个关键字
|
||||
THEN
|
||||
NOT(?! '| ?=) !
|
||||
AND (?!') &&
|
||||
OR (?!') ||
|
||||
NOT(?= ) !
|
||||
AND(?= ) &&
|
||||
OR(?= ) ||
|
||||
|
||||
兼容单字符字典
|
||||
兼容字符串字典
|
||||
\=(?! ?') =
|
||||
> >
|
||||
< <
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
|
||||
123456 INITIALIZE HELLO-WORLD
|
||||
IF KEY = '1' AND KEY NOT = '2' AND (B OR NOT C) THEN
|
||||
IF (KEY NOT = '1' AND '2')
|
||||
AND KEY NOT = '1' THEN
|
||||
MOVE WS-HELLO-WORLD TO HELLO-WORLD
|
||||
END IF
|
||||
TABLE(STRUCT)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
KEY = '1' 字典1
|
||||
KEY NOT = '2' 非 字典2
|
||||
KEY = '2' 字典2
|
||||
HELLO-WORLD 你好世界
|
||||
B001-A 程序A
|
||||
A a
|
||||
|
||||
|
Reference in New Issue
Block a user