|
| 1 | +#include "CodeService/Format/Analyzer/FormatDocAnalyze.h" |
| 2 | +#include "LuaParser/Lexer/LuaTokenTypeDetail.h" |
| 3 | +#include "Util/StringUtil.h" |
| 4 | +#include "LuaParser/Lexer/TextReader.h" |
| 5 | + |
| 6 | +FormatDocAnalyze::FormatDocAnalyze() { |
| 7 | + |
| 8 | +} |
| 9 | + |
| 10 | +void FormatDocAnalyze::Analyze(FormatState &f, const LuaSyntaxTree &t) { |
| 11 | +// for (auto syntaxNode: t.GetSyntaxNodes()) { |
| 12 | +// switch (syntaxNode.GetTokenKind(t)) { |
| 13 | +// case TK_SHORT_COMMENT: { |
| 14 | +// if (syntaxNode.GetParent(t).GetSyntaxKind(t) == LuaSyntaxNodeKind::Block) { |
| 15 | +// |
| 16 | +// |
| 17 | +// break; |
| 18 | +// } |
| 19 | +// } |
| 20 | +// default: { |
| 21 | +// |
| 22 | +// } |
| 23 | +// } |
| 24 | +// } |
| 25 | +} |
| 26 | + |
| 27 | +void FormatDocAnalyze::ComplexAnalyze(FormatState &f, const LuaSyntaxTree &t) { |
| 28 | + FormatAnalyzer::ComplexAnalyze(f, t); |
| 29 | +} |
| 30 | + |
| 31 | +void |
| 32 | +FormatDocAnalyze::Query(FormatState &f, LuaSyntaxNode &syntaxNode, const LuaSyntaxTree &t, FormatResolve &resolve) { |
| 33 | + |
| 34 | +} |
| 35 | + |
| 36 | +bool IsWhiteSpaces(int c) { |
| 37 | + return c > 0 && std::isspace(c); |
| 38 | +} |
| 39 | + |
| 40 | +bool ActionStart(int c) { |
| 41 | + return c > 0 && std::isalpha(c); |
| 42 | +} |
| 43 | + |
| 44 | +bool ActionContinue(int c) { |
| 45 | + return c > 0 && (std::isalnum(c) || c == '-'); |
| 46 | +} |
| 47 | + |
| 48 | +void FormatDocAnalyze::AnalyzeDocFormat(LuaSyntaxNode n, FormatState &f, const LuaSyntaxTree &t) { |
| 49 | + auto text = n.GetText(t); |
| 50 | + TextReader textReader(text); |
| 51 | + |
| 52 | + enum class ParseState { |
| 53 | + Init, |
| 54 | + TagFormat, |
| 55 | + Action, |
| 56 | + List |
| 57 | + } state = ParseState::Init; |
| 58 | + |
| 59 | + while (!textReader.IsEof()) { |
| 60 | + textReader.ResetBuffer(); |
| 61 | + |
| 62 | + if (IsWhiteSpaces(textReader.GetCurrentChar())) { |
| 63 | + textReader.EatWhile(IsWhiteSpaces); |
| 64 | + continue; |
| 65 | + } |
| 66 | + |
| 67 | + switch (state) { |
| 68 | + case ParseState::Init: { |
| 69 | + if (textReader.GetCurrentChar() == '-') { |
| 70 | + auto dashNum = textReader.EatWhen('-'); |
| 71 | + if (dashNum == 3) { |
| 72 | + state = ParseState::TagFormat; |
| 73 | + break; |
| 74 | + } |
| 75 | + } |
| 76 | + return; |
| 77 | + } |
| 78 | + case ParseState::TagFormat: { |
| 79 | + if (textReader.GetCurrentChar() == '@') { |
| 80 | + textReader.NextChar(); |
| 81 | + textReader.EatWhile([](int c) { return c > 0 && std::isalpha(c); }); |
| 82 | + if (textReader.GetSaveText() == "format") { |
| 83 | + state = ParseState::Action; |
| 84 | + break; |
| 85 | + } |
| 86 | + } |
| 87 | + return; |
| 88 | + } |
| 89 | + case ParseState::Action: { |
| 90 | + if (ActionStart(textReader.GetCurrentChar())) { |
| 91 | + textReader.EatWhile(ActionContinue); |
| 92 | + auto action = textReader.GetSaveText(); |
| 93 | + if (action == "disable") { |
| 94 | + |
| 95 | + } else if (action == "disable-next") { |
| 96 | + |
| 97 | + } else if (action == "on") { |
| 98 | + state = ParseState::List; |
| 99 | + // todo |
| 100 | + break; |
| 101 | + } else if (action == "on-next") { |
| 102 | + state = ParseState::List; |
| 103 | + // todo |
| 104 | + |
| 105 | + break; |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + return; |
| 110 | + } |
| 111 | + case ParseState::List : { |
| 112 | + return; |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments