72 lines
2.9 KiB
C++
72 lines
2.9 KiB
C++
#pragma once
|
|
#include <vector>
|
|
#include <string>
|
|
#include <unordered_set>
|
|
#include "../protocol/protocol.hpp"
|
|
|
|
namespace tsl
|
|
{
|
|
enum class KeywordCategory
|
|
{
|
|
kProgramStructure, // program, function, procedure, unit, uses, implementation, interface, initialization, finalization
|
|
kDataTypes, // string, integer, boolean, int64, real, array
|
|
kClassTypes, // type, class, fakeclass, new
|
|
kClassModifiers, // override, overload, virtual, property, self, inherited
|
|
kAccessModifiers, // public, protected, private, published
|
|
kPropertyAccessors, // read, write
|
|
kConstructors, // create, destroy, operator
|
|
kVariableModifiers, // external, const, out, var, global, static
|
|
kConditionals, // if, else, then, case, of
|
|
kLoops, // for, while, do, downto, step, until, repeat, to
|
|
kBranchControl, // break, continue, goto, label, exit
|
|
kReturnControl, // return, debugreturn, debugrunenv, debugrunenvdo
|
|
kBlockControl, // begin, end, with
|
|
kReferences, // weakref, autoref
|
|
kNamespace, // namespace
|
|
kExceptions, // except, raise, try, finally, exceptobject
|
|
kLogicalOperators, // and, in, is, not, or
|
|
kArithmeticOperators, // div, mod
|
|
kBitwiseOperators, // ror, rol, shr, shl
|
|
kSetOperators, // union, minus, union2
|
|
kSqlControl, // select, vselect, sselect, update, delete, mselect
|
|
kSqlOperators, // on, like, in (SQL context)
|
|
kSqlKeywords, // sqlin, from, where, group, by, order, distinct, join
|
|
kCallingConventions, // cdecl, pascal, stdcall, safecall, fastcall, register
|
|
kSystemKeywords, // setuid, sudo
|
|
kBuiltinVariables, // paramcount, realparamcount, params, system, tslassigning, likeeps, likeepsrate
|
|
kBuiltinFunctions, // echo, mtic, mtoc
|
|
kBooleanConstants, // false, true
|
|
kMathConstants, // inf, nan
|
|
kNullConstants // nil
|
|
};
|
|
|
|
// 关键字信息
|
|
struct KeywordInfo
|
|
{
|
|
std::string keyword;
|
|
KeywordCategory category;
|
|
std::string description;
|
|
lsp::protocol::CompletionItemKind completion_kind;
|
|
};
|
|
|
|
class TslKeywords
|
|
{
|
|
public:
|
|
static const std::vector<KeywordInfo>& GetAllKeywords();
|
|
static std::vector<KeywordInfo> GetKeywordsByCategory(KeywordCategory category);
|
|
static std::vector<lsp::protocol::CompletionItem> GetCompletionItems(const std::string& prefix = "");
|
|
static bool IsKeyword(const std::string& word);
|
|
static KeywordCategory GetKeywordCategory(const std::string& word);
|
|
|
|
private:
|
|
static void InitKeywords();
|
|
static std::string ToLowerCase(const std::string& str);
|
|
static bool StartsWith(const std::string& str, const std::string& prefix);
|
|
|
|
private:
|
|
static std::vector<KeywordInfo> keywords_;
|
|
static std::unordered_set<std::string> keyword_set_;
|
|
static bool initialized_;
|
|
};
|
|
}
|