Skip to content

Commit 99454b3

Browse files
committed
right comment binder
1 parent 95ee299 commit 99454b3

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

gen/com/tang/intellij/lua/parser/LuaParser.java

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/tang/intellij/lua/lua.bnf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
DOUBLE_DIV = "//"
107107
]
108108

109-
hooks("localDef|assignStat|tableField") = [leftBinder="MY_LEFT_COMMENT_BINDER"]
109+
hooks("localDef|assignStat|tableField") = [leftBinder="MY_LEFT_COMMENT_BINDER" rightBinder="MY_RIGHT_COMMENT_BINDER"]
110110
hooks("globalFuncDef|localFuncDef|classMethodDef") = [leftBinder="MY_LEFT_COMMENT_BINDER"]
111111
hooks("fieldList") = [leftBinder="GREEDY_LEFT_BINDER" rightBinder="GREEDY_RIGHT_BINDER"]
112112
extends(".*Expr") = expr

src/main/java/com/tang/intellij/lua/psi/LuaParserUtil.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import static com.tang.intellij.lua.psi.LuaTypes.*;
2929

30+
@SuppressWarnings("unused")
3031
public class LuaParserUtil extends GeneratedParserUtilBase {
3132

3233
public static WhitespacesAndCommentsBinder MY_LEFT_COMMENT_BINDER = (list, b, tokenTextGetter) -> {
@@ -39,6 +40,21 @@ public class LuaParserUtil extends GeneratedParserUtilBase {
3940
return list.size();
4041
};
4142

43+
public static WhitespacesAndCommentsBinder MY_RIGHT_COMMENT_BINDER = (list, b, tokenTextGetter) -> {
44+
for (int i = 0; i < list.size(); i++) {
45+
IElementType type = list.get(i);
46+
if (type == DOC_COMMENT) {
47+
return i + 1;
48+
} else {
49+
String sequence = String.valueOf(tokenTextGetter.get(i));
50+
if (sequence.contains("\n")) {
51+
break;
52+
}
53+
}
54+
}
55+
return 0;
56+
};
57+
4258
public static boolean repeat(PsiBuilder builder_, int level_, Parser parser, int times) {
4359
PsiBuilder.Marker marker = builder_.mark();
4460
boolean r = true;

0 commit comments

Comments
 (0)