Skip to content

Commit 4667bf9

Browse files
committed
support non standard token
1 parent 2a77910 commit 4667bf9

File tree

19 files changed

+294
-90
lines changed

19 files changed

+294
-90
lines changed

CONTRIBUTING.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Contributing Guidelines
2+
3+
Thank you for your interest in contributing to EmmyLuaCodeStyle! Here are some guidelines to help you make valuable contributions to this project.
4+
5+
## Submitting Issues
6+
7+
If you find any issues or have any suggestions, please submit them on the [Github Issues](https://github.com/CppCXY/EmmyLuaCodeStyle/issues) page. All feedback and suggestions are welcome and we will respond as quickly as possible.
8+
9+
## Code Contributions
10+
11+
### Committing Process
12+
13+
1. Fork the project.
14+
2. Create a new branch in your fork and work on it.
15+
3. Make sure that your code conforms to coding standards and unit testing requirements (you can refer to the project's README file).
16+
4. Submit a Pull Request to the master branch of the project.
17+
18+
### Coding Standards
19+
20+
Please follow these rules when writing code:
21+
22+
- Code style: Try to follow the .clang-format standard and use clang-format for automatic code formatting. If there are any deviations from this standard, please fix them.
23+
- Testing: Run tests before committing code. We use GTest as the testing framework. You can refer to the existing test files in the project and write more test cases.
24+
25+
## Disclaimer
26+
27+
We strive to keep this project running smoothly and do our best to review and test all code changes. However, we cannot be held responsible for any losses or damages resulting from using or running this project. By using or contributing to this project, you agree to this disclaimer.
28+
29+
(Generate by ChatGPT)

CodeFormatCore/include/CodeFormatCore/Config/LuaStyle.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#pragma once
22

3+
#include "LuaParser/Types/EndOfLineType.h"
4+
#include "LuaStyleEnum.h"
5+
#include <map>
6+
#include <memory>
37
#include <string>
48
#include <string_view>
5-
#include <memory>
69
#include <vector>
7-
#include <map>
8-
#include "LuaStyleEnum.h"
9-
#include "LuaParser/Types/EndOfLineType.h"
1010

1111
class LuaStyle {
1212
public:
@@ -46,9 +46,9 @@ class LuaStyle {
4646

4747
CallArgParentheses call_arg_parentheses = CallArgParentheses::Keep;
4848

49-
bool detect_end_of_line = true;
49+
bool detect_end_of_line = true;
5050

51-
bool insert_final_newline = true;
51+
bool insert_final_newline = true;
5252

5353
// [Space]
5454
bool space_around_table_field_list = true;
@@ -109,18 +109,18 @@ class LuaStyle {
109109
AlignChainExpr align_chain_expr = AlignChainExpr::None;
110110
// [Indent]
111111

112-
/*
112+
/*
113113
* if语句的条件可以无延续行缩进
114114
*/
115-
bool never_indent_before_if_condition = false;
115+
bool never_indent_before_if_condition = false;
116116

117-
bool never_indent_comment_on_if_branch = false;
117+
bool never_indent_comment_on_if_branch = false;
118118

119119
// [line space]
120120

121-
LineSpace line_space_after_if_statement = LineSpace(LineSpaceType::Keep);
121+
LineSpace line_space_after_if_statement = LineSpace(LineSpaceType::Keep);
122122

123-
LineSpace line_space_after_do_statement = LineSpace(LineSpaceType::Keep);
123+
LineSpace line_space_after_do_statement = LineSpace(LineSpaceType::Keep);
124124

125125
LineSpace line_space_after_while_statement = LineSpace(LineSpaceType::Keep);
126126

@@ -144,9 +144,9 @@ class LuaStyle {
144144
bool break_before_braces = false;
145145

146146
// [preference]
147-
bool ignore_space_after_colon = false;
147+
bool ignore_space_after_colon = false;
148148

149-
bool remove_call_expression_list_finish_comma = false;
149+
bool remove_call_expression_list_finish_comma = false;
150150

151151
// not implement now
152152
bool leading_comma_style = false;

CodeFormatCore/include/CodeFormatCore/Diagnostic/Spell/IdentifyParser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class IdentifyParser {
1818
End,
1919
};
2020

21-
IdentifyParser(std::string_view source);
21+
explicit IdentifyParser(std::string_view source);
2222

2323
void Parse();
2424

CodeFormatCore/src/Diagnostic/Spell/TextParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using namespace spell;
33

44
bool IsIdentifier(char ch) {
5-
return ch > 0 && (std::isalnum(ch) || ch == '_');
5+
return ch > 0 && (std::isalnum(ch) || ch == '_' || ch == '\'');
66
}
77

88
std::vector<Word> TextParser::ParseToWords(std::string_view source) {

CodeFormatLib/src/LuaCodeFormat.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ void LuaCodeFormat::LoadSpellDictionaryFromBuffer(const std::string &buffer) {
7070
Result<std::string> LuaCodeFormat::Reformat(const std::string &uri, std::string &&text, ConfigMap &configMap) {
7171
auto file = std::make_shared<LuaFile>(std::move(text));
7272
LuaLexer luaLexer(file);
73+
if (_supportNonStandardSymbol){
74+
luaLexer.SupportNonStandardSymbol();
75+
}
7376
luaLexer.Parse();
7477

7578
LuaParser p(file, std::move(luaLexer.GetTokens()));
@@ -95,6 +98,9 @@ Result<std::string> LuaCodeFormat::RangeFormat(const std::string &uri, FormatRan
9598
ConfigMap &configMap) {
9699
auto file = std::make_shared<LuaFile>(std::move(text));
97100
LuaLexer luaLexer(file);
101+
if (_supportNonStandardSymbol){
102+
luaLexer.SupportNonStandardSymbol();
103+
}
98104
luaLexer.Parse();
99105

100106
LuaParser p(file, std::move(luaLexer.GetTokens()));
@@ -122,6 +128,9 @@ LuaCodeFormat::TypeFormat(const std::string &uri, std::size_t line, std::size_t
122128
ConfigMap &configMap, ConfigMap &stringTypeOptions) {
123129
auto file = std::make_shared<LuaFile>(std::move(text));
124130
LuaLexer luaLexer(file);
131+
if (_supportNonStandardSymbol){
132+
luaLexer.SupportNonStandardSymbol();
133+
}
125134
luaLexer.Parse();
126135

127136
LuaParser p(file, std::move(luaLexer.GetTokens()));
@@ -147,6 +156,9 @@ LuaCodeFormat::TypeFormat(const std::string &uri, std::size_t line, std::size_t
147156
Result<std::vector<LuaDiagnosticInfo>> LuaCodeFormat::Diagnostic(const std::string &uri, std::string &&text) {
148157
auto file = std::make_shared<LuaFile>(std::move(text));
149158
LuaLexer luaLexer(file);
159+
if (_supportNonStandardSymbol){
160+
luaLexer.SupportNonStandardSymbol();
161+
}
150162
luaLexer.Parse();
151163

152164
LuaParser p(file, std::move(luaLexer.GetTokens()));
@@ -170,6 +182,9 @@ Result<std::vector<LuaDiagnosticInfo>> LuaCodeFormat::SpellCheck(const std::stri
170182
const CodeSpellChecker::CustomDictionary &tempDict) {
171183
auto file = std::make_shared<LuaFile>(std::move(text));
172184
LuaLexer luaLexer(file);
185+
if (_supportNonStandardSymbol){
186+
luaLexer.SupportNonStandardSymbol();
187+
}
173188
luaLexer.Parse();
174189

175190
LuaParser p(file, std::move(luaLexer.GetTokens()));
@@ -193,6 +208,9 @@ Result<std::vector<LuaDiagnosticInfo>> LuaCodeFormat::SpellCheck(const std::stri
193208
Result<std::vector<LuaDiagnosticInfo>> LuaCodeFormat::NameStyleCheck(const std::string &uri, std::string &&text) {
194209
auto file = std::make_shared<LuaFile>(std::move(text));
195210
LuaLexer luaLexer(file);
211+
if (_supportNonStandardSymbol){
212+
luaLexer.SupportNonStandardSymbol();
213+
}
196214
luaLexer.Parse();
197215

198216
LuaParser p(file, std::move(luaLexer.GetTokens()));

LuaParser/include/LuaParser/Ast/LuaSyntaxNode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include "../Lexer/LuaTokenKind.h"
4-
#include "../Types/TextRange.h"
3+
#include "LuaParser/Lexer/LuaTokenKind.h"
4+
#include "LuaParser/Types/TextRange.h"
55
#include "LuaSyntaxMultiKind.h"
66
#include "LuaSyntaxNodeKind.h"
77
#include <functional>

LuaParser/include/LuaParser/Ast/LuaSyntaxTree.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

3-
#include "../File/LuaFile.h"
4-
#include "../Lexer/LuaToken.h"
5-
#include "../Parse/Mark.h"
3+
#include "LuaParser/File/LuaFile.h"
4+
#include "LuaParser/Lexer/LuaToken.h"
5+
#include "LuaParser/Parse/Mark.h"
66
#include "LuaSyntaxNode.h"
77
#include "NodeOrToken.h"
88
#include <memory>

LuaParser/include/LuaParser/Ast/NodeOrToken.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include "../Lexer/LuaToken.h"
4-
#include "../Lexer/LuaTokenKind.h"
3+
#include "LuaParser/Lexer/LuaToken.h"
4+
#include "LuaParser/Lexer/LuaTokenKind.h"
55
#include "LuaSyntaxNodeKind.h"
66

77
enum class NodeOrTokenType {

LuaParser/include/LuaParser/File/LuaFile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include "../Types/EndOfLineType.h"
4-
#include "../Types/TextRange.h"
3+
#include "LuaParser/Types/EndOfLineType.h"
4+
#include "LuaParser/Types/TextRange.h"
55
#include <string>
66
#include <string_view>
77
#include <vector>

LuaParser/include/LuaParser/Lexer/LuaLexer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <vector>
88
#include <set>
99

10-
#include "../File/LuaFile.h"
10+
#include "LuaParser/File/LuaFile.h"
1111
#include "LuaToken.h"
1212
#include "LuaTokenError.h"
1313
#include "LuaTokenKind.h"
@@ -45,6 +45,8 @@ class LuaLexer
4545

4646
void ReadLongString(std::size_t sep);
4747

48+
void ReadLongCLikeComment();
49+
4850
void ReadString(int del);
4951

5052
void IncLinenumber();

0 commit comments

Comments
 (0)