Add GDScript language

Adds GDScript language support, autocomplete file, functionlist, default and dark themes.

Fix #13329, close #13335
This commit is contained in:
zeltop 2023-03-03 23:12:14 +01:00 committed by Don Ho
parent 01bbebf825
commit 816fa3e414
19 changed files with 1366 additions and 3 deletions

View File

@ -0,0 +1,108 @@
# Everything after "#" is a comment.
# A file is a class!
# (optional) class definition:
class_name MyClass
# Inheritance:
extends BaseClass
# Member variables.
var a = 5
var s = "Hello"
var arr = [1, 2, 3]
var dict = {"key": "value", 2: 3}
var other_dict = {key = "value", other_key = 2}
var typed_var: int
var inferred_type := "String"
var ss = '''
func invalid_single_quote():
pass
'''
var sd = """
func invalid_func_double_quote():
pass
"""
# Constants.
const ANSWER = 42
const THE_NAME = "Charly"
# Enums.
enum {UNIT_NEUTRAL, UNIT_ENEMY, UNIT_ALLY}
enum Named {THING_1, THING_2, ANOTHER_THING = -1}
# Built-in vector types.
var v2 = Vector2(1, 2)
var v3 = Vector3(1, 2, 3)
# Functions.
func my_func(arg1 : int = sin(1), arg2 : String = "") -> void:
return
func some_function(param1, param2, param3):
if param1 < local_const:
print(param1)
elif param2 > 5:
print(param2)
else:
print("Fail!")
for i in range(20):
print(i)
while param2 != 0:
param2 -= 1
match param3:
3:
print("param3 is 3!")
_:
print("param3 is not 3!")
var local_var = param1 + 3
return local_var
# Functions override functions with the same name on the base/super class.
# If you still want to call them, use "super":
func something(p1, p2):
super(p1, p2)
# It's also possible to call another function in the super class:
func other_something(p1, p2):
super.something(p1, p2)
# Inner class
class Something:
var a = 10
func inner_function():
return
func my_func(arg1 : int = sin(1), arg2 : String = "") -> void:
return
# Inner class with inheritance
class fish extends Node2D:
func _init():
_randomize()
func _randomize():
randomize()
_size = rand_range(0.75,2.0)
# Constructor
func _init():
print("Constructed!")
var lv = Something.new()
print(lv.a)

View File

@ -0,0 +1 @@
{"leaves":["my_func(arg1 : int = sin(1), arg2 : String = \"\") -> void","some_function(param1, param2, param3)","something(p1, p2)","other_something(p1, p2)","_init()"],"nodes":[{"leaves":["inner_function()","my_func(arg1 : int = sin(1), arg2 : String = \"\") -> void"],"name":"Something"},{"leaves":["_init()","_randomize()"],"name":"fish"}],"root":"unitTest"}

File diff suppressed because it is too large Load Diff

View File

@ -96,6 +96,7 @@
<association id= "txt2tags.xml" langID= "83"/>
<association id= "visualprolog.xml" langID= "84"/>
<association id= "typescript.xml" langID= "85"/>
<association id= "gdscript.xml" langID= "88"/>
If you create your own parse rule of supported languages (above) for your specific need,
you can copy it without modifying the original one, and make it point to your rule.

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- ==========================================================================\
|
| To learn how to make your own language parser, please check the following
| link:
| https://npp-user-manual.org/docs/function-list/
|
\=========================================================================== -->
<NotepadPlus>
<functionList>
<parser
displayName="GDScript"
id ="gdscript_syntax"
commentExpr="(?s:'''.*?''')|(?s:\x22\x22\x22.*?\x22\x22\x22)|(?m-s:#.*?$)"
>
<classRange
mainExpr ="^class\x20\K.*?(?=\n\S|\Z)"
>
<className>
<nameExpr expr="\w+(?=[\s:])" />
</className>
<function
mainExpr="\s+?func\x20\K.+?(?=:\s*?$|:\s*?#)"
>
<functionName>
<funcNameExpr expr=".*" />
</functionName>
</function>
</classRange>
<function
mainExpr="^func\x20\K.+?(?=:\s*?$|:\s*?#)"
>
<functionName>
<nameExpr expr=".*" />
</functionName>
</function>
</parser>
</functionList>
</NotepadPlus>

View File

@ -96,6 +96,7 @@
<association id= "txt2tags.xml" langID= "83"/>
<association id= "visualprolog.xml" langID= "84"/>
<association id= "typescript.xml" langID= "85"/>
<association id= "gdscript.xml" langID= "88"/>
If you create your own parse rule of supported languages (above) for your specific need,
you can copy it without modifying the original one, and make it point to your rule.

View File

@ -158,6 +158,11 @@ SectionGroup "Auto-completion Files" autoCompletionComponent
File ".\APIs\powershell.xml"
${MementoSectionEnd}
${MementoSection} "GDScript" GDScript
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\gdscript.xml"
${MementoSectionEnd}
SectionGroupEnd
@ -276,5 +281,9 @@ SectionGroup un.autoCompletionComponent
Delete "$INSTDIR\autoCompletion\powershell.xml"
SectionEnd
Section un.GDScript
Delete "$INSTDIR\autoCompletion\gdscript.xml"
SectionEnd
SectionGroupEnd

View File

@ -187,6 +187,11 @@ SectionGroup "Function List Files" functionListComponent
SetOutPath "$INSTDIR\functionList"
File ".\functionList\pascal.xml"
${MementoSectionEnd}
${MementoSection} "GDScript" GDScript
SetOutPath "$INSTDIR\functionList"
File ".\functionList\gdscript.xml"
${MementoSectionEnd}
${MementoSection} "NppExecScript" NppExecScript
SetOutPath "$INSTDIR\functionList"
@ -343,6 +348,10 @@ SectionGroup un.functionListComponent
Delete "$INSTDIR\functionList\pascal.xml"
SectionEnd
Section un.GDScript
Delete "$INSTDIR\functionList\gdscript.xml"
SectionEnd
Section un.NppExecScript
Delete "$INSTDIR\functionList\nppexec.xml"
SectionEnd

View File

@ -33,6 +33,25 @@ License: GPL2
<WordsStyle name="PREPROCESSOR COMMENT" styleID="23" fgColor="7F9F7F" bgColor="3F3F3F" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="PREPROCESSOR COMMENT DOC" styleID="24" fgColor="7F9F7F" bgColor="3F3F3F" fontName="" fontStyle="0" fontSize="" />
</LexerType>
<LexerType name="gdscript" desc="GDScript" ext="">
<WordsStyle name="DEFAULT" styleID="0" fgColor="FFFFFF" bgColor="2A2A2A" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="COMMENT LINE" styleID="1" fgColor="808080" bgColor="2A2A2A" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="NUMBER" styleID="2" fgColor="0080C0" bgColor="2A2A2A" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="STRING" styleID="3" fgColor="80FF80" bgColor="2A2A2A" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="CHARACTER" styleID="4" fgColor="80FF80" bgColor="2A2A2A" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="WORD" styleID="5" fgColor="FF8080" bgColor="2A2A2A" fontName="" fontStyle="1" fontSize="" keywordClass="instre1" />
<WordsStyle name="TRIPLE" styleID="6" fgColor="FFFF80" bgColor="2A2A2A" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="TRIPLE DOUBLE" styleID="7" fgColor="FFFF80" bgColor="2A2A2A" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="CLASS NAME" styleID="8" fgColor="80FFFF" bgColor="2A2A2A" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="FUNC NAME" styleID="9" fgColor="FF80FF" bgColor="2A2A2A" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="OPERATOR" styleID="10" fgColor="CBB6B6" bgColor="2A2A2A" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="IDENTIFIER" styleID="11" fgColor="FFFFFF" bgColor="2A2A2A" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="COMMENT BLOCK" styleID="12" fgColor="008000" bgColor="2A2A2A" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="STRING EOL" styleID="13" fgColor="FF80C0" bgColor="2A2A2A" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="WORD2" styleID="14" fgColor="FF80C0" bgColor="2A2A2A" fontName="" fontStyle="0" fontSize="" keywordClass="instre2" />
<WordsStyle name="ANNOTATION" styleID="15" fgColor="FFFF80" bgColor="2A2A2A" fontName="" fontStyle="2" fontSize="" />
<WordsStyle name="NODEPATH" styleID="16" fgColor="008040" bgColor="2A2A2A" fontName="" fontStyle="1" fontSize="" />
</LexerType>
<LexerType name="ada" desc="ADA" ext="">
<WordsStyle name="DEFAULT" styleID="0" fgColor="DCDCCC" bgColor="3F3F3F" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="INSTRUCTION WORD" styleID="1" fgColor="DFC47D" bgColor="3F3F3F" fontName="" fontStyle="1" fontSize="" keywordClass="instre1" />

View File

@ -33,7 +33,7 @@ enum LangType {L_TEXT, L_PHP , L_C, L_CPP, L_CS, L_OBJC, L_JAVA, L_RC,\
L_CSOUND, L_ERLANG, L_ESCRIPT, L_FORTH, L_LATEX, \
L_MMIXAL, L_NIM, L_NNCRONTAB, L_OSCRIPT, L_REBOL, \
L_REGISTRY, L_RUST, L_SPICE, L_TXT2TAGS, L_VISUALPROLOG,\
L_TYPESCRIPT, L_JSON5, L_MSSQL,\
L_TYPESCRIPT, L_JSON5, L_MSSQL, L_GDSCRIPT,\
// Don't use L_JS, use L_JAVASCRIPT instead
// The end of enumated language type, so it should be always at the end
L_EXTERNAL};

View File

@ -3725,6 +3725,8 @@ LangType Notepad_plus::menuID2LangType(int cmdID)
return L_VISUALPROLOG;
case IDM_LANG_TYPESCRIPT:
return L_TYPESCRIPT;
case IDM_LANG_GDSCRIPT:
return L_GDSCRIPT;
case IDM_LANG_USER:
return L_USER;
default:

View File

@ -926,6 +926,7 @@ BEGIN
MENUITEM "Fortran (free form)", IDM_LANG_FORTRAN
MENUITEM "Fortran (fixed form)", IDM_LANG_FORTRAN_77
MENUITEM "Freebasic", IDM_LANG_FREEBASIC
MENUITEM "GDScript", IDM_LANG_GDSCRIPT
MENUITEM "Gui4Cli", IDM_LANG_GUI4CLI
MENUITEM "Haskell", IDM_LANG_HASKELL
MENUITEM "HTML", IDM_LANG_HTML
@ -1039,7 +1040,11 @@ BEGIN
MENUITEM "Fortran (fixed form)", IDM_LANG_FORTRAN_77
MENUITEM "Freebasic", IDM_LANG_FREEBASIC
END
MENUITEM "Gui4Cli", IDM_LANG_GUI4CLI
POPUP "G"
BEGIN
MENUITEM "GDScript", IDM_LANG_GDSCRIPT
MENUITEM "Gui4Cli", IDM_LANG_GUI4CLI
END
POPUP "H"
BEGIN
MENUITEM "Haskell", IDM_LANG_HASKELL

View File

@ -3548,6 +3548,7 @@ void Notepad_plus::command(int id)
case IDM_LANG_TXT2TAGS :
case IDM_LANG_VISUALPROLOG:
case IDM_LANG_TYPESCRIPT:
case IDM_LANG_GDSCRIPT:
case IDM_LANG_USER :
{
setLanguage(menuID2LangType(id));

View File

@ -7765,6 +7765,9 @@ int NppParameters::langTypeToCommandID(LangType lt) const
case L_TYPESCRIPT:
id = IDM_LANG_TYPESCRIPT; break;
case L_GDSCRIPT:
id = IDM_LANG_GDSCRIPT; break;
case L_SEARCHRESULT :
id = -1; break;

View File

@ -154,6 +154,7 @@ LanguageNameInfo ScintillaEditView::_langNameInfoArray[L_EXTERNAL + 1] = {
{TEXT("typescript"), TEXT("TypeScript"), TEXT("TypeScript file"), L_TYPESCRIPT, "cpp"},
{TEXT("json5"), TEXT("json5"), TEXT("JSON5 file"), L_JSON5, "json"},
{TEXT("mssql"), TEXT("mssql"), TEXT("Microsoft Transact-SQL (SQL Server) file"), L_MSSQL, "mssql"},
{TEXT("gdscript"), TEXT("GDScript"), TEXT("GDScript file"), L_GDSCRIPT, "gdscript"},
{TEXT("ext"), TEXT("External"), TEXT("External"), L_EXTERNAL, "null"}
};
@ -1810,6 +1811,9 @@ void ScintillaEditView::defineDocType(LangType typeDoc)
case L_TYPESCRIPT:
setTypeScriptLexer(); break;
case L_GDSCRIPT:
setGDScriptLexer(); break;
case L_TEXT :
default :
if (typeDoc >= L_EXTERNAL && typeDoc < NppParameters::getInstance().L_END)

View File

@ -649,7 +649,8 @@ public:
bool isPythonStyleIndentation(LangType typeDoc) const{
return (typeDoc == L_PYTHON || typeDoc == L_COFFEESCRIPT || typeDoc == L_HASKELL ||\
typeDoc == L_C || typeDoc == L_CPP || typeDoc == L_OBJC || typeDoc == L_CS || typeDoc == L_JAVA ||\
typeDoc == L_PHP || typeDoc == L_JS || typeDoc == L_JAVASCRIPT || typeDoc == L_MAKEFILE || typeDoc == L_ASN1);
typeDoc == L_PHP || typeDoc == L_JS || typeDoc == L_JAVASCRIPT || typeDoc == L_MAKEFILE ||\
typeDoc == L_ASN1 || typeDoc == L_GDSCRIPT);
};
void defineDocType(LangType typeDoc); //setup stylers for active document
@ -795,6 +796,12 @@ protected:
setLexer(L_PYTHON, LIST_0 | LIST_1);
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.quotes.python"), reinterpret_cast<LPARAM>("1"));
};
void setGDScriptLexer() {
setLexer(L_GDSCRIPT, LIST_0 | LIST_1);
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("lexer.gdscript.keywords2.no.sub.identifiers"), reinterpret_cast<LPARAM>("1"));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("lexer.gdscript.whinge.level"), reinterpret_cast<LPARAM>("1"));
};
void setBatchLexer() {
setLexer(L_BATCH, LIST_0);

File diff suppressed because one or more lines are too long

View File

@ -539,6 +539,7 @@
#define IDM_LANG_TYPESCRIPT (IDM_LANG + 84)
#define IDM_LANG_JSON5 (IDM_LANG + 85)
#define IDM_LANG_MSSQL (IDM_LANG + 86)
#define IDM_LANG_GDSCRIPT (IDM_LANG + 87)
#define IDM_LANG_EXTERNAL (IDM_LANG + 165)
#define IDM_LANG_EXTERNAL_LIMIT (IDM_LANG + 179)

View File

@ -1321,6 +1321,25 @@
<WordsStyle name="COMMENT DOC KEYWORD" styleID="17" fgColor="008080" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="COMMENT DOC KEYWORD ERROR" styleID="18" fgColor="008080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
</LexerType>
<LexerType name="gdscript" desc="GDScript" ext="">
<WordsStyle name="DEFAULT" styleID="0" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="COMMENT LINE" styleID="1" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="NUMBER" styleID="2" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="STRING" styleID="3" fgColor="008040" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="CHARACTER" styleID="4" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="WORD" styleID="5" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" keywordClass="instre1" />
<WordsStyle name="TRIPLE" styleID="6" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="TRIPLE DOUBLE" styleID="7" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="CLASS NAME" styleID="8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="FUNC NAME" styleID="9" fgColor="0080FF" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="OPERATOR" styleID="10" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="IDENTIFIER" styleID="11" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="COMMENT BLOCK" styleID="12" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="STRING EOL" styleID="13" fgColor="880088" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="WORD2" styleID="14" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" keywordClass="instre2" />
<WordsStyle name="ANNOTATION" styleID="15" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="NODEPATH" styleID="16" fgColor="004000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" />
</LexerType>
<LexerType name="vb" desc="VB / VBS" ext="">
<WordsStyle name="DEFAULT" styleID="7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="COMMENT" styleID="1" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />