Skip to content

Commit 8adf3ec

Browse files
committed
支持扩展标识字符
1 parent cf82f9b commit 8adf3ec

File tree

9 files changed

+107
-68
lines changed

9 files changed

+107
-68
lines changed

3rd/uriparser/src/config.h

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

4444
#define PACKAGE_VERSION "0.9.5"
4545

46-
/* #undef HAVE_WPRINTF */
46+
#define HAVE_WPRINTF
4747
/* #undef HAVE_REALLOCARRAY */
4848

4949

CodeFormatServer/src/LanguageService.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "CodeFormatServer/Service/CompletionService.h"
1414
#include "Util/Url.h"
1515
#include "Util/format.h"
16+
#include "LuaParser/LuaIdentify.h"
1617

1718
using namespace std::placeholders;
1819

@@ -124,6 +125,14 @@ std::shared_ptr<vscode::InitializeResult> LanguageService::OnInitialize(std::sha
124125
}
125126
}
126127

128+
if(!param->initializationOptions.extensionChars.empty())
129+
{
130+
for(auto& c:param->initializationOptions.extensionChars)
131+
{
132+
LuaIdentify::AddIdentifyChar(c);
133+
}
134+
}
135+
127136
LanguageClient::GetInstance().SetRoot(param->rootPath);
128137
return result;
129138
}

CodeFormatServer/src/VSCode.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ void vscode::InitializationOptions::Deserialize(nlohmann::json json)
196196
{
197197
localeRoot = json["localeRoot"];
198198
}
199+
200+
if(json["extensionChars"].is_string())
201+
{
202+
extensionChars = json["extensionChars"];
203+
}
199204
}
200205

201206
void vscode::InitializeParams::Deserialize(nlohmann::json json)

LuaParser/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ target_sources(LuaParser PUBLIC
3030
${LuaParser_SOURCE_DIR}/src/TextRange.cpp
3131
${LuaParser_SOURCE_DIR}/src/LuaAstVisitor.cpp
3232
${LuaParser_SOURCE_DIR}/src/LuaFile.cpp
33-
${LuaParser_SOURCE_DIR}/src/LuaDefine.h
33+
${LuaParser_SOURCE_DIR}/src/LuaIdentify.cpp
3434
)
3535

3636
target_link_libraries(LuaParser Util)

LuaParser/src/LuaDefine.h

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

3+
#include "LuaParser/LuaIdentify.h"
34
#include <climits>
45

5-
// come from lua code
6-
76
const int EOZ = -1;
87

98
//accept UniCode IDentifiers
109
const unsigned char NONA = 0x01;
1110

12-
const unsigned char luai_ctype_[UCHAR_MAX + 2] = {
13-
0x00, /* EOZ */
14-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */
15-
0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
16-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */
17-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
18-
0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */
19-
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
20-
0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */
21-
0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
22-
0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */
23-
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
24-
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */
25-
0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05,
26-
0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */
27-
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
28-
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */
29-
0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00,
30-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 8. */
31-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
32-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 9. */
33-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
34-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* a. */
35-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
36-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* b. */
37-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
38-
0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, /* c. */
39-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
40-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* d. */
41-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
42-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* e. */
43-
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
44-
NONA, NONA, NONA, NONA, NONA, 0x00, 0x00, 0x00, /* f. */
45-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
46-
};
47-
48-
49-
#define ALPHABIT 0
50-
#define DIGITBIT 1
51-
#define PRINTBIT 2
52-
#define SPACEBIT 3
53-
#define XDIGITBIT 4
54-
55-
56-
#define MASK(B) (1 << (B))
57-
58-
59-
/*
60-
** add 1 to char to allow index -1 (EOZ)
61-
*/
62-
#define testprop(c,p) (luai_ctype_[(c)+1] & (p))
63-
64-
/*
65-
** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
66-
*/
67-
#define lislalpha(c) testprop(c, MASK(ALPHABIT))
68-
#define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
69-
#define lisdigit(c) testprop(c, MASK(DIGITBIT))
70-
#define lisspace(c) testprop(c, MASK(SPACEBIT))
71-
#define lisprint(c) testprop(c, MASK(PRINTBIT))
72-
#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
73-
74-
7511
/*
7612
** Priority table for binary operators.
7713
*/

LuaParser/src/LuaIdentify.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#pragma once
2+
3+
#include "LuaParser/LuaIdentify.h"
4+
#include "LuaDefine.h"
5+
6+
std::array<unsigned char, UCHAR_MAX + 2> LuaIdentify::LuaCharType = {
7+
0x00, /* EOZ */
8+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */
9+
0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
10+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */
11+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
12+
0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */
13+
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
14+
0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */
15+
0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
16+
0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */
17+
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
18+
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */
19+
0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05,
20+
0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */
21+
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
22+
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */
23+
0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00,
24+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 8. */
25+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
26+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 9. */
27+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
28+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* a. */
29+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
30+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* b. */
31+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
32+
0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, /* c. */
33+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
34+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* d. */
35+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
36+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* e. */
37+
NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
38+
NONA, NONA, NONA, NONA, NONA, 0x00, 0x00, 0x00, /* f. */
39+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
40+
};
41+
42+
void LuaIdentify::AddIdentifyChar(char ch)
43+
{
44+
if (ch < 0)
45+
{
46+
return;
47+
}
48+
LuaCharType[ch + 1] |= MASK(ALPHABIT);
49+
}

LuaParser/src/LuaTokenParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "LuaParser/LuaTokenParser.h"
22
#include <limits>
33
#include "LuaDefine.h"
4+
#include "LuaParser/LuaIdentify.h"
45
#include "LuaParser/LuaTokenTypeDetail.h"
56
#include "Util/format.h"
67
#include "Util/Utf8.h"
78

8-
99
std::map<std::string, LuaTokenType, std::less<>> LuaTokenParser::LuaReserved = {
1010
{"and", TK_AND},
1111
{"break", TK_BREAK},

include/CodeFormatServer/VSCode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class InitializationOptions : public Serializable
247247
std::vector<ConfigSource> editorConfigFiles;
248248
std::vector<ConfigSource> moduleConfigFiles;
249249
std::string localeRoot;
250+
std::string extensionChars;
250251
void Deserialize(nlohmann::json json) override;
251252
};
252253

include/LuaParser/LuaIdentify.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <climits>
4+
#include <array>
5+
6+
class LuaIdentify
7+
{
8+
public:
9+
static std::array<unsigned char, UCHAR_MAX + 2> LuaCharType;
10+
static void AddIdentifyChar(char ch);
11+
private:
12+
};
13+
14+
// 保持lua惯用法
15+
16+
#define ALPHABIT 0
17+
#define DIGITBIT 1
18+
#define PRINTBIT 2
19+
#define SPACEBIT 3
20+
#define XDIGITBIT 4
21+
22+
23+
#define MASK(B) (1 << (B))
24+
25+
26+
/*
27+
** add 1 to char to allow index -1 (EOZ)
28+
*/
29+
#define testprop(c,p) (LuaIdentify::LuaCharType[(c)+1] & (p))
30+
31+
/*
32+
** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
33+
*/
34+
#define lislalpha(c) testprop(c, MASK(ALPHABIT))
35+
#define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
36+
#define lisdigit(c) testprop(c, MASK(DIGITBIT))
37+
#define lisspace(c) testprop(c, MASK(SPACEBIT))
38+
#define lisprint(c) testprop(c, MASK(PRINTBIT))
39+
#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))

0 commit comments

Comments
 (0)