MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / Parse

Method Parse

CodeFormatCore/src/Config/FunctionOption.cpp:5–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include "LuaParser/Lexer/LuaTokenTypeDetail.h"
4
5void FunctionOption::Parse(std::string_view option) {
6 std::string text(option);
7 auto virtualFile = LuaSource::From(std::move(text));
8 LuaLexer lexer(virtualFile);
9 lexer.Parse();
10 if (lexer.HasError()) {
11 return;
12 }
13 enum class ParseState {
14 None,
15 Key,
16 ExpectParam,
17 ExpectCommaOrFinish
18 } state = ParseState::None;
19 auto &tokens = lexer.GetTokens();
20 for (auto token: tokens) {
21 switch (state) {
22 case ParseState::None: {
23 if (token.TokenType != TK_NAME) {
24 return;
25 }
26 _key = std::string(
27 virtualFile->Slice(token.Range.StartOffset, token.Range.GetEndOffset()));
28 state = ParseState::Key;
29 break;
30 }
31 case ParseState::Key: {
32 if (token.TokenType != '(') {
33 return;
34 }
35 state = ParseState::ExpectParam;
36 break;
37 }
38 case ParseState::ExpectParam: {
39 if (token.TokenType == TK_NAME || token.TokenType == TK_NUMBER || token.TokenType == TK_STRING) {
40 _params.emplace_back(virtualFile->Slice(token.Range.StartOffset, token.Range.GetEndOffset()));
41 state = ParseState::ExpectCommaOrFinish;
42 } else if (token.TokenType == ')') {
43 return;
44 }
45 break;
46 }
47 case ParseState::ExpectCommaOrFinish: {
48 if (token.TokenType == ',') {
49 state = ParseState::ExpectParam;
50 } else if (token.TokenType == ')') {
51 return;
52 }
53 break;
54 }
55 }
56 }
57}
58
59std::string &FunctionOption::GetKey() {
60 return _key;

Callers

nothing calls this directly

Calls 5

stringFunction · 0.85
GetTokensMethod · 0.80
SliceMethod · 0.80
HasErrorMethod · 0.45
GetEndOffsetMethod · 0.45

Tested by

no test coverage detected