COBOL NOT AND OR | 特殊处理

This commit is contained in:
林万程
2022-04-09 22:46:31 +08:00
parent ce286c7d14
commit 63303a39da
4 changed files with 30 additions and 6 deletions

View File

@@ -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,

View File

@@ -13,11 +13,11 @@
IF if
有些程序 THEN 没有换行所以要加这个关键字
THEN
NOT(?! '| ?=) !
AND (?!') &&
OR (?!') ||
NOT(?= ) !
AND(?= ) &&
OR(?= ) ||
兼容字符字典
兼容字符字典
\=(?! ?') =
> >
< <
1 COBOL 必要【关键字】
13 NOT(?! '| ?=) NOT(?= ) !
14 AND (?!') AND(?= ) &&
15 OR (?!') OR(?= ) ||
16 兼容单字符字典 兼容字符串字典
17 \=(?! ?') =
18 > >
19 < <
20 PERFORM call
21 WS-
22 (?<!\w)\( (
23 \) )

View File

@@ -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)

View File

@@ -1,5 +1,5 @@
KEY = '1' 字典1
KEY NOT = '2' 字典2
KEY = '2' 字典2
HELLO-WORLD 你好世界
B001-A 程序A
A a
1 KEY = '1' 字典1
2 KEY NOT = '2' KEY = '2' 非 字典2 字典2
3 HELLO-WORLD 你好世界
4 B001-A 程序A
5 A a