From 5e605a96929bf36a70074851597bfe7b3798da45 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Sat, 17 May 2025 20:34:10 +0200 Subject: [PATCH] feat(editor): customized lexer to add custom keywords --- editor/script/scriptdocument.cpp | 74 +++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/editor/script/scriptdocument.cpp b/editor/script/scriptdocument.cpp index a0fffe0..71285b8 100644 --- a/editor/script/scriptdocument.cpp +++ b/editor/script/scriptdocument.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -17,6 +18,8 @@ #include "objects/script.h" #include "datatypes/meta.h" +QsciAPIs* makeApis(QsciLexer*); + std::map DARK_MODE_COLOR_SCHEME = {{ {QsciLexerLua::Comment, QColor("#808080")}, {QsciLexerLua::LineComment, QColor("#808080")}, @@ -36,6 +39,61 @@ std::map DARK_MODE_COLOR_SCHEME = {{ }}; +class ObLuaLexer : public QsciLexerLua { + const char * keywords(int set) const override { + // Taken from qscilexerlua.cpp + + if (set == 1) + // Keywords. + return + "and break do else elseif end false for function if " + "in local nil not or repeat return then true until " + "while"; + + if (set == 2) + // Basic functions. + return + //"foreach foreachi getn " + + // Openblocks extensions + "shared require game workspace " + + "_G _VERSION getfenv getmetatable ipairs loadstring " + "next pairs pcall rawequal rawget rawset select " + "setfenv setmetatable xpcall string table tonumber " + "tostring type math newproxy coroutine io os"; + + if (set == 3) + // String, table and maths functions. + return + // "abs acos asin atan atan2 ceil cos deg exp floor " + // "format frexp gsub ldexp log log10 max min mod rad " + // "random randomseed sin sqrt tan " + + "string.byte string.char string.dump string.find " + "string.len string.lower string.rep string.sub " + "string.upper string.format string.gfind string.gsub " + "table.concat table.foreach table.foreachi table.getn " + "table.sort table.insert table.remove table.setn " + "math.abs math.acos math.asin math.atan math.atan2 " + "math.ceil math.cos math.deg math.exp math.floor " + "math.frexp math.ldexp math.log math.log10 math.max " + "math.min math.mod math.pi math.rad math.random " + "math.randomseed math.sin math.sqrt math.tan"; + + if (set == 4) + // Coroutine, I/O and system facilities. + return + // "clock date difftime time " + + "coroutine.create coroutine.resume coroutine.status " + "coroutine.wrap coroutine.yield os.clock os.date " + "os.difftime os.time"; + + return 0; + }; +}; + ScriptDocument::ScriptDocument(std::shared_ptr