Skip to content

Commit 3513cb8

Browse files
committed
修复一个存在语法错误但仍然格式化的bug
1 parent 7d25614 commit 3513cb8

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

LuaParser/src/LuaParser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ std::vector<LuaError>& LuaParser::GetErrors()
7070

7171
bool LuaParser::HasError() const
7272
{
73-
return !_errors.empty();
73+
return !_errors.empty() || !_tokenParser->ConsumeAllTokens();
7474
}
7575

7676
std::vector<LuaToken>& LuaParser::GetAllComments()
@@ -159,7 +159,6 @@ void LuaParser::BuildAstWithComment()
159159
}
160160
}
161161

162-
_tokenParser->ReleaseTokens();
163162
}
164163

165164
LuaParser::LuaParser(std::shared_ptr<LuaTokenParser> tokenParser)

LuaParser/src/LuaTokenParser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ std::shared_ptr<LuaFile> LuaTokenParser::GetFile()
171171
return _file;
172172
}
173173

174+
bool LuaTokenParser::ConsumeAllTokens()
175+
{
176+
return Current().TokenType == _eosToken.TokenType;
177+
}
178+
174179
LuaTokenType LuaTokenParser::Lex()
175180
{
176181
ResetBuffer();

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
该项目主要追求的是合理的格式化,多样的代码风格诊断
1010

11-
该项目除了提供语言服务实例,也提供独立的命令行工具CodeFormat,他能用于批量的代码格式化和代码风格检查(还存在很多问题,可以自行修改)
11+
该项目除了提供语言服务实例,也提供独立的命令行工具CodeFormat,他能用于批量的代码格式化和代码风格检查。
1212

1313
## 文档
1414

README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This project is an example of Lua code analysis\formatting\code diagnosis algori
88

99
The main pursuit of this project is reasonable formatting and diagnosis of various code styles
1010

11-
In addition to providing language service examples, the project also provides an independent command line tool CodeFormat, which can be used for batch code formatting and code style checking (there are still many problems, you can modify it yourself).
11+
In addition to providing language service examples, the project also provides an independent command line tool CodeFormat, which can be used for batch code formatting and code style checking.
1212

1313
## Document
1414

include/LuaParser/LuaTokenParser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class LuaTokenParser
4040
void ReleaseTokens();
4141

4242
std::shared_ptr<LuaFile> GetFile();
43+
44+
bool ConsumeAllTokens();
4345
private:
4446
static std::map<std::string, LuaTokenType, std::less<>> LuaReserved;
4547

0 commit comments

Comments
 (0)