Skip to content

Commit 5ac6293

Browse files
committed
optimize BNF
1 parent 33f61f1 commit 5ac6293

File tree

12 files changed

+36
-99
lines changed

12 files changed

+36
-99
lines changed

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

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/com/tang/intellij/lua/psi/LuaFieldList.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

gen/com/tang/intellij/lua/psi/LuaTableExpr.java

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

gen/com/tang/intellij/lua/psi/LuaTypes.java

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

gen/com/tang/intellij/lua/psi/LuaVisitor.java

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

gen/com/tang/intellij/lua/psi/impl/LuaFieldListImpl.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

gen/com/tang/intellij/lua/psi/impl/LuaTableExprImpl.java

Lines changed: 9 additions & 3 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/editor/formatter/LuaFormattingModelBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
5656
.after(DO).lineBreakInCode()
5757
.after(THEN).lineBreakInCode()
5858
.after(LOCAL).spaces(1) //local<SPACE>
59+
.before(COMMA).spaces(settings.SPACE_BEFORE_COMMA ? 1 : 0)
5960
.after(COMMA).spaces(settings.SPACE_AFTER_COMMA ? 1 : 0) //,<SPACE>
6061
.between(LCURLY, TABLE_FIELD).spaces(1) // {<SPACE>1, 2 }
6162
.between(TABLE_FIELD, RCURLY).spaces(1) // { 1, 2<SPACE>}
63+
.before(TABLE_FIELD_SEP).none() // { 1<SPACE>, 2 }
6264
.after(TABLE_FIELD_SEP).spaces(luaCodeStyleSettings.SPACE_AFTER_TABLE_FIELD_SEP ? 1 : 0) // { 1,<SPACE>2 }
6365
.before(BLOCK).blankLines(0)
6466
.afterInside(RPAREN, FUNC_BODY).lineBreakInCode()
@@ -68,7 +70,6 @@ private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
6870
.around(UNARY_OP).none()
6971
.around(ASSIGN).lineBreakOrForceSpace(false, settings.SPACE_AROUND_ASSIGNMENT_OPERATORS) // = 号两头不能换行
7072
.around(LuaSyntaxHighlighter.KEYWORD_TOKENS).spaces(1)
71-
.before(COMMA).spaces(settings.SPACE_BEFORE_COMMA ? 1 : 0)
7273
.before(SEMI).spaces(0);
7374
}
7475

src/main/java/com/tang/intellij/lua/editor/formatter/blocks/LuaScriptBlock.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ open class LuaScriptBlock(private val parent: LuaScriptBlock?,
4141

4242
//不创建 ASTBlock
4343
private val fakeBlockSet = TokenSet.create(
44-
BLOCK,
45-
FIELD_LIST
44+
BLOCK
4645
)
4746

4847
//回车时
@@ -71,21 +70,28 @@ open class LuaScriptBlock(private val parent: LuaScriptBlock?,
7170
}
7271

7372
private fun buildChildren(parent: ASTNode, results: MutableList<Block>) {
74-
var node: ASTNode? = parent.firstChildNode
73+
var child: ASTNode? = parent.firstChildNode
7574
val parentType = parent.elementType
7675
var childIndent = Indent.getNoneIndent()
7776
if (fakeBlockSet.contains(parentType)) {
7877
childIndent = Indent.getNormalIndent()
7978
}
8079

81-
while (node != null) {
82-
val nodeElementType = node.elementType
83-
if (fakeBlockSet.contains(nodeElementType)) {
84-
buildChildren(node, results)
85-
} else if (shouldCreateBlockFor(node)) {
86-
results.add(createBlock(node, childIndent, null))
80+
while (child != null) {
81+
val childType = child.elementType
82+
if (parentType == TABLE_EXPR ) {
83+
if (childType != LCURLY && childType != RCURLY)
84+
childIndent = Indent.getNormalIndent()
85+
else
86+
childIndent = Indent.getNoneIndent()
8787
}
88-
node = node.treeNext
88+
89+
if (fakeBlockSet.contains(childType)) {
90+
buildChildren(child, results)
91+
} else if (shouldCreateBlockFor(child)) {
92+
results.add(createBlock(child, childIndent, null))
93+
}
94+
child = child.treeNext
8995
}
9096
}
9197

src/main/java/com/tang/intellij/lua/lang/type/LuaTableType.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
package com.tang.intellij.lua.lang.type;
1818

1919
import com.tang.intellij.lua.psi.LuaClassField;
20-
import com.tang.intellij.lua.psi.LuaFieldList;
2120
import com.tang.intellij.lua.psi.LuaTableExpr;
2221
import com.tang.intellij.lua.psi.LuaTableField;
2322
import com.tang.intellij.lua.search.SearchContext;
2423
import org.jetbrains.annotations.NotNull;
2524

26-
import java.util.ArrayList;
2725
import java.util.List;
2826

2927
/**
@@ -62,11 +60,7 @@ public String getDisplayName() {
6260

6361
private void InitFieldList() {
6462
if (tableFields == null) {
65-
tableFields = new ArrayList<>();
66-
LuaFieldList fieldList = tableConstructor.getFieldList();
67-
if (fieldList != null) {
68-
tableFields.addAll(fieldList.getTableFieldList());
69-
}
63+
tableFields = tableConstructor.getTableFieldList();
7064
}
7165
}
7266

0 commit comments

Comments
 (0)