LanguageDefinitions.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. #include "TextEditor.h"
  2. static bool TokenizeCStyleString(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
  3. {
  4. const char* p = in_begin;
  5. if (*p == '"')
  6. {
  7. p++;
  8. while (p < in_end)
  9. {
  10. // handle end of string
  11. if (*p == '"')
  12. {
  13. out_begin = in_begin;
  14. out_end = p + 1;
  15. return true;
  16. }
  17. // handle escape character for "
  18. if (*p == '\\' && p + 1 < in_end && p[1] == '"')
  19. p++;
  20. p++;
  21. }
  22. }
  23. return false;
  24. }
  25. static bool TokenizeCStyleCharacterLiteral(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
  26. {
  27. const char* p = in_begin;
  28. if (*p == '\'')
  29. {
  30. p++;
  31. // handle escape characters
  32. if (p < in_end && *p == '\\')
  33. p++;
  34. if (p < in_end)
  35. p++;
  36. // handle end of character literal
  37. if (p < in_end && *p == '\'')
  38. {
  39. out_begin = in_begin;
  40. out_end = p + 1;
  41. return true;
  42. }
  43. }
  44. return false;
  45. }
  46. static bool TokenizeCStyleIdentifier(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
  47. {
  48. const char* p = in_begin;
  49. if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || *p == '_')
  50. {
  51. p++;
  52. while ((p < in_end) && ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || *p == '_'))
  53. p++;
  54. out_begin = in_begin;
  55. out_end = p;
  56. return true;
  57. }
  58. return false;
  59. }
  60. static bool TokenizeCStyleNumber(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
  61. {
  62. const char* p = in_begin;
  63. const bool startsWithNumber = *p >= '0' && *p <= '9';
  64. if (*p != '+' && *p != '-' && !startsWithNumber)
  65. return false;
  66. p++;
  67. bool hasNumber = startsWithNumber;
  68. while (p < in_end && (*p >= '0' && *p <= '9'))
  69. {
  70. hasNumber = true;
  71. p++;
  72. }
  73. if (hasNumber == false)
  74. return false;
  75. bool isFloat = false;
  76. bool isHex = false;
  77. bool isBinary = false;
  78. if (p < in_end)
  79. {
  80. if (*p == '.')
  81. {
  82. isFloat = true;
  83. p++;
  84. while (p < in_end && (*p >= '0' && *p <= '9'))
  85. p++;
  86. }
  87. else if (*p == 'x' || *p == 'X')
  88. {
  89. // hex formatted integer of the type 0xef80
  90. isHex = true;
  91. p++;
  92. while (p < in_end && ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') || (*p >= 'A' && *p <= 'F')))
  93. p++;
  94. }
  95. else if (*p == 'b' || *p == 'B')
  96. {
  97. // binary formatted integer of the type 0b01011101
  98. isBinary = true;
  99. p++;
  100. while (p < in_end && (*p >= '0' && *p <= '1'))
  101. p++;
  102. }
  103. }
  104. if (isHex == false && isBinary == false)
  105. {
  106. // floating point exponent
  107. if (p < in_end && (*p == 'e' || *p == 'E'))
  108. {
  109. isFloat = true;
  110. p++;
  111. if (p < in_end && (*p == '+' || *p == '-'))
  112. p++;
  113. bool hasDigits = false;
  114. while (p < in_end && (*p >= '0' && *p <= '9'))
  115. {
  116. hasDigits = true;
  117. p++;
  118. }
  119. if (hasDigits == false)
  120. return false;
  121. }
  122. // single precision floating point type
  123. if (p < in_end && *p == 'f')
  124. p++;
  125. }
  126. if (isFloat == false)
  127. {
  128. // integer size type
  129. while (p < in_end && (*p == 'u' || *p == 'U' || *p == 'l' || *p == 'L'))
  130. p++;
  131. }
  132. out_begin = in_begin;
  133. out_end = p;
  134. return true;
  135. }
  136. static bool TokenizeCStylePunctuation(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
  137. {
  138. (void)in_end;
  139. switch (*in_begin)
  140. {
  141. case '[':
  142. case ']':
  143. case '{':
  144. case '}':
  145. case '!':
  146. case '%':
  147. case '^':
  148. case '&':
  149. case '*':
  150. case '(':
  151. case ')':
  152. case '-':
  153. case '+':
  154. case '=':
  155. case '~':
  156. case '|':
  157. case '<':
  158. case '>':
  159. case '?':
  160. case ':':
  161. case '/':
  162. case ';':
  163. case ',':
  164. case '.':
  165. out_begin = in_begin;
  166. out_end = in_begin + 1;
  167. return true;
  168. }
  169. return false;
  170. }
  171. static bool TokenizeLuaStyleString(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
  172. {
  173. const char* p = in_begin;
  174. bool is_single_quote = false;
  175. bool is_double_quotes = false;
  176. bool is_double_square_brackets = false;
  177. switch (*p)
  178. {
  179. case '\'':
  180. is_single_quote = true;
  181. break;
  182. case '"':
  183. is_double_quotes = true;
  184. break;
  185. case '[':
  186. p++;
  187. if (p < in_end && *(p) == '[')
  188. is_double_square_brackets = true;
  189. break;
  190. }
  191. if (is_single_quote || is_double_quotes || is_double_square_brackets)
  192. {
  193. p++;
  194. while (p < in_end)
  195. {
  196. // handle end of string
  197. if ((is_single_quote && *p == '\'') || (is_double_quotes && *p == '"') || (is_double_square_brackets && *p == ']' && p + 1 < in_end && *(p + 1) == ']'))
  198. {
  199. out_begin = in_begin;
  200. if (is_double_square_brackets)
  201. out_end = p + 2;
  202. else
  203. out_end = p + 1;
  204. return true;
  205. }
  206. // handle escape character for "
  207. if (*p == '\\' && p + 1 < in_end && (is_single_quote || is_double_quotes))
  208. p++;
  209. p++;
  210. }
  211. }
  212. return false;
  213. }
  214. static bool TokenizeLuaStyleIdentifier(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
  215. {
  216. const char* p = in_begin;
  217. if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || *p == '_')
  218. {
  219. p++;
  220. while ((p < in_end) && ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || *p == '_'))
  221. p++;
  222. out_begin = in_begin;
  223. out_end = p;
  224. return true;
  225. }
  226. return false;
  227. }
  228. static bool TokenizeLuaStyleNumber(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
  229. {
  230. const char* p = in_begin;
  231. const bool startsWithNumber = *p >= '0' && *p <= '9';
  232. if (*p != '+' && *p != '-' && !startsWithNumber)
  233. return false;
  234. p++;
  235. bool hasNumber = startsWithNumber;
  236. while (p < in_end && (*p >= '0' && *p <= '9'))
  237. {
  238. hasNumber = true;
  239. p++;
  240. }
  241. if (hasNumber == false)
  242. return false;
  243. if (p < in_end)
  244. {
  245. if (*p == '.')
  246. {
  247. p++;
  248. while (p < in_end && (*p >= '0' && *p <= '9'))
  249. p++;
  250. }
  251. // floating point exponent
  252. if (p < in_end && (*p == 'e' || *p == 'E'))
  253. {
  254. p++;
  255. if (p < in_end && (*p == '+' || *p == '-'))
  256. p++;
  257. bool hasDigits = false;
  258. while (p < in_end && (*p >= '0' && *p <= '9'))
  259. {
  260. hasDigits = true;
  261. p++;
  262. }
  263. if (hasDigits == false)
  264. return false;
  265. }
  266. }
  267. out_begin = in_begin;
  268. out_end = p;
  269. return true;
  270. }
  271. static bool TokenizeLuaStylePunctuation(const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end)
  272. {
  273. (void)in_end;
  274. switch (*in_begin)
  275. {
  276. case '[':
  277. case ']':
  278. case '{':
  279. case '}':
  280. case '!':
  281. case '%':
  282. case '#':
  283. case '^':
  284. case '&':
  285. case '*':
  286. case '(':
  287. case ')':
  288. case '-':
  289. case '+':
  290. case '=':
  291. case '~':
  292. case '|':
  293. case '<':
  294. case '>':
  295. case '?':
  296. case ':':
  297. case '/':
  298. case ';':
  299. case ',':
  300. case '.':
  301. out_begin = in_begin;
  302. out_end = in_begin + 1;
  303. return true;
  304. }
  305. return false;
  306. }
  307. const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Cpp()
  308. {
  309. static bool inited = false;
  310. static LanguageDefinition langDef;
  311. if (!inited)
  312. {
  313. static const char* const cppKeywords[] = {
  314. "alignas", "alignof", "and", "and_eq", "asm", "atomic_cancel", "atomic_commit", "atomic_noexcept", "auto", "bitand", "bitor", "bool", "break", "case", "catch", "char", "char16_t", "char32_t", "class",
  315. "compl", "concept", "const", "constexpr", "const_cast", "continue", "decltype", "default", "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "float",
  316. "for", "friend", "goto", "if", "import", "inline", "int", "long", "module", "mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", "private", "protected", "public",
  317. "register", "reinterpret_cast", "requires", "return", "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "synchronized", "template", "this", "thread_local",
  318. "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq"
  319. };
  320. for (auto& k : cppKeywords)
  321. langDef.mKeywords.insert(k);
  322. static const char* const identifiers[] = {
  323. "abort", "abs", "acos", "asin", "atan", "atexit", "atof", "atoi", "atol", "ceil", "clock", "cosh", "ctime", "div", "exit", "fabs", "floor", "fmod", "getchar", "getenv", "isalnum", "isalpha", "isdigit", "isgraph",
  324. "ispunct", "isspace", "isupper", "kbhit", "log10", "log2", "log", "memcmp", "modf", "pow", "printf", "sprintf", "snprintf", "putchar", "putenv", "puts", "rand", "remove", "rename", "sinh", "sqrt", "srand", "strcat", "strcmp", "strerror", "time", "tolower", "toupper",
  325. "std", "string", "vector", "map", "unordered_map", "set", "unordered_set", "min", "max"
  326. };
  327. for (auto& k : identifiers)
  328. {
  329. Identifier id;
  330. id.mDeclaration = "Built-in function";
  331. langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
  332. }
  333. langDef.mTokenize = [](const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end, PaletteIndex& paletteIndex) -> bool
  334. {
  335. paletteIndex = PaletteIndex::Max;
  336. while (in_begin < in_end && isascii(*in_begin) && isblank(*in_begin))
  337. in_begin++;
  338. if (in_begin == in_end)
  339. {
  340. out_begin = in_end;
  341. out_end = in_end;
  342. paletteIndex = PaletteIndex::Default;
  343. }
  344. else if (TokenizeCStyleString(in_begin, in_end, out_begin, out_end))
  345. paletteIndex = PaletteIndex::String;
  346. else if (TokenizeCStyleCharacterLiteral(in_begin, in_end, out_begin, out_end))
  347. paletteIndex = PaletteIndex::CharLiteral;
  348. else if (TokenizeCStyleIdentifier(in_begin, in_end, out_begin, out_end))
  349. paletteIndex = PaletteIndex::Identifier;
  350. else if (TokenizeCStyleNumber(in_begin, in_end, out_begin, out_end))
  351. paletteIndex = PaletteIndex::Number;
  352. else if (TokenizeCStylePunctuation(in_begin, in_end, out_begin, out_end))
  353. paletteIndex = PaletteIndex::Punctuation;
  354. return paletteIndex != PaletteIndex::Max;
  355. };
  356. langDef.mCommentStart = "/*";
  357. langDef.mCommentEnd = "*/";
  358. langDef.mSingleLineComment = "//";
  359. langDef.mCaseSensitive = true;
  360. langDef.mName = "C++";
  361. inited = true;
  362. }
  363. return langDef;
  364. }
  365. const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Hlsl()
  366. {
  367. static bool inited = false;
  368. static LanguageDefinition langDef;
  369. if (!inited)
  370. {
  371. static const char* const keywords[] = {
  372. "AppendStructuredBuffer", "asm", "asm_fragment", "BlendState", "bool", "break", "Buffer", "ByteAddressBuffer", "case", "cbuffer", "centroid", "class", "column_major", "compile", "compile_fragment",
  373. "CompileShader", "const", "continue", "ComputeShader", "ConsumeStructuredBuffer", "default", "DepthStencilState", "DepthStencilView", "discard", "do", "double", "DomainShader", "dword", "else",
  374. "export", "extern", "false", "float", "for", "fxgroup", "GeometryShader", "groupshared", "half", "Hullshader", "if", "in", "inline", "inout", "InputPatch", "int", "interface", "line", "lineadj",
  375. "linear", "LineStream", "matrix", "min16float", "min10float", "min16int", "min12int", "min16uint", "namespace", "nointerpolation", "noperspective", "NULL", "out", "OutputPatch", "packoffset",
  376. "pass", "pixelfragment", "PixelShader", "point", "PointStream", "precise", "RasterizerState", "RenderTargetView", "return", "register", "row_major", "RWBuffer", "RWByteAddressBuffer", "RWStructuredBuffer",
  377. "RWTexture1D", "RWTexture1DArray", "RWTexture2D", "RWTexture2DArray", "RWTexture3D", "sample", "sampler", "SamplerState", "SamplerComparisonState", "shared", "snorm", "stateblock", "stateblock_state",
  378. "static", "string", "struct", "switch", "StructuredBuffer", "tbuffer", "technique", "technique10", "technique11", "texture", "Texture1D", "Texture1DArray", "Texture2D", "Texture2DArray", "Texture2DMS",
  379. "Texture2DMSArray", "Texture3D", "TextureCube", "TextureCubeArray", "true", "typedef", "triangle", "triangleadj", "TriangleStream", "uint", "uniform", "unorm", "unsigned", "vector", "vertexfragment",
  380. "VertexShader", "void", "volatile", "while",
  381. "bool1","bool2","bool3","bool4","double1","double2","double3","double4", "float1", "float2", "float3", "float4", "int1", "int2", "int3", "int4", "in", "out", "inout",
  382. "uint1", "uint2", "uint3", "uint4", "dword1", "dword2", "dword3", "dword4", "half1", "half2", "half3", "half4",
  383. "float1x1","float2x1","float3x1","float4x1","float1x2","float2x2","float3x2","float4x2",
  384. "float1x3","float2x3","float3x3","float4x3","float1x4","float2x4","float3x4","float4x4",
  385. "half1x1","half2x1","half3x1","half4x1","half1x2","half2x2","half3x2","half4x2",
  386. "half1x3","half2x3","half3x3","half4x3","half1x4","half2x4","half3x4","half4x4",
  387. };
  388. for (auto& k : keywords)
  389. langDef.mKeywords.insert(k);
  390. static const char* const identifiers[] = {
  391. "abort", "abs", "acos", "all", "AllMemoryBarrier", "AllMemoryBarrierWithGroupSync", "any", "asdouble", "asfloat", "asin", "asint", "asint", "asuint",
  392. "asuint", "atan", "atan2", "ceil", "CheckAccessFullyMapped", "clamp", "clip", "cos", "cosh", "countbits", "cross", "D3DCOLORtoUBYTE4", "ddx",
  393. "ddx_coarse", "ddx_fine", "ddy", "ddy_coarse", "ddy_fine", "degrees", "determinant", "DeviceMemoryBarrier", "DeviceMemoryBarrierWithGroupSync",
  394. "distance", "dot", "dst", "errorf", "EvaluateAttributeAtCentroid", "EvaluateAttributeAtSample", "EvaluateAttributeSnapped", "exp", "exp2",
  395. "f16tof32", "f32tof16", "faceforward", "firstbithigh", "firstbitlow", "floor", "fma", "fmod", "frac", "frexp", "fwidth", "GetRenderTargetSampleCount",
  396. "GetRenderTargetSamplePosition", "GroupMemoryBarrier", "GroupMemoryBarrierWithGroupSync", "InterlockedAdd", "InterlockedAnd", "InterlockedCompareExchange",
  397. "InterlockedCompareStore", "InterlockedExchange", "InterlockedMax", "InterlockedMin", "InterlockedOr", "InterlockedXor", "isfinite", "isinf", "isnan",
  398. "ldexp", "length", "lerp", "lit", "log", "log10", "log2", "mad", "max", "min", "modf", "msad4", "mul", "noise", "normalize", "pow", "printf",
  399. "Process2DQuadTessFactorsAvg", "Process2DQuadTessFactorsMax", "Process2DQuadTessFactorsMin", "ProcessIsolineTessFactors", "ProcessQuadTessFactorsAvg",
  400. "ProcessQuadTessFactorsMax", "ProcessQuadTessFactorsMin", "ProcessTriTessFactorsAvg", "ProcessTriTessFactorsMax", "ProcessTriTessFactorsMin",
  401. "radians", "rcp", "reflect", "refract", "reversebits", "round", "rsqrt", "saturate", "sign", "sin", "sincos", "sinh", "smoothstep", "sqrt", "step",
  402. "tan", "tanh", "tex1D", "tex1D", "tex1Dbias", "tex1Dgrad", "tex1Dlod", "tex1Dproj", "tex2D", "tex2D", "tex2Dbias", "tex2Dgrad", "tex2Dlod", "tex2Dproj",
  403. "tex3D", "tex3D", "tex3Dbias", "tex3Dgrad", "tex3Dlod", "tex3Dproj", "texCUBE", "texCUBE", "texCUBEbias", "texCUBEgrad", "texCUBElod", "texCUBEproj", "transpose", "trunc"
  404. };
  405. for (auto& k : identifiers)
  406. {
  407. Identifier id;
  408. id.mDeclaration = "Built-in function";
  409. langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
  410. }
  411. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([ \t]*#[ \t]*[a-zA-Z_]+)##", PaletteIndex::Preprocessor));
  412. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(L?\"(\\.|[^\"])*\")##", PaletteIndex::String));
  413. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(\'\\?[^\']\')##", PaletteIndex::CharLiteral));
  414. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?)##", PaletteIndex::Number));
  415. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?[0-9]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
  416. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[0-7]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
  417. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?)##", PaletteIndex::Number));
  418. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([a-zA-Z_][a-zA-Z0-9_]*)##", PaletteIndex::Identifier));
  419. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.])##", PaletteIndex::Punctuation));
  420. langDef.mCommentStart = "/*";
  421. langDef.mCommentEnd = "*/";
  422. langDef.mSingleLineComment = "//";
  423. langDef.mCaseSensitive = true;
  424. langDef.mName = "HLSL";
  425. inited = true;
  426. }
  427. return langDef;
  428. }
  429. const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Glsl()
  430. {
  431. static bool inited = false;
  432. static LanguageDefinition langDef;
  433. if (!inited)
  434. {
  435. static const char* const keywords[] = {
  436. "auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "inline", "int", "long", "register", "restrict", "return", "short",
  437. "signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", "while", "_Alignas", "_Alignof", "_Atomic", "_Bool", "_Complex", "_Generic", "_Imaginary",
  438. "_Noreturn", "_Static_assert", "_Thread_local"
  439. };
  440. for (auto& k : keywords)
  441. langDef.mKeywords.insert(k);
  442. static const char* const identifiers[] = {
  443. "abort", "abs", "acos", "asin", "atan", "atexit", "atof", "atoi", "atol", "ceil", "clock", "cosh", "ctime", "div", "exit", "fabs", "floor", "fmod", "getchar", "getenv", "isalnum", "isalpha", "isdigit", "isgraph",
  444. "ispunct", "isspace", "isupper", "kbhit", "log10", "log2", "log", "memcmp", "modf", "pow", "putchar", "putenv", "puts", "rand", "remove", "rename", "sinh", "sqrt", "srand", "strcat", "strcmp", "strerror", "time", "tolower", "toupper"
  445. };
  446. for (auto& k : identifiers)
  447. {
  448. Identifier id;
  449. id.mDeclaration = "Built-in function";
  450. langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
  451. }
  452. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([ \t]*#[ \t]*[a-zA-Z_]+)##", PaletteIndex::Preprocessor));
  453. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(L?\"(\\.|[^\"])*\")##", PaletteIndex::String));
  454. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(\'\\?[^\']\')##", PaletteIndex::CharLiteral));
  455. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?)##", PaletteIndex::Number));
  456. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?[0-9]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
  457. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[0-7]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
  458. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?)##", PaletteIndex::Number));
  459. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([a-zA-Z_][a-zA-Z0-9_]*)##", PaletteIndex::Identifier));
  460. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.])##", PaletteIndex::Punctuation));
  461. langDef.mCommentStart = "/*";
  462. langDef.mCommentEnd = "*/";
  463. langDef.mSingleLineComment = "//";
  464. langDef.mCaseSensitive = true;
  465. langDef.mName = "GLSL";
  466. inited = true;
  467. }
  468. return langDef;
  469. }
  470. const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Python()
  471. {
  472. static bool inited = false;
  473. static LanguageDefinition langDef;
  474. if (!inited)
  475. {
  476. static const char* const keywords[] = {
  477. "False", "await", "else", "import", "pass", "None", "break", "except", "in", "raise", "True", "class", "finally", "is", "return", "and", "continue", "for", "lambda", "try", "as", "def", "from", "nonlocal", "while", "assert", "del", "global", "not", "with", "async", "elif", "if", "or", "yield"
  478. };
  479. for (auto& k : keywords)
  480. langDef.mKeywords.insert(k);
  481. static const char* const identifiers[] = {
  482. "abs", "aiter", "all", "any", "anext", "ascii", "bin", "bool", "breakpoint", "bytearray", "bytes", "callable", "chr", "classmethod", "compile", "complex", "delattr", "dict", "dir", "divmod", "enumerate", "eval", "exec", "filter", "float", "format", "frozenset", "getattr", "globals", "hasattr", "hash", "help", "hex", "id", "input", "int", "isinstance", "issubclass", "iter", "len", "list", "locals", "map", "max", "memoryview", "min", "next", "object", "oct", "open", "ord", "pow", "print", "property", "range", "repr", "reversed", "round", "set", "setattr", "slice", "sorted", "staticmethod", "str", "sum", "super", "tuple", "type", "vars", "zip", "__import__"
  483. };
  484. for (auto& k : identifiers)
  485. {
  486. Identifier id;
  487. id.mDeclaration = "Built-in function";
  488. langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
  489. }
  490. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##((b|u|f|r)?\"(\\.|[^\"])*\")##", PaletteIndex::String));
  491. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##((b|u|f|r)?'(\\.|[^'])*')##", PaletteIndex::String));
  492. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?)##", PaletteIndex::Number));
  493. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?[0-9]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
  494. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[0-7]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
  495. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?)##", PaletteIndex::Number));
  496. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([a-zA-Z_][a-zA-Z0-9_]*)##", PaletteIndex::Identifier));
  497. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.\:])##", PaletteIndex::Punctuation));
  498. langDef.mCommentStart = "\"\"\"";
  499. langDef.mCommentEnd = "\"\"\"";
  500. langDef.mSingleLineComment = "#";
  501. langDef.mCaseSensitive = true;
  502. langDef.mName = "Python";
  503. inited = true;
  504. }
  505. return langDef;
  506. }
  507. const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::C()
  508. {
  509. static bool inited = false;
  510. static LanguageDefinition langDef;
  511. if (!inited)
  512. {
  513. static const char* const keywords[] = {
  514. "auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "inline", "int", "long", "register", "restrict", "return", "short",
  515. "signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", "while", "_Alignas", "_Alignof", "_Atomic", "_Bool", "_Complex", "_Generic", "_Imaginary",
  516. "_Noreturn", "_Static_assert", "_Thread_local"
  517. };
  518. for (auto& k : keywords)
  519. langDef.mKeywords.insert(k);
  520. static const char* const identifiers[] = {
  521. "abort", "abs", "acos", "asin", "atan", "atexit", "atof", "atoi", "atol", "ceil", "clock", "cosh", "ctime", "div", "exit", "fabs", "floor", "fmod", "getchar", "getenv", "isalnum", "isalpha", "isdigit", "isgraph",
  522. "ispunct", "isspace", "isupper", "kbhit", "log10", "log2", "log", "memcmp", "modf", "pow", "putchar", "putenv", "puts", "rand", "remove", "rename", "sinh", "sqrt", "srand", "strcat", "strcmp", "strerror", "time", "tolower", "toupper"
  523. };
  524. for (auto& k : identifiers)
  525. {
  526. Identifier id;
  527. id.mDeclaration = "Built-in function";
  528. langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
  529. }
  530. langDef.mTokenize = [](const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end, PaletteIndex& paletteIndex) -> bool
  531. {
  532. paletteIndex = PaletteIndex::Max;
  533. while (in_begin < in_end && isascii(*in_begin) && isblank(*in_begin))
  534. in_begin++;
  535. if (in_begin == in_end)
  536. {
  537. out_begin = in_end;
  538. out_end = in_end;
  539. paletteIndex = PaletteIndex::Default;
  540. }
  541. else if (TokenizeCStyleString(in_begin, in_end, out_begin, out_end))
  542. paletteIndex = PaletteIndex::String;
  543. else if (TokenizeCStyleCharacterLiteral(in_begin, in_end, out_begin, out_end))
  544. paletteIndex = PaletteIndex::CharLiteral;
  545. else if (TokenizeCStyleIdentifier(in_begin, in_end, out_begin, out_end))
  546. paletteIndex = PaletteIndex::Identifier;
  547. else if (TokenizeCStyleNumber(in_begin, in_end, out_begin, out_end))
  548. paletteIndex = PaletteIndex::Number;
  549. else if (TokenizeCStylePunctuation(in_begin, in_end, out_begin, out_end))
  550. paletteIndex = PaletteIndex::Punctuation;
  551. return paletteIndex != PaletteIndex::Max;
  552. };
  553. langDef.mCommentStart = "/*";
  554. langDef.mCommentEnd = "*/";
  555. langDef.mSingleLineComment = "//";
  556. langDef.mCaseSensitive = true;
  557. langDef.mName = "C";
  558. inited = true;
  559. }
  560. return langDef;
  561. }
  562. const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Sql()
  563. {
  564. static bool inited = false;
  565. static LanguageDefinition langDef;
  566. if (!inited)
  567. {
  568. static const char* const keywords[] = {
  569. "ADD", "EXCEPT", "PERCENT", "ALL", "EXEC", "PLAN", "ALTER", "EXECUTE", "PRECISION", "AND", "EXISTS", "PRIMARY", "ANY", "EXIT", "PRINT", "AS", "FETCH", "PROC", "ASC", "FILE", "PROCEDURE",
  570. "AUTHORIZATION", "FILLFACTOR", "PUBLIC", "BACKUP", "FOR", "RAISERROR", "BEGIN", "FOREIGN", "READ", "BETWEEN", "FREETEXT", "READTEXT", "BREAK", "FREETEXTTABLE", "RECONFIGURE",
  571. "BROWSE", "FROM", "REFERENCES", "BULK", "FULL", "REPLICATION", "BY", "FUNCTION", "RESTORE", "CASCADE", "GOTO", "RESTRICT", "CASE", "GRANT", "RETURN", "CHECK", "GROUP", "REVOKE",
  572. "CHECKPOINT", "HAVING", "RIGHT", "CLOSE", "HOLDLOCK", "ROLLBACK", "CLUSTERED", "IDENTITY", "ROWCOUNT", "COALESCE", "IDENTITY_INSERT", "ROWGUIDCOL", "COLLATE", "IDENTITYCOL", "RULE",
  573. "COLUMN", "IF", "SAVE", "COMMIT", "IN", "SCHEMA", "COMPUTE", "INDEX", "SELECT", "CONSTRAINT", "INNER", "SESSION_USER", "CONTAINS", "INSERT", "SET", "CONTAINSTABLE", "INTERSECT", "SETUSER",
  574. "CONTINUE", "INTO", "SHUTDOWN", "CONVERT", "IS", "SOME", "CREATE", "JOIN", "STATISTICS", "CROSS", "KEY", "SYSTEM_USER", "CURRENT", "KILL", "TABLE", "CURRENT_DATE", "LEFT", "TEXTSIZE",
  575. "CURRENT_TIME", "LIKE", "THEN", "CURRENT_TIMESTAMP", "LINENO", "TO", "CURRENT_USER", "LOAD", "TOP", "CURSOR", "NATIONAL", "TRAN", "DATABASE", "NOCHECK", "TRANSACTION",
  576. "DBCC", "NONCLUSTERED", "TRIGGER", "DEALLOCATE", "NOT", "TRUNCATE", "DECLARE", "NULL", "TSEQUAL", "DEFAULT", "NULLIF", "UNION", "DELETE", "OF", "UNIQUE", "DENY", "OFF", "UPDATE",
  577. "DESC", "OFFSETS", "UPDATETEXT", "DISK", "ON", "USE", "DISTINCT", "OPEN", "USER", "DISTRIBUTED", "OPENDATASOURCE", "VALUES", "DOUBLE", "OPENQUERY", "VARYING","DROP", "OPENROWSET", "VIEW",
  578. "DUMMY", "OPENXML", "WAITFOR", "DUMP", "OPTION", "WHEN", "ELSE", "OR", "WHERE", "END", "ORDER", "WHILE", "ERRLVL", "OUTER", "WITH", "ESCAPE", "OVER", "WRITETEXT"
  579. };
  580. for (auto& k : keywords)
  581. langDef.mKeywords.insert(k);
  582. static const char* const identifiers[] = {
  583. "ABS", "ACOS", "ADD_MONTHS", "ASCII", "ASCIISTR", "ASIN", "ATAN", "ATAN2", "AVG", "BFILENAME", "BIN_TO_NUM", "BITAND", "CARDINALITY", "CASE", "CAST", "CEIL",
  584. "CHARTOROWID", "CHR", "COALESCE", "COMPOSE", "CONCAT", "CONVERT", "CORR", "COS", "COSH", "COUNT", "COVAR_POP", "COVAR_SAMP", "CUME_DIST", "CURRENT_DATE",
  585. "CURRENT_TIMESTAMP", "DBTIMEZONE", "DECODE", "DECOMPOSE", "DENSE_RANK", "DUMP", "EMPTY_BLOB", "EMPTY_CLOB", "EXP", "EXTRACT", "FIRST_VALUE", "FLOOR", "FROM_TZ", "GREATEST",
  586. "GROUP_ID", "HEXTORAW", "INITCAP", "INSTR", "INSTR2", "INSTR4", "INSTRB", "INSTRC", "LAG", "LAST_DAY", "LAST_VALUE", "LEAD", "LEAST", "LENGTH", "LENGTH2", "LENGTH4",
  587. "LENGTHB", "LENGTHC", "LISTAGG", "LN", "LNNVL", "LOCALTIMESTAMP", "LOG", "LOWER", "LPAD", "LTRIM", "MAX", "MEDIAN", "MIN", "MOD", "MONTHS_BETWEEN", "NANVL", "NCHR",
  588. "NEW_TIME", "NEXT_DAY", "NTH_VALUE", "NULLIF", "NUMTODSINTERVAL", "NUMTOYMINTERVAL", "NVL", "NVL2", "POWER", "RANK", "RAWTOHEX", "REGEXP_COUNT", "REGEXP_INSTR",
  589. "REGEXP_REPLACE", "REGEXP_SUBSTR", "REMAINDER", "REPLACE", "ROUND", "ROWNUM", "RPAD", "RTRIM", "SESSIONTIMEZONE", "SIGN", "SIN", "SINH",
  590. "SOUNDEX", "SQRT", "STDDEV", "SUBSTR", "SUM", "SYS_CONTEXT", "SYSDATE", "SYSTIMESTAMP", "TAN", "TANH", "TO_CHAR", "TO_CLOB", "TO_DATE", "TO_DSINTERVAL", "TO_LOB",
  591. "TO_MULTI_BYTE", "TO_NCLOB", "TO_NUMBER", "TO_SINGLE_BYTE", "TO_TIMESTAMP", "TO_TIMESTAMP_TZ", "TO_YMINTERVAL", "TRANSLATE", "TRIM", "TRUNC", "TZ_OFFSET", "UID", "UPPER",
  592. "USER", "USERENV", "VAR_POP", "VAR_SAMP", "VARIANCE", "VSIZE"
  593. };
  594. for (auto& k : identifiers)
  595. {
  596. Identifier id;
  597. id.mDeclaration = "Built-in function";
  598. langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
  599. }
  600. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(L?\"(\\.|[^\"])*\")##", PaletteIndex::String));
  601. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(\'[^\']*\')##", PaletteIndex::String));
  602. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?)##", PaletteIndex::Number));
  603. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?[0-9]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
  604. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[0-7]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
  605. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?)##", PaletteIndex::Number));
  606. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([a-zA-Z_][a-zA-Z0-9_]*)##", PaletteIndex::Identifier));
  607. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.])##", PaletteIndex::Punctuation));
  608. langDef.mCommentStart = "/*";
  609. langDef.mCommentEnd = "*/";
  610. langDef.mSingleLineComment = "--";
  611. langDef.mCaseSensitive = false;
  612. langDef.mName = "SQL";
  613. inited = true;
  614. }
  615. return langDef;
  616. }
  617. const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::AngelScript()
  618. {
  619. static bool inited = false;
  620. static LanguageDefinition langDef;
  621. if (!inited)
  622. {
  623. static const char* const keywords[] = {
  624. "and", "abstract", "auto", "bool", "break", "case", "cast", "class", "const", "continue", "default", "do", "double", "else", "enum", "false", "final", "float", "for",
  625. "from", "funcdef", "function", "get", "if", "import", "in", "inout", "int", "interface", "int8", "int16", "int32", "int64", "is", "mixin", "namespace", "not",
  626. "null", "or", "out", "override", "private", "protected", "return", "set", "shared", "super", "switch", "this ", "true", "typedef", "uint", "uint8", "uint16", "uint32",
  627. "uint64", "void", "while", "xor"
  628. };
  629. for (auto& k : keywords)
  630. langDef.mKeywords.insert(k);
  631. static const char* const identifiers[] = {
  632. "cos", "sin", "tab", "acos", "asin", "atan", "atan2", "cosh", "sinh", "tanh", "log", "log10", "pow", "sqrt", "abs", "ceil", "floor", "fraction", "closeTo", "fpFromIEEE", "fpToIEEE",
  633. "complex", "opEquals", "opAddAssign", "opSubAssign", "opMulAssign", "opDivAssign", "opAdd", "opSub", "opMul", "opDiv"
  634. };
  635. for (auto& k : identifiers)
  636. {
  637. Identifier id;
  638. id.mDeclaration = "Built-in function";
  639. langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
  640. }
  641. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(L?\"(\\.|[^\"])*\")##", PaletteIndex::String));
  642. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(\'\\?[^\']\')##", PaletteIndex::String));
  643. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?)##", PaletteIndex::Number));
  644. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?[0-9]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
  645. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[0-7]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
  646. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?)##", PaletteIndex::Number));
  647. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([a-zA-Z_][a-zA-Z0-9_]*)##", PaletteIndex::Identifier));
  648. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.])##", PaletteIndex::Punctuation));
  649. langDef.mCommentStart = "/*";
  650. langDef.mCommentEnd = "*/";
  651. langDef.mSingleLineComment = "//";
  652. langDef.mCaseSensitive = true;
  653. langDef.mName = "AngelScript";
  654. inited = true;
  655. }
  656. return langDef;
  657. }
  658. const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Lua()
  659. {
  660. static bool inited = false;
  661. static LanguageDefinition langDef;
  662. if (!inited)
  663. {
  664. static const char* const keywords[] = {
  665. "and", "break", "do", "else", "elseif", "end", "false", "for", "function", "goto", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while"
  666. };
  667. for (auto& k : keywords)
  668. langDef.mKeywords.insert(k);
  669. static const char* const identifiers[] = {
  670. "assert", "collectgarbage", "dofile", "error", "getmetatable", "ipairs", "loadfile", "load", "loadstring", "next", "pairs", "pcall", "print", "rawequal", "rawlen", "rawget", "rawset",
  671. "select", "setmetatable", "tonumber", "tostring", "type", "xpcall", "_G", "_VERSION","arshift", "band", "bnot", "bor", "bxor", "btest", "extract", "lrotate", "lshift", "replace",
  672. "rrotate", "rshift", "create", "resume", "running", "status", "wrap", "yield", "isyieldable", "debug","getuservalue", "gethook", "getinfo", "getlocal", "getregistry", "getmetatable",
  673. "getupvalue", "upvaluejoin", "upvalueid", "setuservalue", "sethook", "setlocal", "setmetatable", "setupvalue", "traceback", "close", "flush", "input", "lines", "open", "output", "popen",
  674. "read", "tmpfile", "type", "write", "close", "flush", "lines", "read", "seek", "setvbuf", "write", "__gc", "__tostring", "abs", "acos", "asin", "atan", "ceil", "cos", "deg", "exp", "tointeger",
  675. "floor", "fmod", "ult", "log", "max", "min", "modf", "rad", "random", "randomseed", "sin", "sqrt", "string", "tan", "type", "atan2", "cosh", "sinh", "tanh",
  676. "pow", "frexp", "ldexp", "log10", "pi", "huge", "maxinteger", "mininteger", "loadlib", "searchpath", "seeall", "preload", "cpath", "path", "searchers", "loaded", "module", "require", "clock",
  677. "date", "difftime", "execute", "exit", "getenv", "remove", "rename", "setlocale", "time", "tmpname", "byte", "char", "dump", "find", "format", "gmatch", "gsub", "len", "lower", "match", "rep",
  678. "reverse", "sub", "upper", "pack", "packsize", "unpack", "concat", "maxn", "insert", "pack", "unpack", "remove", "move", "sort", "offset", "codepoint", "char", "len", "codes", "charpattern",
  679. "coroutine", "table", "io", "os", "string", "utf8", "bit32", "math", "debug", "package"
  680. };
  681. for (auto& k : identifiers)
  682. {
  683. Identifier id;
  684. id.mDeclaration = "Built-in function";
  685. langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
  686. }
  687. langDef.mTokenize = [](const char* in_begin, const char* in_end, const char*& out_begin, const char*& out_end, PaletteIndex& paletteIndex) -> bool
  688. {
  689. paletteIndex = PaletteIndex::Max;
  690. while (in_begin < in_end && isascii(*in_begin) && isblank(*in_begin))
  691. in_begin++;
  692. if (in_begin == in_end)
  693. {
  694. out_begin = in_end;
  695. out_end = in_end;
  696. paletteIndex = PaletteIndex::Default;
  697. }
  698. else if (TokenizeLuaStyleString(in_begin, in_end, out_begin, out_end))
  699. paletteIndex = PaletteIndex::String;
  700. else if (TokenizeLuaStyleIdentifier(in_begin, in_end, out_begin, out_end))
  701. paletteIndex = PaletteIndex::Identifier;
  702. else if (TokenizeLuaStyleNumber(in_begin, in_end, out_begin, out_end))
  703. paletteIndex = PaletteIndex::Number;
  704. else if (TokenizeLuaStylePunctuation(in_begin, in_end, out_begin, out_end))
  705. paletteIndex = PaletteIndex::Punctuation;
  706. return paletteIndex != PaletteIndex::Max;
  707. };
  708. langDef.mCommentStart = "--[[";
  709. langDef.mCommentEnd = "]]";
  710. langDef.mSingleLineComment = "--";
  711. langDef.mCaseSensitive = true;
  712. langDef.mName = "Lua";
  713. inited = true;
  714. }
  715. return langDef;
  716. }
  717. const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Cs()
  718. {
  719. static bool inited = false;
  720. static LanguageDefinition langDef;
  721. if (!inited)
  722. {
  723. static const char* const keywords[] = {
  724. "abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "in (generic modifier)", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "out (generic modifier)", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "using static", "void", "volatile", "while"
  725. };
  726. for (auto& k : keywords)
  727. langDef.mKeywords.insert(k);
  728. static const char* const identifiers[] = {
  729. "add", "alias", "ascending", "async", "await", "descending", "dynamic", "from", "get", "global", "group", "into", "join", "let", "orderby", "partial", "remove", "select", "set", "value", "var", "when", "where", "yield"
  730. };
  731. for (auto& k : identifiers)
  732. {
  733. Identifier id;
  734. id.mDeclaration = "Built-in function";
  735. langDef.mIdentifiers.insert(std::make_pair(std::string(k), id));
  736. }
  737. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(($|@)?\"(\\.|[^\"])*\")##", PaletteIndex::String));
  738. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?[fF]?)##", PaletteIndex::Number));
  739. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?[0-9]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
  740. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[0-7]+[Uu]?[lL]?[lL]?)##", PaletteIndex::Number));
  741. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(0[xX][0-9a-fA-F]+[uU]?[lL]?[lL]?)##", PaletteIndex::Number));
  742. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([a-zA-Z_][a-zA-Z0-9_]*)##", PaletteIndex::Identifier));
  743. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.])##", PaletteIndex::Punctuation));
  744. langDef.mCommentStart = "/*";
  745. langDef.mCommentEnd = "*/";
  746. langDef.mSingleLineComment = "//";
  747. langDef.mCaseSensitive = true;
  748. langDef.mName = "C#";
  749. inited = true;
  750. }
  751. return langDef;
  752. }
  753. const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Json()
  754. {
  755. static bool inited = false;
  756. static LanguageDefinition langDef;
  757. if (!inited)
  758. {
  759. langDef.mKeywords.clear();
  760. langDef.mIdentifiers.clear();
  761. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(\"(\\.|[^\"])*\")##", PaletteIndex::String));
  762. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][+-]?[0-9]+)?)##", PaletteIndex::Number));
  763. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##([\[\]\{\}\!\%\^\&\*\(\)\-\+\=\~\|\<\>\?\/\;\,\.\:])##", PaletteIndex::Punctuation));
  764. langDef.mTokenRegexStrings.push_back(std::make_pair<std::string, PaletteIndex>(R"##(false|true)##", PaletteIndex::Keyword));
  765. langDef.mCommentStart = "/*";
  766. langDef.mCommentEnd = "*/";
  767. langDef.mSingleLineComment = "//";
  768. langDef.mCaseSensitive = true;
  769. langDef.mName = "Json";
  770. inited = true;
  771. }
  772. return langDef;
  773. }