Branch: refs/heads/master Author: David Yu Yang davidyang6us@gmail.com Committer: David Yang davidyang6us@gmail.com Date: Fri, 14 Jan 2022 04:01:41 UTC Commit: f59e52008e93bf3b1585a918bb248bf5d406e383 https://github.com/geany/geany/commit/f59e52008e93bf3b1585a918bb248bf5d406e3...
Log Message: ----------- Add GDScript file type
Heavily borrowed from python due to GDScript's syntax being heavily borrowed from python
Modified Paths: -------------- ctags/Makefile.am ctags/main/entry.c ctags/main/entry.h ctags/parsers/gdscript.c data/Makefile.am data/filedefs/filetypes.gdscript data/filetype_extensions.conf scintilla/Makefile.am scintilla/lexilla/include/LexicalStyles.iface scintilla/lexilla/lexers/LexGDScript.cxx scintilla/lexilla/src/Lexilla.cxx scintilla/scintilla_changes.patch src/filetypes.c src/filetypes.h src/highlighting.c src/highlightingmappings.h src/symbols.c src/tagmanager/tm_parser.c src/tagmanager/tm_parser.h src/tagmanager/tm_parsers.h
Modified: ctags/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -59,6 +59,7 @@ parsers = \ parsers/erlang.c \ parsers/flex.c \ parsers/geany_fortran.c \ + parsers/gdscript.c \ parsers/go.c \ parsers/haskell.c \ parsers/haxe.c \
Modified: ctags/main/entry.c 5 lines changed, 5 insertions(+), 0 deletions(-) =================================================================== @@ -1916,6 +1916,11 @@ extern void markTagExtraBit (tagEntryInfo *const tag, xtagType extra) markTagExtraBitFull (tag, extra, true); }
+extern void unmarkTagExtraBit (tagEntryInfo *const tag, xtagType extra) +{ + markTagExtraBitFull (tag, extra, false); +} + extern bool isTagExtraBitMarked (const tagEntryInfo *const tag, xtagType extra) { unsigned int index;
Modified: ctags/main/entry.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -198,6 +198,7 @@ int anyKindsEntryInScopeRecursive (int corkIndex, const int * kinds, int count);
extern void markTagExtraBit (tagEntryInfo *const tag, xtagType extra); +extern void unmarkTagExtraBit (tagEntryInfo *const tag, xtagType extra); extern bool isTagExtraBitMarked (const tagEntryInfo *const tag, xtagType extra);
/* If any extra bit is on, return true. */
Modified: ctags/parsers/gdscript.c 1410 lines changed, 1410 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,1410 @@ +/* +* Copyright (c) 2000-2003, Darren Hiebert +* Copyright (c) 2014-2016, Colomban Wendling ban@herbesfolles.org +* Copyright (c) 2021, David Yang davidyang6us@gmail.com +* +* This source code is released for free distribution under the terms of the +* GNU General Public License version 2 or (at your option) any later version. +* +* This module contains functions for generating tags for GDScript language +* files. This module is derived from the Python module. +* +* GDScript language reference: +* https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript... +* https://docs.godotengine.org/en/stable/development/file_formats/gdscript_gra... +* https://godotengine.org/article/gdscript-progress-report-new-gdscript-now-me... +* +*/ + +#include "general.h" /* must always come first */ + +#include <string.h> + +#include "entry.h" +#include "nestlevel.h" +#include "read.h" +#include "parse.h" +#include "vstring.h" +#include "keyword.h" +#include "routines.h" +#include "debug.h" +#include "xtag.h" +#include "objpool.h" +#include "strlist.h" + +#define isIdentifierChar(c) \ + (isalnum (c) || (c) == '_' || (c) >= 0x80) +#define newToken() (objPoolGet (TokenPool)) +#define deleteToken(t) (objPoolPut (TokenPool, (t))) + +enum { + KEYWORD_class, + KEYWORD_func, + KEYWORD_extends, + KEYWORD_pass, + KEYWORD_return, + KEYWORD_lambda, + KEYWORD_variable, + KEYWORD_const, + KEYWORD_enum, + KEYWORD_class_name, + KEYWORD_signal, + KEYWORD_modifier, +}; +typedef int keywordId; /* to allow KEYWORD_NONE */ + +typedef enum { + ACCESS_PRIVATE, + ACCESS_PROTECTED, + ACCESS_PUBLIC, + COUNT_ACCESS +} accessType; + +static const char *const GDScriptAccesses[COUNT_ACCESS] = { + "private", + "protected", + "public" +}; + +typedef enum { + F_ANNOTATIONS, + COUNT_FIELD +} gdscriptField; + +static fieldDefinition GDScriptFields[COUNT_FIELD] = { + { .name = "annotations", + .description = "annotations on functions and variables", + .enabled = true }, +}; + +typedef enum { + K_CLASS, + K_METHOD, + K_VARIABLE, + K_CONST, + K_ENUM, + K_ENUMERATOR, + K_PARAMETER, + K_LOCAL_VARIABLE, + K_SIGNAL, + COUNT_KIND +} gdscriptKind; + +typedef enum { + GDSCRIPT_CLASS_EXTENDED, +} gdscriptClassRole; + +static roleDefinition GDScriptClassRoles [] = { + { true, "extended", "used as a base class for extending" }, +}; + +static kindDefinition GDScriptKinds[COUNT_KIND] = { + {true, 'c', "class", "classes", + .referenceOnly = false, ATTACH_ROLES(GDScriptClassRoles)}, + {true, 'm', "method", "methods"}, + {true, 'v', "variable", "variables"}, + {true, 'C', "const", "constants"}, + {true, 'g', "enum", "enumeration names"}, + {true, 'e', "enumerator", "enumerated values"}, + {false,'z', "parameter", "function parameters"}, + {false,'l', "local", "local variables"}, + {true, 's', "signal", "signals"}, +}; + +typedef enum { + X_IMPLICIT_CLASS, +} gdscriptXtag; + +static xtagDefinition GDScriptXtagTable [] = { + { + .enabled = false, + .name = "implicitClass", + .description = "Include tag for the implicitly defined unnamed class", + }, +}; + +static const keywordTable GDScriptKeywordTable[] = { + /* keyword keyword ID */ + { "class", KEYWORD_class }, + { "func", KEYWORD_func }, + { "extends", KEYWORD_extends }, + { "lambda", KEYWORD_lambda }, // Future GDScript lambda currently uses func, may change + { "pass", KEYWORD_pass }, + { "return", KEYWORD_return }, + { "var", KEYWORD_variable }, + { "const", KEYWORD_const }, + { "enum", KEYWORD_enum }, + { "class_name", KEYWORD_class_name }, + { "signal", KEYWORD_signal }, + +}; + +const static struct keywordGroup modifierKeywords = { + .value = KEYWORD_modifier, + .addingUnlessExisting = false, + .keywords = { + "static", + "remote", "remotesync", + "master", "mastersycn", + "puppet", "puppetsync", + NULL, + }, +}; + +typedef enum eTokenType { + /* 0..255 are the byte's value */ + TOKEN_EOF = 256, + TOKEN_UNDEFINED, + TOKEN_INDENT, + TOKEN_KEYWORD, + TOKEN_OPERATOR, + TOKEN_IDENTIFIER, + TOKEN_STRING, + TOKEN_ARROW, /* -> */ + TOKEN_WHITESPACE, +} tokenType; + +typedef struct { + int type; + keywordId keyword; + vString * string; + int indent; + unsigned long lineNumber; + MIOPos filePosition; +} tokenInfo; + +struct gdscriptNestingLevelUserData { + int indentation; +}; +#define GDS_NL(nl) ((struct gdscriptNestingLevelUserData *) nestingLevelGetUserData (nl)) + +static langType Lang_gdscript; +static unsigned int TokenContinuationDepth = 0; +static tokenInfo *NextToken = NULL; +static NestingLevels *GDScriptNestingLevels = NULL; +static objPool *TokenPool = NULL; + + +// Always reports single-underscores as protected +static accessType accessFromIdentifier (const vString *const ident, int parentKind) +{ + const char *const p = vStringValue (ident); + const size_t len = vStringLength (ident); + + /* inside a function/method, private */ + if (parentKind != -1 && parentKind != K_CLASS) + return ACCESS_PRIVATE; + /* not starting with "_", public */ + else if (len < 1 || p[0] != '_') + return ACCESS_PUBLIC; + /* "_...": suggested as non-public, but easily accessible */ + else + return ACCESS_PROTECTED; +} + +static void initGDScriptEntry (tagEntryInfo *const e, const tokenInfo *const token, + const gdscriptKind kind) +{ + accessType access; + int parentKind = -1; + NestingLevel *nl; + + initTagEntry (e, vStringValue (token->string), kind); + + e->lineNumber = token->lineNumber; + e->filePosition = token->filePosition; + + nl = nestingLevelsGetCurrent (GDScriptNestingLevels); + if (nl) + { + tagEntryInfo *nlEntry = getEntryOfNestingLevel (nl); + + e->extensionFields.scopeIndex = nl->corkIndex; + + /* nlEntry can be NULL if a kind was disabled. But what can we do + * here? Even disabled kinds should count for the hierarchy I + * guess -- as it'd otherwise be wrong -- but with cork we're + * fucked up as there's nothing to look up. Damn. */ + if (nlEntry) + parentKind = nlEntry->kindIndex; + } + + access = accessFromIdentifier (token->string, parentKind); + e->extensionFields.access = GDScriptAccesses[access]; + /* FIXME: should we really set isFileScope in addition to access? */ + if (access == ACCESS_PRIVATE) + e->isFileScope = true; +} + +static int makeClassTag (const tokenInfo *const token, + const vString *const inheritance) +{ + if (GDScriptKinds[K_CLASS].enabled) + { + tagEntryInfo e; + + initGDScriptEntry (&e, token, K_CLASS); + + e.extensionFields.inheritance = inheritance ? vStringValue (inheritance) : ""; + + return makeTagEntry (&e); + } + + return CORK_NIL; +} + +static vString *makeDecoratorString (const stringList *const strlist) +{ + vString *vstr = vStringNew (); + + for (unsigned int i = 0; i < stringListCount (strlist); i++) + { + vString *elt = stringListItem (strlist, i); + if (i != 0 && (vStringValue (elt) > 0 + && vStringValue (elt)[0] != '(')) + vStringPut (vstr, ','); + vStringCat (vstr, elt); + } + return vstr; +} + +static int makeFunctionTag (const tokenInfo *const token, + int kind, + const vString *const arglist, + const stringList *const decorators) +{ + if (GDScriptKinds[kind].enabled) + { + tagEntryInfo e; + vString *vstr = NULL; + int r; + + initGDScriptEntry (&e, token, kind); + + if (arglist) + e.extensionFields.signature = vStringValue (arglist); + if (decorators && stringListCount (decorators) > 0) + { + vstr = makeDecoratorString (decorators); + attachParserField (&e, false, GDScriptFields[F_ANNOTATIONS].ftype, + vStringValue (vstr)); + } + + r = makeTagEntry (&e); + vStringDelete (vstr); /* NULL is ignored. */ + + return r; + } + + return CORK_NIL; +} + +static int makeSimpleGDScriptTag (const tokenInfo *const token, gdscriptKind const kind) +{ + if (GDScriptKinds[kind].enabled) + { + tagEntryInfo e; + + initGDScriptEntry (&e, token, kind); + return makeTagEntry (&e); + } + + return CORK_NIL; +} + +static int makeSimpleGDScriptRefTag (const tokenInfo *const token, + gdscriptKind const kind, + int roleIndex, xtagType xtag) +{ + if (isXtagEnabled (XTAG_REFERENCE_TAGS)) + { + tagEntryInfo e; + + initRefTagEntry (&e, vStringValue (token->string), + kind, roleIndex); + + e.lineNumber = token->lineNumber; + e.filePosition = token->filePosition; + + if (xtag != XTAG_UNKNOWN) + markTagExtraBit (&e, xtag); + + return makeTagEntry (&e); + } + + return CORK_NIL; +} + +static void *newPoolToken (void *createArg CTAGS_ATTR_UNUSED) +{ + tokenInfo *token = xMalloc (1, tokenInfo); + token->string = vStringNew (); + return token; +} + +static void deletePoolToken (void *data) +{ + tokenInfo *token = data; + vStringDelete (token->string); + eFree (token); +} + +static void clearPoolToken (void *data) +{ + tokenInfo *token = data; + + token->type = TOKEN_UNDEFINED; + token->keyword = KEYWORD_NONE; + token->indent = 0; + token->lineNumber = getInputLineNumber (); + token->filePosition = getInputFilePosition (); + vStringClear (token->string); +} + +static void copyToken (tokenInfo *const dest, const tokenInfo *const src) +{ + dest->lineNumber = src->lineNumber; + dest->filePosition = src->filePosition; + dest->type = src->type; + dest->keyword = src->keyword; + dest->indent = src->indent; + vStringCopy(dest->string, src->string); +} + +/* Skip a single or double quoted string. */ +static void readString (vString *const string, const int delimiter) +{ + int escaped = 0; + int c; + + while ((c = getcFromInputFile ()) != EOF) + { + if (escaped) + { + vStringPut (string, c); + escaped--; + } + else if (c == '\') + escaped++; + else if (c == delimiter || c == '\n' || c == '\r') + { + if (c != delimiter) + ungetcToInputFile (c); + break; + } + else + vStringPut (string, c); + } +} + +/* Skip a single or double triple quoted string. */ +static void readTripleString (vString *const string, const int delimiter) +{ + int c; + int escaped = 0; + int n = 0; + while ((c = getcFromInputFile ()) != EOF) + { + if (c == delimiter && ! escaped) + { + if (++n >= 3) + break; + } + else + { + for (; n > 0; n--) + vStringPut (string, delimiter); + if (c != '\' || escaped) + vStringPut (string, c); + n = 0; + } + + if (escaped) + escaped--; + else if (c == '\') + escaped++; + } +} + +static void readIdentifier (vString *const string, const int firstChar) +{ + int c = firstChar; + do + { + vStringPut (string, c); + c = getcFromInputFile (); + } + while (isIdentifierChar (c)); + ungetcToInputFile (c); +} + +static void ungetToken (tokenInfo *const token) +{ + Assert (NextToken == NULL); + NextToken = newToken (); + copyToken (NextToken, token); +} + +static void readTokenFull (tokenInfo *const token, bool inclWhitespaces) +{ + int c; + int n; + + /* if we've got a token held back, emit it */ + if (NextToken) + { + copyToken (token, NextToken); + deleteToken (NextToken); + NextToken = NULL; + return; + } + + token->type = TOKEN_UNDEFINED; + token->keyword = KEYWORD_NONE; + vStringClear (token->string); + +getNextChar: + + n = 0; + do + { + c = getcFromInputFile (); + n++; + } + while (c == ' ' || c == '\t' || c == '\f'); + + token->lineNumber = getInputLineNumber (); + token->filePosition = getInputFilePosition (); + + if (inclWhitespaces && n > 1 && c != '\r' && c != '\n') + { + ungetcToInputFile (c); + vStringPut (token->string, ' '); + token->type = TOKEN_WHITESPACE; + return; + } + + switch (c) + { + case EOF: + token->type = TOKEN_EOF; + break; + + case ''': + case '"': + { + int d = getcFromInputFile (); + token->type = TOKEN_STRING; + vStringPut (token->string, c); + if (d != c) + { + ungetcToInputFile (d); + readString (token->string, c); + } + else if ((d = getcFromInputFile ()) == c) + readTripleString (token->string, c); + else /* empty string */ + ungetcToInputFile (d); + vStringPut (token->string, c); + token->lineNumber = getInputLineNumber (); + token->filePosition = getInputFilePosition (); + break; + } + + case '=': + { + int d = getcFromInputFile (); + vStringPut (token->string, c); + if (d == c) + { + vStringPut (token->string, d); + token->type = TOKEN_OPERATOR; + } + else + { + ungetcToInputFile (d); + token->type = c; + } + break; + } + + case '-': + { + int d = getcFromInputFile (); + if (d == '>') + { + vStringPut (token->string, c); + vStringPut (token->string, d); + token->type = TOKEN_ARROW; + break; + } + ungetcToInputFile (d); + /* fall through */ + } + case '+': + case '*': + case '%': + case '<': + case '>': + case '/': + { + int d = getcFromInputFile (); + vStringPut (token->string, c); + if (d != '=') + { + ungetcToInputFile (d); + token->type = c; + } + else + { + vStringPut (token->string, d); + token->type = TOKEN_OPERATOR; + } + break; + } + + /* eats newline to implement line continuation */ + case '\': + { + int d = getcFromInputFile (); + if (d == '\r') + d = getcFromInputFile (); + if (d != '\n') + ungetcToInputFile (d); + goto getNextChar; + } + + case '#': /* comment */ + case '\r': /* newlines for indent */ + case '\n': + { + int indent = 0; + do + { + if (c == '#') + { + do + c = getcFromInputFile (); + while (c != EOF && c != '\r' && c != '\n'); + } + if (c == '\r') + { + int d = getcFromInputFile (); + if (d != '\n') + ungetcToInputFile (d); + } + indent = 0; + while ((c = getcFromInputFile ()) == ' ' || c == '\t' || c == '\f') + { + if (c == '\t') + indent += 8 - (indent % 8); + else if (c == '\f') /* yeah, it's weird */ + indent = 0; + else + indent++; + } + } /* skip completely empty lines, so retry */ + while (c == '\r' || c == '\n' || c == '#'); + ungetcToInputFile (c); + if (TokenContinuationDepth > 0) + { + if (inclWhitespaces) + { + vStringPut (token->string, ' '); + token->type = TOKEN_WHITESPACE; + } + else + goto getNextChar; + } + else + { + token->type = TOKEN_INDENT; + token->indent = indent; + } + break; + } + + default: + if (! isIdentifierChar (c)) + { + vStringPut (token->string, c); + token->type = c; + } + else + { + /* FIXME: handle U, B, R and F string prefixes? */ + readIdentifier (token->string, c); + token->keyword = lookupKeyword (vStringValue (token->string), Lang_gdscript); + if (token->keyword == KEYWORD_NONE) + token->type = TOKEN_IDENTIFIER; + else + token->type = TOKEN_KEYWORD; + } + break; + } + + // handle implicit continuation lines not to emit INDENT inside brackets + if (token->type == '(' || + token->type == '{' || + token->type == '[') + { + TokenContinuationDepth ++; + } + else if (TokenContinuationDepth > 0 && + (token->type == ')' || + token->type == '}' || + token->type == ']')) + { + TokenContinuationDepth --; + } +} + +static void readToken (tokenInfo *const token) +{ + readTokenFull (token, false); +} + +/*================================= parsing =================================*/ + + +static void reprCat (vString *const repr, const tokenInfo *const token) +{ + if (token->type != TOKEN_INDENT && + token->type != TOKEN_WHITESPACE) + { + vStringCat (repr, token->string); + } + else if (vStringLength (repr) > 0 && vStringLast (repr) != ' ') + { + vStringPut (repr, ' '); + } +} + +static bool skipOverPair (tokenInfo *const token, int tOpen, int tClose, + vString *const repr, bool reprOuterPair) +{ + if (token->type == tOpen) + { + int depth = 1; + + if (repr && reprOuterPair) + reprCat (repr, token); + do + { + readTokenFull (token, true); + if (repr && (reprOuterPair || token->type != tClose || depth > 1)) + { + reprCat (repr, token); + } + if (token->type == tOpen) + depth ++; + else if (token->type == tClose) + depth --; + } + while (token->type != TOKEN_EOF && depth > 0); + } + + return token->type == tClose; +} + +static void readQualifiedName (tokenInfo *const nameToken) +{ + readToken (nameToken); + + if (nameToken->type == TOKEN_IDENTIFIER || + nameToken->type == '.') + { + vString *qualifiedName = vStringNew (); + tokenInfo *token = newToken (); + + while (nameToken->type == TOKEN_IDENTIFIER || + nameToken->type == '.') + { + vStringCat (qualifiedName, nameToken->string); + copyToken (token, nameToken); + + readToken (nameToken); + } + /* put the last, non-matching, token back */ + ungetToken (nameToken); + + copyToken (nameToken, token); + nameToken->type = TOKEN_IDENTIFIER; + vStringCopy (nameToken->string, qualifiedName); + + deleteToken (token); + vStringDelete (qualifiedName); + } +} + +static vString *parseParamTypeAnnotation (tokenInfo *const token, + vString *arglist) +{ + readToken (token); + if (token->type != ':') + { + ungetToken (token); + return NULL; + } + + reprCat (arglist, token); + int depth = 0; + vString *t = vStringNew (); + while (true) + { + readTokenFull (token, true); + if (token->type == TOKEN_WHITESPACE) + { + reprCat (arglist, token); + continue; + } + else if (token->type == TOKEN_EOF) + break; + + if (token->type == '(' || + token->type == '[' || + token->type == '{') + depth ++; + else if (token->type == ')' || + token->type == ']' || + token->type == '}') + depth --; + + if (depth < 0 + || (depth == 0 && (token->type == '=' + || token->type == ','))) + { + ungetToken (token); + return t; + } + reprCat (arglist, token); + reprCat (t, token); + } + vStringDelete (t); + return NULL; +} + +static vString *parseReturnTypeAnnotation (tokenInfo *const token) +{ + readToken (token); + if (token->type != TOKEN_ARROW) + { + return NULL; + } + + int depth = 0; + vString *t = vStringNew (); + while (true) + { + readToken (token); + if (token->type == TOKEN_EOF) + break; + + if (token->type == '(' || + token->type == '[' || + token->type == '{') + depth ++; + else if (token->type == ')' || + token->type == ']' || + token->type == '}') + depth --; + if (depth == 0 && token->type == ':') + { + ungetToken (token); + return t; + } + else + reprCat (t, token); + } + vStringDelete (t); + return NULL; +} + +static bool parseClassOrDef (tokenInfo *const token, + const stringList *const decorators, + gdscriptKind kind, bool isCDef) +{ + vString *arglist = NULL; + tokenInfo *name = NULL; + tokenInfo *parameterTokens[16] = { NULL }; + vString *parameterTypes [ARRAY_SIZE(parameterTokens)] = { NULL }; + unsigned int parameterCount = 0; + NestingLevel *lv; + int corkIndex; + + readToken (token); + if (token->type != TOKEN_IDENTIFIER) + return false; + + name = newToken (); + copyToken (name, token); + + readToken (token); + /* collect parameters or inheritance */ + if (token->type == '(') + { + int prevTokenType = token->type; + int depth = 1; + + arglist = vStringNew (); + if (kind != K_CLASS) + reprCat (arglist, token); + + do + { + if (token->type != TOKEN_WHITESPACE && + token->type != '*') + { + prevTokenType = token->type; + } + + readTokenFull (token, true); + if (kind != K_CLASS || token->type != ')' || depth > 1) + reprCat (arglist, token); + + if (token->type == '(' || + token->type == '[' || + token->type == '{') + depth ++; + else if (token->type == ')' || + token->type == ']' || + token->type == '}') + depth --; + else if (kind != K_CLASS && depth == 1 && + token->type == TOKEN_IDENTIFIER && + (prevTokenType == '(' || prevTokenType == ',') && + parameterCount < ARRAY_SIZE (parameterTokens) && + GDScriptKinds[K_PARAMETER].enabled) + { + tokenInfo *parameterName = newToken (); + + copyToken (parameterName, token); + parameterTokens[parameterCount] = parameterName; + parameterTypes [parameterCount++] = parseParamTypeAnnotation (token, arglist); + } + } + while (token->type != TOKEN_EOF && depth > 0); + } + else if (token->type == TOKEN_KEYWORD && token->keyword == KEYWORD_extends) + { + readToken (token); + if (token->type == TOKEN_IDENTIFIER) + { + makeSimpleGDScriptRefTag (token, K_CLASS, GDSCRIPT_CLASS_EXTENDED, XTAG_UNKNOWN); + arglist = vStringNewCopy (token->string); + } + } + else if (kind == K_SIGNAL) + { + /* signal can be defined with no parameter list. */ + ungetToken (token); + } + + if (kind == K_CLASS) + corkIndex = makeClassTag (name, arglist); + else + corkIndex = makeFunctionTag (name, kind, arglist, decorators); + + lv = nestingLevelsPush (GDScriptNestingLevels, corkIndex); + GDS_NL (lv)->indentation = token->indent; + + deleteToken (name); + vStringDelete (arglist); + + if (parameterCount > 0) + { + unsigned int i; + + for (i = 0; i < parameterCount; i++) + { + int paramCorkIndex = makeSimpleGDScriptTag (parameterTokens[i], K_PARAMETER); + deleteToken (parameterTokens[i]); + tagEntryInfo *e = getEntryInCorkQueue (paramCorkIndex); + if (e && parameterTypes[i]) + { + e->extensionFields.typeRef [0] = eStrdup ("typename"); + e->extensionFields.typeRef [1] = vStringDeleteUnwrap (parameterTypes[i]); + parameterTypes[i] = NULL; + } + vStringDelete (parameterTypes[i]); /* NULL is acceptable. */ + } + } + + tagEntryInfo *e; + vString *t; + if (kind != K_CLASS + && (e = getEntryInCorkQueue (corkIndex)) + && (t = parseReturnTypeAnnotation (token))) + { + e->extensionFields.typeRef [0] = eStrdup ("typename"); + e->extensionFields.typeRef [1] = vStringDeleteUnwrap (t); + } + + if (kind == K_SIGNAL) + nestingLevelsPop (GDScriptNestingLevels); + + return true; +} + +static bool parseEnum (tokenInfo *const token) +{ + int corkIndex; + + readToken (token); + + if (token->type == '{') + { + tokenInfo *name = newToken (); + copyToken (name, token); + vStringClear (name->string); + anonGenerate (name->string, "anon_enum_", K_ENUM); + name->type = TOKEN_IDENTIFIER; + corkIndex = makeSimpleGDScriptTag (name, K_ENUM); + deleteToken (name); + tagEntryInfo *e = getEntryInCorkQueue (corkIndex); + if (e) + markTagExtraBit (e, XTAG_ANONYMOUS); + } + else if (token->type == TOKEN_IDENTIFIER) + { + corkIndex = makeSimpleGDScriptTag(token, K_ENUM); + readToken (token); + } + else + return false; + + if (token->type != '{') + return false; + + readToken (token); + nestingLevelsPush (GDScriptNestingLevels, corkIndex); + + while (token->type != '}' && token->type != TOKEN_EOF) + { + if (token->type == TOKEN_IDENTIFIER) + makeSimpleGDScriptTag(token, K_ENUMERATOR); + else if (token->type == '=') + { + /* Skip the right value. */ + do + readToken (token); + while (token->type != ',' + && token->type != '}' + && token->type != TOKEN_EOF); + if (token->type != ',') + continue; + } + readToken (token); + } + + tagEntryInfo *e; + vString *t; + if ((e = getEntryInCorkQueue (corkIndex)) + && (t = parseReturnTypeAnnotation (token))) + { + e->extensionFields.typeRef [0] = eStrdup ("typename"); + e->extensionFields.typeRef [1] = vStringDeleteUnwrap (t); + } + + nestingLevelsPop (GDScriptNestingLevels); + return true; +} + +static bool parseClassName (tokenInfo *const token) +{ + readToken (token); + if (token->type == TOKEN_IDENTIFIER) + { + /* A class name is explicitly given with "class_name" keyword. + * Let's overwrite the anonymous tag for the class + */ + NestingLevel *nl = nestingLevelsGetNthFromRoot (GDScriptNestingLevels, 0); + tagEntryInfo *klass = nl? getEntryInCorkQueue (nl->corkIndex): NULL; + + tagEntryInfo e; + char *name = vStringStrdup (token->string); + initTagEntry (&e, klass? "UNUSED": name, K_CLASS); + + if (klass) + { + eFree ((void *)klass->name); + klass->name = name; + name = NULL; + unmarkTagExtraBit(klass, XTAG_ANONYMOUS); + + /* Adjust the position. */ + setTagPositionFromTag (klass, &e); + } + + /* Extract B in class_name C extends B */ + readToken (token); + if (token->type == TOKEN_KEYWORD + && token->keyword == KEYWORD_extends) + { + readToken (token); + if (token->type == TOKEN_IDENTIFIER) + { + makeSimpleGDScriptRefTag (token, K_CLASS, + GDSCRIPT_CLASS_EXTENDED, + XTAG_UNKNOWN); + if (klass) + { + if (klass->extensionFields.inheritance) + eFree ((void *)klass->extensionFields.inheritance); + klass->extensionFields.inheritance = vStringStrdup (token->string); + } + else + e.extensionFields.inheritance = vStringValue(token->string); + } + } + + if (!klass) + makeTagEntry (&e); + + if (name) + eFree (name); + } + + while (token->type != TOKEN_EOF && + token->type != ';' && + token->type != TOKEN_INDENT) + readToken (token); + + return false; +} + +static bool parseExtends (tokenInfo *const token) +{ + if (token->keyword == KEYWORD_extends) + { + readQualifiedName (token); + if (token->type == TOKEN_IDENTIFIER) + { + makeSimpleGDScriptRefTag (token, K_CLASS, GDSCRIPT_CLASS_EXTENDED, XTAG_UNKNOWN); + NestingLevel *nl = nestingLevelsGetCurrent (GDScriptNestingLevels); + if (nl) + { + tagEntryInfo *klass = getEntryInCorkQueue (nl->corkIndex); + if (klass) + { + if (klass->extensionFields.inheritance) + eFree ((void *)klass->extensionFields.inheritance); + klass->extensionFields.inheritance = vStringStrdup(token->string); + } + } + } + } + readToken (token); + return false; +} + +/* this only handles the most common cases, but an annotation can be any + * expression in theory. + * this function assumes there must be an annotation, and doesn't do any check + * on the token on which it is called: the caller should do that part. */ +static bool skipVariableTypeAnnotation (tokenInfo *const token, vString *const repr) +{ + bool readNext = true; + + readToken (token); + switch (token->type) + { + case '[': readNext = skipOverPair (token, '[', ']', repr, true); break; + case '(': readNext = skipOverPair (token, '(', ')', repr, true); break; + case '{': readNext = skipOverPair (token, '{', '}', repr, true); break; + default: reprCat (repr, token); + } + if (readNext) + readToken (token); + /* skip subscripts and calls */ + while (token->type == '[' || token->type == '(' || token->type == '.' || token->type == '|') + { + switch (token->type) + { + case '[': readNext = skipOverPair (token, '[', ']', repr, true); break; + case '(': readNext = skipOverPair (token, '(', ')', repr, true); break; + case '|': + reprCat (repr, token); + skipVariableTypeAnnotation (token, repr); + readNext = false; + break; + case '.': + reprCat (repr, token); + readToken (token); + readNext = token->type == TOKEN_IDENTIFIER; + if (readNext) + reprCat (repr, token); + break; + default: readNext = false; break; + } + if (readNext) + readToken (token); + } + + return false; +} + +static bool parseVariable (tokenInfo *const token, const gdscriptKind kind, + const stringList *const decorators, + const int keyword) +{ + readToken(token); + vString *type = vStringNew(); + tokenInfo *name = newToken (); + copyToken (name, token); + if (!name) + return false; + + readToken (token); + // Variable declarations with dotted names are illegal + if (token->type == '.') + return false; + + /* (parse and) skip annotations. we need not to be too permissive because we + * aren't yet sure we're actually parsing a variable. */ + if (token->type == ':' && skipVariableTypeAnnotation (token, type)) + readToken (token); + + int index = makeSimpleGDScriptTag (name, kind); + deleteToken(name); + tagEntryInfo *e = getEntryInCorkQueue (index); + + if (e && decorators && stringListCount (decorators) > 0) + { + vString *vstr = makeDecoratorString (decorators); + attachParserField (e, true, GDScriptFields[F_ANNOTATIONS].ftype, + vStringValue (vstr)); + vStringDelete (vstr); + } + + vString *vtype = vStringNew(); + char * stype = vStringValue (type); + if (strcmp(stype, "=") && strcmp(stype, "")) + { + vStringCatS(vtype, stype); + } + vStringDelete(type); + + if (e && vStringLength(vtype) > 0) /// TODO: Fix types away + { + e->extensionFields.typeRef [0] = eStrdup ("typename"); + e->extensionFields.typeRef [1] = vStringDeleteUnwrap (vtype); + } + else + { + vStringDelete(vtype); + } + + + while ((TokenContinuationDepth > 0 || token->type != ',') && + token->type != TOKEN_EOF && + token->type != ';' && + token->type != TOKEN_INDENT) + { + readToken (token); + } + + + return false; +} + +/* pops any level >= to indent */ +static void setIndent (tokenInfo *const token) +{ + NestingLevel *lv = nestingLevelsGetCurrent (GDScriptNestingLevels); + + while (lv && GDS_NL (lv)->indentation >= token->indent) + { + tagEntryInfo *e = getEntryInCorkQueue (lv->corkIndex); + if (e) + e->extensionFields.endLine = token->lineNumber; + + nestingLevelsPop (GDScriptNestingLevels); + lv = nestingLevelsGetCurrent (GDScriptNestingLevels); + } +} + +static int prepareUnnamedClass (struct NestingLevels *nls) +{ + { + /* Ugly: we need a "position" on the input stream for making a tag. + * At the begining of parsing, the position is undefined. + * By reading a byte, the position is defined. + */ + int c = getcFromInputFile (); + if (c == EOF) + return CORK_NIL; + ungetcToInputFile (c); + } + + vString * tmp_class = anonGenerateNew ("anon_class_", K_CLASS); + int corkIndex = makeSimpleTag (tmp_class, K_CLASS); + vStringDelete (tmp_class); + + tagEntryInfo *e = getEntryInCorkQueue (corkIndex); + if (e) + markTagExtraBit (e, XTAG_ANONYMOUS); + + /* This virtual scope should not be poped. */ + NestingLevel *lv = nestingLevelsPush (nls, corkIndex); + GDS_NL (lv)->indentation = -1; + + return corkIndex; +} + +static void findGDScriptTags (void) +{ + tokenInfo *const token = newToken (); + stringList *decorators = stringListNew(); + bool atStatementStart = true; + + TokenContinuationDepth = 0; + NextToken = NULL; + GDScriptNestingLevels = nestingLevelsNew (sizeof (struct gdscriptNestingLevelUserData)); + + if (isXtagEnabled (GDScriptXtagTable[X_IMPLICIT_CLASS].xtype)) + prepareUnnamedClass (GDScriptNestingLevels); + + readToken (token); + while (token->type != TOKEN_EOF) + { + tokenType iterationTokenType = token->type; + int iterationTokenKeyword = token->keyword; + bool readNext = true; + + if (token->type == TOKEN_INDENT) + setIndent (token); + else if (token->keyword == KEYWORD_class || + token->keyword == KEYWORD_func || + token->keyword == KEYWORD_signal) + { + gdscriptKind kind = K_METHOD; + switch (token->keyword) + { + case KEYWORD_class: kind = K_CLASS; break; + case KEYWORD_func: kind = K_METHOD; break; + case KEYWORD_signal: kind = K_SIGNAL; break; + default: + AssertNotReached(); + } + readNext = parseClassOrDef (token, decorators, kind, false); + } + else if (token->keyword == KEYWORD_extends) + { + readNext = parseExtends (token); + } + else if (token->type == '(') + { /* skip parentheses to avoid finding stuff inside them */ + readNext = skipOverPair (token, '(', ')', NULL, false); + } + else if (token->keyword == KEYWORD_variable || token->keyword == KEYWORD_const) + { + NestingLevel *lv = nestingLevelsGetCurrent (GDScriptNestingLevels); + tagEntryInfo *lvEntry = NULL; + gdscriptKind kind = K_VARIABLE; + + if (lv) + lvEntry = getEntryOfNestingLevel (lv); + + if (lvEntry && lvEntry->kindIndex != K_CLASS) + kind = K_LOCAL_VARIABLE; + + if (token->keyword == KEYWORD_const) + kind = K_CONST; + + readNext = parseVariable (token, kind, decorators, token->keyword); + } + else if (token->keyword == KEYWORD_enum) + { + readNext = parseEnum (token); + } + else if (token->keyword == KEYWORD_class_name) + { + readNext = parseClassName (token); + } + else if (token->type == TOKEN_KEYWORD + && token->keyword == KEYWORD_modifier) + { + stringListAdd (decorators, vStringNewCopy(token->string)); + } + else if (token->type == '@' && atStatementStart && + GDScriptFields[F_ANNOTATIONS].enabled) + { + /* collect decorators */ + readQualifiedName (token); + if (token->type != TOKEN_IDENTIFIER + && (token->keyword != KEYWORD_modifier)) + readNext = false; + else + { + stringListAdd (decorators, vStringNewCopy(token->string)); + readToken (token); + + vString *d = vStringNew (); + readNext = skipOverPair (token, '(', ')', d, true); + if (vStringLength (d) > 0) + stringListAdd (decorators, d); + else + vStringDelete (d); + } + } + + /* clear collected decorators for any non-decorator tokens non-indent + * token. decorator collection takes care of skipping the possible + * argument list, so we should never hit here parsing a decorator */ + if (iterationTokenType != TOKEN_INDENT && + iterationTokenType != '@' && + iterationTokenKeyword != KEYWORD_modifier && + GDScriptFields[F_ANNOTATIONS].enabled) + { + stringListClear (decorators); + } + + atStatementStart = (token->type == TOKEN_INDENT || token->type == ';'); + + if (readNext) + readToken (token); + } + + nestingLevelsFree (GDScriptNestingLevels); + stringListDelete (decorators); + deleteToken (token); + Assert (NextToken == NULL); +} + +static void initialize (const langType language) +{ + Lang_gdscript = language; + + TokenPool = objPoolNew (16, newPoolToken, deletePoolToken, clearPoolToken, NULL); + addKeywordGroup (&modifierKeywords, language); +} + +static void finalize (langType language CTAGS_ATTR_UNUSED, bool initialized) +{ + if (!initialized) + return; + + objPoolDelete (TokenPool); +} + +extern parserDefinition* GDScriptParser (void) +{ + static const char *const extensions[] = { "gd", NULL }; + parserDefinition *def = parserNew ("GDScript"); + def->kindTable = GDScriptKinds; + def->kindCount = ARRAY_SIZE (GDScriptKinds); + def->extensions = extensions; + def->parser = findGDScriptTags; + def->initialize = initialize; + def->finalize = finalize; + def->keywordTable = GDScriptKeywordTable; + def->keywordCount = ARRAY_SIZE (GDScriptKeywordTable); + def->fieldTable = GDScriptFields; + def->fieldCount = ARRAY_SIZE (GDScriptFields); + def->xtagTable = GDScriptXtagTable; + def->xtagCount = ARRAY_SIZE(GDScriptXtagTable); + def->useCork = CORK_QUEUE; + def->requestAutomaticFQTag = true; + return def; +}
Modified: data/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -34,6 +34,7 @@ filetypes_dist = \ filedefs/filetypes.forth \ filedefs/filetypes.fortran \ filedefs/filetypes.freebasic \ + filedefs/filetypes.gdscript \ filedefs/filetypes.Genie.conf \ filedefs/filetypes.glsl \ filedefs/filetypes.go \
Modified: data/filedefs/filetypes.gdscript 69 lines changed, 69 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,69 @@ +# For complete documentation of this file, please see Geany's main documentation +[styling] +# Edit these in the colorscheme .conf file instead +default=default +commentline=comment_line +number=number_1 +string=string_1 +character=character +word=keyword_1 +triple=string_2 +tripledouble=string_2 +classname=type +defname=function +operator=operator +identifier=identifier_1 +commentblock=comment +stringeol=string_eol +word2=keyword_2 +decorator=decorator + +[keywords] +# all items must be in one line +# both primary and identifiers are collected from https://github.com/godotengine/godot-docs/blob/master/_extensions/gdscript.p... and https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gd... +primary=and in not or as breakpoint class class_name extends is func signal const enum static var break continue if elif else for pass return match while setget yield +# additional keywords, will be highlighted with style "word2" +# Using GDScript 2 keyword classification +identifiers=PI TAU INF NAN Color8 ColorN abs acos asin assert atan atan2 await bytes2var ceil char clamp convert cos cosh db2linear decimals dectime deg2rad dict2inst ease exp floor fmod fposmod funcref hash inst2dict instance_from_id is_inf is_nan lerp linear2db load log max min nearest_po2 pow preload print print_stack printerr printraw prints printt rad2deg rand_range rand_seed randf randi randomize range round seed sign sin sinh sqrt stepify str str2var tan tan tanh type_exist typeof var2bytes var2str weakref set get self remote master puppet remotesync mastersync puppetsync icon export onready tool export_enum export_file export_dir export_global_file export_global_dir export_multiline export_placeholder export_range export_exp_easing export_color_no_alpha export_node_path export_flags export_flags_2d_render export_flags_2d_physics export_flags_2d_navigation export_flags_3d_render export_flags_3d_physics export_flags_3d_navigation rpc + +[lexer_properties] +fold.gdscript.quotes=1 +lexer.gdscript.keywords2.no.sub.identifiers=1 + +[settings] +# default extension used when saving files +extension=gd + +# MIME type +mime_type=application/x-gdscript + +# single comment char, like # in this file +comment_single=#\s + +# set to false if a comment character/string should start at column 0 of a line, true uses any +# indentation of the line, e.g. setting to true causes the following on pressing CTRL+d + #command_example(); +# setting to false would generate this +# command_example(); +# This setting works only for single line comments +comment_use_indent=true + +[indentation] +width=4 +# 0 is spaces, 1 is tabs, 2 is tab & spaces +type=1 + +[build-menu] +# %f will be replaced by the complete filename +# %e will be replaced by the filename without extension +# (use only one of it at one time) +FT_00_LB=_Compile +FT_00_CM= +FT_00_WD= +FT_02_LB=_Lint +FT_02_CM= +FT_02_WD= +error_regex=(.+):([0-9]+):([0-9]+) +EX_00_LB=_Execute +EX_00_CM= +EX_00_WD=
Modified: data/filetype_extensions.conf 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -32,6 +32,7 @@ Ferite=*.fe; Forth=*.fs;*.fth; Fortran=*.f90;*.f95;*.f03;*.f08;*.F90;*.F95;*.F03;*.F08; FreeBasic=*.bas;*.bi;*.vbs; +GDScript=*.gd; Genie=*.gs; GLSL=*.glsl;*.frag;*.vert; Go=*.go;
Modified: scintilla/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -29,6 +29,7 @@ lexilla/lexers/LexDiff.cxx \ lexilla/lexers/LexErlang.cxx \ lexilla/lexers/LexForth.cxx \ lexilla/lexers/LexFortran.cxx \ +lexilla/lexers/LexGDScript.cxx \ lexilla/lexers/LexHTML.cxx \ lexilla/lexers/LexHaskell.cxx \ lexilla/lexers/LexJulia.cxx \
Modified: scintilla/lexilla/include/LexicalStyles.iface 19 lines changed, 19 insertions(+), 0 deletions(-) =================================================================== @@ -142,6 +142,7 @@ val SCLEX_HOLLYWOOD=130 val SCLEX_RAKU=131 val SCLEX_FSHARP=132 val SCLEX_JULIA=133 +val SCLEX_GDSCRIPT=134
# When a lexer specifies its language as SCLEX_AUTOMATIC it receives a # value assigned in sequence from SCLEX_AUTOMATIC+1. @@ -2250,3 +2251,21 @@ val SCE_FSHARP_VERBATIM=16 val SCE_FSHARP_QUOTATION=17 val SCE_FSHARP_ATTRIBUTE=18 val SCE_FSHARP_FORMAT_SPEC=19 +# Lexical states for SCLEX_GDSCRIPT +lex GDScript=SCLEX_GDSCRIPT SCE_GD_ +val SCE_GD_DEFAULT=0 +val SCE_GD_COMMENTLINE=1 +val SCE_GD_NUMBER=2 +val SCE_GD_STRING=3 +val SCE_GD_CHARACTER=4 +val SCE_GD_WORD=5 +val SCE_GD_TRIPLE=6 +val SCE_GD_TRIPLEDOUBLE=7 +val SCE_GD_CLASSNAME=8 +val SCE_GD_FUNCNAME=9 +val SCE_GD_OPERATOR=10 +val SCE_GD_IDENTIFIER=11 +val SCE_GD_COMMENTBLOCK=12 +val SCE_GD_STRINGEOL=13 +val SCE_GD_WORD2=14 +val SCE_GD_ANNOTATION=15
Modified: scintilla/lexilla/lexers/LexGDScript.cxx 734 lines changed, 734 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,734 @@ +// Scintilla source code edit control +/** @file LexGDScript.cxx + ** Lexer for GDScript. + **/ +// Copyright 1998-2002 by Neil Hodgson neilh@scintilla.org +// Heavily modified later for GDScript +// The License.txt file describes the conditions under which this software may be distributed. + +#include <cstdlib> +#include <cassert> +#include <cstring> + +#include <string> +#include <string_view> +#include <vector> +#include <map> +#include <algorithm> +#include <functional> + +#include "ILexer.h" +#include "Scintilla.h" +#include "SciLexer.h" + +#include "StringCopy.h" +#include "WordList.h" +#include "LexAccessor.h" +#include "Accessor.h" +#include "StyleContext.h" +#include "CharacterSet.h" +#include "CharacterCategory.h" +#include "LexerModule.h" +#include "OptionSet.h" +#include "SubStyles.h" +#include "DefaultLexer.h" + +using namespace Scintilla; +using namespace Lexilla; + +namespace { + +enum kwType { kwOther, kwClass, kwDef, kwExtends}; + +constexpr int indicatorWhitespace = 1; + +bool IsGDStringStart(int ch) { + return (ch == ''' || ch == '"'); +} + +bool IsGDComment(Accessor &styler, Sci_Position pos, Sci_Position len) { + return len > 0 && styler[pos] == '#'; +} + +constexpr bool IsGDSingleQuoteStringState(int st) noexcept { + + return ((st == SCE_GD_CHARACTER) || (st == SCE_GD_STRING)); +} + +constexpr bool IsGDTripleQuoteStringState(int st) noexcept { + return ((st == SCE_GD_TRIPLE) || (st == SCE_GD_TRIPLEDOUBLE)); +} + +char GetGDStringQuoteChar(int st) noexcept { + if ((st == SCE_GD_CHARACTER) || (st == SCE_GD_TRIPLE)) + return '''; + if ((st == SCE_GD_STRING) || (st == SCE_GD_TRIPLEDOUBLE)) + return '"'; + + return '\0'; +} + +/* Return the state to use for the string starting at i; *nextIndex will be set to the first index following the quote(s) */ +int GetGDStringState(Accessor &styler, Sci_Position i, Sci_PositionU *nextIndex) { + char ch = styler.SafeGetCharAt(i); + char chNext = styler.SafeGetCharAt(i + 1); + + if (ch != '"' && ch != ''') { + *nextIndex = i + 1; + return SCE_GD_DEFAULT; + } + + if (ch == chNext && ch == styler.SafeGetCharAt(i + 2)) { + *nextIndex = i + 3; + + if (ch == '"') + return SCE_GD_TRIPLEDOUBLE; + else + return SCE_GD_TRIPLE; + } else { + *nextIndex = i + 1; + + if (ch == '"') + return SCE_GD_STRING; + else + return SCE_GD_CHARACTER; + } +} + +inline bool IsAWordChar(int ch, bool unicodeIdentifiers) { + if (IsASCII(ch)) + return (IsAlphaNumeric(ch) || ch == '.' || ch == '_'); + + if (!unicodeIdentifiers) + return false; + + return IsXidContinue(ch); +} + +inline bool IsAWordStart(int ch, bool unicodeIdentifiers) { + if (IsASCII(ch)) + return (IsUpperOrLowerCase(ch) || ch == '_'); + + if (!unicodeIdentifiers) + return false; + + return IsXidStart(ch); +} + +bool IsFirstNonWhitespace(Sci_Position pos, Accessor &styler) { + const Sci_Position line = styler.GetLine(pos); + const Sci_Position start_pos = styler.LineStart(line); + for (Sci_Position i = start_pos; i < pos; i++) { + const char ch = styler[i]; + if (!(ch == ' ' || ch == '\t')) + return false; + } + return true; +} + +// Options used for LexerGDScript +struct OptionsGDScript { + int whingeLevel; + bool base2or8Literals; + bool stringsOverNewline; + bool keywords2NoSubIdentifiers; + bool fold; + bool foldQuotes; + bool foldCompact; + bool unicodeIdentifiers; + + OptionsGDScript() noexcept { + whingeLevel = 0; + base2or8Literals = true; + stringsOverNewline = false; + keywords2NoSubIdentifiers = false; + fold = false; + foldQuotes = false; + foldCompact = false; + unicodeIdentifiers = true; + } +}; + +const char *const gdscriptWordListDesc[] = { + "Keywords", + "Highlighted identifiers", + nullptr +}; + +struct OptionSetGDScript : public OptionSet<OptionsGDScript> { + OptionSetGDScript() { + DefineProperty("lexer.gdscript.whinge.level", &OptionsGDScript::whingeLevel, + "For GDScript code, checks whether indenting is consistent. " + "The default, 0 turns off indentation checking, " + "1 checks whether each line is potentially inconsistent with the previous line, " + "2 checks whether any space characters occur before a tab character in the indentation, " + "3 checks whether any spaces are in the indentation, and " + "4 checks for any tab characters in the indentation. " + "1 is a good level to use."); + + DefineProperty("lexer.gdscript.literals.binary", &OptionsGDScript::base2or8Literals, + "Set to 0 to not recognise binary and octal literals: 0b1011 0o712."); + + DefineProperty("lexer.gdscript.strings.over.newline", &OptionsGDScript::stringsOverNewline, + "Set to 1 to allow strings to span newline characters."); + + DefineProperty("lexer.gdscript.keywords2.no.sub.identifiers", &OptionsGDScript::keywords2NoSubIdentifiers, + "When enabled, it will not style keywords2 items that are used as a sub-identifier. " + "Example: when set, will not highlight "foo.open" when "open" is a keywords2 item."); + + DefineProperty("fold", &OptionsGDScript::fold); + + DefineProperty("fold.gdscript.quotes", &OptionsGDScript::foldQuotes, + "This option enables folding multi-line quoted strings when using the GDScript lexer."); + + DefineProperty("fold.compact", &OptionsGDScript::foldCompact); + + DefineProperty("lexer.gdscript.unicode.identifiers", &OptionsGDScript::unicodeIdentifiers, + "Set to 0 to not recognise Unicode identifiers."); + + DefineWordListSets(gdscriptWordListDesc); + } +}; + +const char styleSubable[] = { SCE_GD_IDENTIFIER, 0 }; + +LexicalClass lexicalClasses[] = { + // Lexer GDScript SCLEX_GDSCRIPT SCE_GD_: + 0, "SCE_GD_DEFAULT", "default", "White space", + 1, "SCE_GD_COMMENTLINE", "comment line", "Comment", + 2, "SCE_GD_NUMBER", "literal numeric", "Number", + 3, "SCE_GD_STRING", "literal string", "String", + 4, "SCE_GD_CHARACTER", "literal string", "Single quoted string", + 5, "SCE_GD_WORD", "keyword", "Keyword", + 6, "SCE_GD_TRIPLE", "literal string", "Triple quotes", + 7, "SCE_GD_TRIPLEDOUBLE", "literal string", "Triple double quotes", + 8, "SCE_GD_CLASSNAME", "identifier", "Class name definition", + 9, "SCE_GD_FUNCNAME", "identifier", "Function or method name definition", + 10, "SCE_GD_OPERATOR", "operator", "Operators", + 11, "SCE_GD_IDENTIFIER", "identifier", "Identifiers", + 12, "SCE_GD_COMMENTBLOCK", "comment", "Comment-blocks", + 13, "SCE_GD_STRINGEOL", "error literal string", "End of line where string is not closed", + 14, "SCE_GD_WORD2", "identifier", "Highlighted identifiers", + 15, "SCE_GD_ANNOTATION", "annotation", "Annotations", +}; + +} + +class LexerGDScript : public DefaultLexer { + WordList keywords; + WordList keywords2; + OptionsGDScript options; + OptionSetGDScript osGDScript; + enum { ssIdentifier }; + SubStyles subStyles; +public: + explicit LexerGDScript() : + DefaultLexer("gdscript", SCLEX_GDSCRIPT, lexicalClasses, ELEMENTS(lexicalClasses)), + subStyles(styleSubable, 0x80, 0x40, 0) { + } + ~LexerGDScript() override { + } + void SCI_METHOD Release() override { + delete this; + } + int SCI_METHOD Version() const override { + return lvRelease5; + } + const char *SCI_METHOD PropertyNames() override { + return osGDScript.PropertyNames(); + } + int SCI_METHOD PropertyType(const char *name) override { + return osGDScript.PropertyType(name); + } + const char *SCI_METHOD DescribeProperty(const char *name) override { + return osGDScript.DescribeProperty(name); + } + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; + const char * SCI_METHOD PropertyGet(const char *key) override { + return osGDScript.PropertyGet(key); + } + const char *SCI_METHOD DescribeWordListSets() override { + return osGDScript.DescribeWordListSets(); + } + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + + void *SCI_METHOD PrivateCall(int, void *) override { + return nullptr; + } + + int SCI_METHOD LineEndTypesSupported() override { + return SC_LINE_END_TYPE_UNICODE; + } + + int SCI_METHOD AllocateSubStyles(int styleBase, int numberStyles) override { + return subStyles.Allocate(styleBase, numberStyles); + } + int SCI_METHOD SubStylesStart(int styleBase) override { + return subStyles.Start(styleBase); + } + int SCI_METHOD SubStylesLength(int styleBase) override { + return subStyles.Length(styleBase); + } + int SCI_METHOD StyleFromSubStyle(int subStyle) override { + const int styleBase = subStyles.BaseStyle(subStyle); + return styleBase; + } + int SCI_METHOD PrimaryStyleFromStyle(int style) override { + return style; + } + void SCI_METHOD FreeSubStyles() override { + subStyles.Free(); + } + void SCI_METHOD SetIdentifiers(int style, const char *identifiers) override { + subStyles.SetIdentifiers(style, identifiers); + } + int SCI_METHOD DistanceToSecondaryStyles() override { + return 0; + } + const char *SCI_METHOD GetSubStyleBases() override { + return styleSubable; + } + + static ILexer5 *LexerFactoryGDScript() { + return new LexerGDScript(); + } + +private: + void ProcessLineEnd(StyleContext &sc, bool &inContinuedString); +}; + +Sci_Position SCI_METHOD LexerGDScript::PropertySet(const char *key, const char *val) { + if (osGDScript.PropertySet(&options, key, val)) { + return 0; + } + return -1; +} + +Sci_Position SCI_METHOD LexerGDScript::WordListSet(int n, const char *wl) { + WordList *wordListN = nullptr; + switch (n) { + case 0: + wordListN = &keywords; + break; + case 1: + wordListN = &keywords2; + break; + default: + break; + } + Sci_Position firstModification = -1; + if (wordListN) { + WordList wlNew; + wlNew.Set(wl); + if (*wordListN != wlNew) { + wordListN->Set(wl); + firstModification = 0; + } + } + return firstModification; +} + +void LexerGDScript::ProcessLineEnd(StyleContext &sc, bool &inContinuedString) { + if ((sc.state == SCE_GD_DEFAULT) + || IsGDTripleQuoteStringState(sc.state)) { + // Perform colourisation of white space and triple quoted strings at end of each line to allow + // tab marking to work inside white space and triple quoted strings + sc.SetState(sc.state); + } + + if (IsGDSingleQuoteStringState(sc.state)) { + if (inContinuedString || options.stringsOverNewline) { + inContinuedString = false; + } else { + sc.ChangeState(SCE_GD_STRINGEOL); + sc.ForwardSetState(SCE_GD_DEFAULT); + } + } +} + +void SCI_METHOD LexerGDScript::Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) { + Accessor styler(pAccess, nullptr); + + const Sci_Position endPos = startPos + length; + + // Backtrack to previous line in case need to fix its tab whinging + Sci_Position lineCurrent = styler.GetLine(startPos); + if (startPos > 0) { + if (lineCurrent > 0) { + lineCurrent--; + // Look for backslash-continued lines + while (lineCurrent > 0) { + const Sci_Position eolPos = styler.LineStart(lineCurrent) - 1; + const int eolStyle = styler.StyleAt(eolPos); + if (eolStyle == SCE_GD_STRING || eolStyle == SCE_GD_CHARACTER + || eolStyle == SCE_GD_STRINGEOL) { + lineCurrent -= 1; + } else { + break; + } + } + startPos = styler.LineStart(lineCurrent); + } + initStyle = startPos == 0 ? SCE_GD_DEFAULT : styler.StyleAt(startPos - 1); + } + + initStyle = initStyle & 31; + if (initStyle == SCE_GD_STRINGEOL) { + initStyle = SCE_GD_DEFAULT; + } + + kwType kwLast = kwOther; + int spaceFlags = 0; + styler.IndentAmount(lineCurrent, &spaceFlags, IsGDComment); + bool base_n_number = false; + + const WordClassifier &classifierIdentifiers = subStyles.Classifier(SCE_GD_IDENTIFIER); + + StyleContext sc(startPos, endPos - startPos, initStyle, styler); + + bool indentGood = true; + Sci_Position startIndicator = sc.currentPos; + bool inContinuedString = false; + + for (; sc.More(); sc.Forward()) { + + if (sc.atLineStart) { + styler.IndentAmount(lineCurrent, &spaceFlags, IsGDComment); + indentGood = true; + if (options.whingeLevel == 1) { + indentGood = (spaceFlags & wsInconsistent) == 0; + } else if (options.whingeLevel == 2) { + indentGood = (spaceFlags & wsSpaceTab) == 0; + } else if (options.whingeLevel == 3) { + indentGood = (spaceFlags & wsSpace) == 0; + } else if (options.whingeLevel == 4) { + indentGood = (spaceFlags & wsTab) == 0; + } + if (!indentGood) { + styler.IndicatorFill(startIndicator, sc.currentPos, indicatorWhitespace, 0); + startIndicator = sc.currentPos; + } + } + + if (sc.atLineEnd) { + ProcessLineEnd(sc, inContinuedString); + lineCurrent++; + if (!sc.More()) + break; + } + + bool needEOLCheck = false; + + if (sc.state == SCE_GD_OPERATOR) { + kwLast = kwOther; + sc.SetState(SCE_GD_DEFAULT); + } else if (sc.state == SCE_GD_NUMBER) { + if (!IsAWordChar(sc.ch, false) && + !(!base_n_number && ((sc.ch == '+' || sc.ch == '-') && (sc.chPrev == 'e' || sc.chPrev == 'E')))) { + sc.SetState(SCE_GD_DEFAULT); + } + } else if (sc.state == SCE_GD_IDENTIFIER) { + if ((sc.ch == '.') || (!IsAWordChar(sc.ch, options.unicodeIdentifiers))) { + char s[100]; + sc.GetCurrent(s, sizeof(s)); + int style = SCE_GD_IDENTIFIER; + if (keywords.InList(s)) { + style = SCE_GD_WORD; + } else if (kwLast == kwClass) { + style = SCE_GD_CLASSNAME; + } else if (kwLast == kwDef) { + style = SCE_GD_FUNCNAME; + } else if (keywords2.InList(s)) { + if (options.keywords2NoSubIdentifiers) { + // We don't want to highlight keywords2 + // that are used as a sub-identifier, + // i.e. not open in "foo.open". + const Sci_Position pos = styler.GetStartSegment() - 1; + if (pos < 0 || (styler.SafeGetCharAt(pos, '\0') != '.')) + style = SCE_GD_WORD2; + } else { + style = SCE_GD_WORD2; + } + } else { + const int subStyle = classifierIdentifiers.ValueFor(s); + if (subStyle >= 0) { + style = subStyle; + } + } + sc.ChangeState(style); + sc.SetState(SCE_GD_DEFAULT); + if (style == SCE_GD_WORD) { + if (0 == strcmp(s, "class")) + kwLast = kwClass; + else if (0 == strcmp(s, "func")) + kwLast = kwDef; + else if (0 == strcmp(s, "extends")) + kwLast = kwExtends; + else + kwLast = kwOther; + } else { + kwLast = kwOther; + } + } + } else if ((sc.state == SCE_GD_COMMENTLINE) || (sc.state == SCE_GD_COMMENTBLOCK)) { + if (sc.ch == '\r' || sc.ch == '\n') { + sc.SetState(SCE_GD_DEFAULT); + } + } else if (sc.state == SCE_GD_ANNOTATION) { + if (!IsAWordStart(sc.ch, options.unicodeIdentifiers)) { + sc.SetState(SCE_GD_DEFAULT); + } + } else if (IsGDSingleQuoteStringState(sc.state)) { + if (sc.ch == '\') { + if ((sc.chNext == '\r') && (sc.GetRelative(2) == '\n')) { + sc.Forward(); + } + if (sc.chNext == '\n' || sc.chNext == '\r') { + inContinuedString = true; + } else { + // Don't roll over the newline. + sc.Forward(); + } + } else if (sc.ch == GetGDStringQuoteChar(sc.state)) { + sc.ForwardSetState(SCE_GD_DEFAULT); + needEOLCheck = true; + } + } else if (sc.state == SCE_GD_TRIPLE) { + if (sc.ch == '\') { + sc.Forward(); + } else if (sc.Match(R"(''')")) { + sc.Forward(); + sc.Forward(); + sc.ForwardSetState(SCE_GD_DEFAULT); + needEOLCheck = true; + } + } else if (sc.state == SCE_GD_TRIPLEDOUBLE) { + if (sc.ch == '\') { + sc.Forward(); + } else if (sc.Match(R"(""")")) { + sc.Forward(); + sc.Forward(); + sc.ForwardSetState(SCE_GD_DEFAULT); + needEOLCheck = true; + } + } + + if (!indentGood && !IsASpaceOrTab(sc.ch)) { + styler.IndicatorFill(startIndicator, sc.currentPos, indicatorWhitespace, 1); + startIndicator = sc.currentPos; + indentGood = true; + } + + // State exit code may have moved on to end of line + if (needEOLCheck && sc.atLineEnd) { + ProcessLineEnd(sc, inContinuedString); + lineCurrent++; + styler.IndentAmount(lineCurrent, &spaceFlags, IsGDComment); + if (!sc.More()) + break; + } + + // Check for a new state starting character + if (sc.state == SCE_GD_DEFAULT) { + if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) { + if (sc.ch == '0' && (sc.chNext == 'x' || sc.chNext == 'X')) { + base_n_number = true; + sc.SetState(SCE_GD_NUMBER); + } else if (sc.ch == '0' && + (sc.chNext == 'o' || sc.chNext == 'O' || sc.chNext == 'b' || sc.chNext == 'B')) { + if (options.base2or8Literals) { + base_n_number = true; + sc.SetState(SCE_GD_NUMBER); + } else { + sc.SetState(SCE_GD_NUMBER); + sc.ForwardSetState(SCE_GD_IDENTIFIER); + } + } else { + base_n_number = false; + sc.SetState(SCE_GD_NUMBER); + } + } else if (isoperator(sc.ch) || sc.ch == '`') { + sc.SetState(SCE_GD_OPERATOR); + } else if (sc.ch == '#') { + sc.SetState(sc.chNext == '#' ? SCE_GD_COMMENTBLOCK : SCE_GD_COMMENTLINE); + } else if (sc.ch == '@') { + if (IsFirstNonWhitespace(sc.currentPos, styler)) + sc.SetState(SCE_GD_ANNOTATION); + else + sc.SetState(SCE_GD_OPERATOR); + } else if (IsGDStringStart(sc.ch)) { + Sci_PositionU nextIndex = 0; + sc.SetState(GetGDStringState(styler, sc.currentPos, &nextIndex)); + while (nextIndex > (sc.currentPos + 1) && sc.More()) { + sc.Forward(); + } + } else if (IsAWordStart(sc.ch, options.unicodeIdentifiers)) { + sc.SetState(SCE_GD_IDENTIFIER); + } + } + } + styler.IndicatorFill(startIndicator, sc.currentPos, indicatorWhitespace, 0); + sc.Complete(); +} + +static bool IsCommentLine(Sci_Position line, Accessor &styler) { + const Sci_Position pos = styler.LineStart(line); + const Sci_Position eol_pos = styler.LineStart(line + 1) - 1; + for (Sci_Position i = pos; i < eol_pos; i++) { + const char ch = styler[i]; + if (ch == '#') + return true; + else if (ch != ' ' && ch != '\t') + return false; + } + return false; +} + +static bool IsQuoteLine(Sci_Position line, const Accessor &styler) { + const int style = styler.StyleAt(styler.LineStart(line)) & 31; + return IsGDTripleQuoteStringState(style); +} + + +void SCI_METHOD LexerGDScript::Fold(Sci_PositionU startPos, Sci_Position length, int /*initStyle - unused*/, IDocument *pAccess) { + if (!options.fold) + return; + + Accessor styler(pAccess, nullptr); + + const Sci_Position maxPos = startPos + length; + const Sci_Position maxLines = (maxPos == styler.Length()) ? styler.GetLine(maxPos) : styler.GetLine(maxPos - 1); // Requested last line + const Sci_Position docLines = styler.GetLine(styler.Length()); // Available last line + + // Backtrack to previous non-blank line so we can determine indent level + // for any white space lines (needed esp. within triple quoted strings) + // and so we can fix any preceding fold level (which is why we go back + // at least one line in all cases) + int spaceFlags = 0; + Sci_Position lineCurrent = styler.GetLine(startPos); + int indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags, nullptr); + while (lineCurrent > 0) { + lineCurrent--; + indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags, nullptr); + if (!(indentCurrent & SC_FOLDLEVELWHITEFLAG) && + (!IsCommentLine(lineCurrent, styler)) && + (!IsQuoteLine(lineCurrent, styler))) + break; + } + int indentCurrentLevel = indentCurrent & SC_FOLDLEVELNUMBERMASK; + + // Set up initial loop state + startPos = styler.LineStart(lineCurrent); + int prev_state = SCE_GD_DEFAULT & 31; + if (lineCurrent >= 1) + prev_state = styler.StyleAt(startPos - 1) & 31; + int prevQuote = options.foldQuotes && IsGDTripleQuoteStringState(prev_state); + + // Process all characters to end of requested range or end of any triple quote + //that hangs over the end of the range. Cap processing in all cases + // to end of document (in case of unclosed quote at end). + while ((lineCurrent <= docLines) && ((lineCurrent <= maxLines) || prevQuote)) { + + // Gather info + int lev = indentCurrent; + Sci_Position lineNext = lineCurrent + 1; + int indentNext = indentCurrent; + int quote = false; + if (lineNext <= docLines) { + // Information about next line is only available if not at end of document + indentNext = styler.IndentAmount(lineNext, &spaceFlags, nullptr); + const Sci_Position lookAtPos = (styler.LineStart(lineNext) == styler.Length()) ? styler.Length() - 1 : styler.LineStart(lineNext); + const int style = styler.StyleAt(lookAtPos) & 31; + quote = options.foldQuotes && IsGDTripleQuoteStringState(style); + } + const bool quote_start = (quote && !prevQuote); + const bool quote_continue = (quote && prevQuote); + if (!quote || !prevQuote) + indentCurrentLevel = indentCurrent & SC_FOLDLEVELNUMBERMASK; + if (quote) + indentNext = indentCurrentLevel; + if (indentNext & SC_FOLDLEVELWHITEFLAG) + indentNext = SC_FOLDLEVELWHITEFLAG | indentCurrentLevel; + + if (quote_start) { + // Place fold point at start of triple quoted string + lev |= SC_FOLDLEVELHEADERFLAG; + } else if (quote_continue || prevQuote) { + // Add level to rest of lines in the string + lev = lev + 1; + } + + // Skip past any blank lines for next indent level info; we skip also + // comments (all comments, not just those starting in column 0) + // which effectively folds them into surrounding code rather + // than screwing up folding. If comments end file, use the min + // comment indent as the level after + + int minCommentLevel = indentCurrentLevel; + while (!quote && + (lineNext < docLines) && + ((indentNext & SC_FOLDLEVELWHITEFLAG) || (IsCommentLine(lineNext, styler)))) { + + if (IsCommentLine(lineNext, styler) && indentNext < minCommentLevel) { + minCommentLevel = indentNext; + } + + lineNext++; + indentNext = styler.IndentAmount(lineNext, &spaceFlags, nullptr); + } + + const int levelAfterComments = ((lineNext < docLines) ? indentNext & SC_FOLDLEVELNUMBERMASK : minCommentLevel); + const int levelBeforeComments = std::max(indentCurrentLevel, levelAfterComments); + + // Now set all the indent levels on the lines we skipped + // Do this from end to start. Once we encounter one line + // which is indented more than the line after the end of + // the comment-block, use the level of the block before + + Sci_Position skipLine = lineNext; + int skipLevel = levelAfterComments; + + while (--skipLine > lineCurrent) { + const int skipLineIndent = styler.IndentAmount(skipLine, &spaceFlags, nullptr); + + if (options.foldCompact) { + if ((skipLineIndent & SC_FOLDLEVELNUMBERMASK) > levelAfterComments) + skipLevel = levelBeforeComments; + + const int whiteFlag = skipLineIndent & SC_FOLDLEVELWHITEFLAG; + + styler.SetLevel(skipLine, skipLevel | whiteFlag); + } else { + if ((skipLineIndent & SC_FOLDLEVELNUMBERMASK) > levelAfterComments && + !(skipLineIndent & SC_FOLDLEVELWHITEFLAG) && + !IsCommentLine(skipLine, styler)) + skipLevel = levelBeforeComments; + + styler.SetLevel(skipLine, skipLevel); + } + } + + // Set fold header on non-quote line + if (!quote && !(indentCurrent & SC_FOLDLEVELWHITEFLAG)) { + if ((indentCurrent & SC_FOLDLEVELNUMBERMASK) < (indentNext & SC_FOLDLEVELNUMBERMASK)) + lev |= SC_FOLDLEVELHEADERFLAG; + } + + // Keep track of triple quote state of previous line + prevQuote = quote; + + // Set fold level for this line and move to next line + styler.SetLevel(lineCurrent, options.foldCompact ? lev : lev & ~SC_FOLDLEVELWHITEFLAG); + indentCurrent = indentNext; + lineCurrent = lineNext; + } + + // NOTE: Cannot set level of last line here because indentCurrent doesn't have + // header flag set; the loop above is crafted to take care of this case! + //styler.SetLevel(lineCurrent, indentCurrent); +} + +LexerModule lmGDScript(SCLEX_GDSCRIPT, LexerGDScript::LexerFactoryGDScript, "gdscript", + gdscriptWordListDesc);
Modified: scintilla/lexilla/src/Lexilla.cxx 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -188,6 +188,7 @@ static void AddGeanyLexers() &lmForth, &lmFortran, &lmFreeBasic, ++ &lmGDScript, &lmHaskell, &lmHTML, &lmJulia,
Modified: scintilla/scintilla_changes.patch 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -87,6 +87,7 @@ index cd4b23617..af4a73db4 100644 + &lmForth, + &lmFortran, + &lmFreeBasic, ++ &lmGDScript, + &lmHaskell, + &lmHTML, + &lmJulia,
Modified: src/filetypes.c 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -188,6 +188,7 @@ static void init_builtin_filetypes(void) FT_INIT( ZEPHIR, ZEPHIR, "Zephir", NULL, SOURCE_FILE, COMPILED ); FT_INIT( SMALLTALK, NONE, "Smalltalk", NULL, SOURCE_FILE, SCRIPT ); FT_INIT( JULIA, JULIA, "Julia", NULL, SOURCE_FILE, SCRIPT ); + FT_INIT( GDSCRIPT, GDSCRIPT, "GDScript", NULL, SOURCE_FILE, SCRIPT ); }
Modified: src/filetypes.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -108,6 +108,7 @@ typedef enum GEANY_FILETYPES_BIBTEX, GEANY_FILETYPES_SMALLTALK, GEANY_FILETYPES_JULIA, + GEANY_FILETYPES_GDSCRIPT, /* ^ append items here */ GEANY_MAX_BUILT_IN_FILETYPES /* Don't use this, use filetypes_array->len instead */ }
Modified: src/highlighting.c 13 lines changed, 13 insertions(+), 0 deletions(-) =================================================================== @@ -1019,6 +1019,7 @@ void highlighting_init_styles(guint filetype_idx, GKeyFile *config, GKeyFile *co init_styleset_case(F77); init_styleset_case(FORTH); init_styleset_case(FORTRAN); + init_styleset_case(GDSCRIPT); init_styleset_case(GO); init_styleset_case(HASKELL); init_styleset_case(HAXE); @@ -1109,6 +1110,7 @@ void highlighting_set_styles(ScintillaObject *sci, GeanyFiletype *ft) styleset_case(F77); styleset_case(FORTH); styleset_case(FORTRAN); + styleset_case(GDSCRIPT); styleset_case(GO); styleset_case(HASKELL); styleset_case(HAXE); @@ -1436,6 +1438,13 @@ gboolean highlighting_is_string_style(gint lexer, gint style) style == SCE_P_FTRIPLEDOUBLE || style == SCE_P_STRINGEOL);
+ case SCLEX_GDSCRIPT: + return (style == SCE_GD_STRING || + style == SCE_GD_TRIPLE || + style == SCE_GD_TRIPLEDOUBLE || + style == SCE_GD_CHARACTER || + style == SCE_GD_STRINGEOL); + case SCLEX_F77: case SCLEX_FORTRAN: return (style == SCE_F_STRING1 || @@ -1855,6 +1864,10 @@ gboolean highlighting_is_comment_style(gint lexer, gint style) case SCLEX_MARKDOWN: /* there is no comment type in those lexers, listing here just for completeness */ return FALSE; + + case SCLEX_GDSCRIPT: + return (style == SCE_GD_COMMENTLINE || + style == SCE_GD_COMMENTBLOCK); } return FALSE; }
Modified: src/highlightingmappings.h 29 lines changed, 29 insertions(+), 0 deletions(-) =================================================================== @@ -655,6 +655,35 @@ static const HLKeyword highlighting_keywords_FORTH[] = #define highlighting_properties_FORTRAN highlighting_properties_F77
+/* GDScript */ +#define highlighting_lexer_GDSCRIPT SCLEX_GDSCRIPT +static const HLStyle highlighting_styles_GDSCRIPT[] = +{ + { SCE_GD_DEFAULT, "default", FALSE }, + { SCE_GD_COMMENTLINE, "commentline", FALSE }, + { SCE_GD_NUMBER, "number", FALSE }, + { SCE_GD_STRING, "string", FALSE }, + { SCE_GD_CHARACTER, "character", FALSE }, + { SCE_GD_WORD, "word", FALSE }, + { SCE_GD_TRIPLE, "triple", FALSE }, + { SCE_GD_TRIPLEDOUBLE, "tripledouble", FALSE }, + { SCE_GD_CLASSNAME, "classname", FALSE }, + { SCE_GD_FUNCNAME, "funcname", FALSE }, + { SCE_GD_OPERATOR, "operator", FALSE }, + { SCE_GD_IDENTIFIER, "identifier", FALSE }, + { SCE_GD_COMMENTBLOCK, "commentblock", FALSE }, + { SCE_GD_STRINGEOL, "stringeol", FALSE }, + { SCE_GD_WORD2, "word2", FALSE }, + { SCE_GD_ANNOTATION, "annotation", FALSE } +}; +static const HLKeyword highlighting_keywords_GDSCRIPT[] = +{ + { 0, "primary", FALSE }, + { 1, "identifiers", FALSE } +}; +#define highlighting_properties_GDSCRIPT EMPTY_PROPERTIES + + /* Go */ #define highlighting_lexer_GO SCLEX_CPP #define highlighting_styles_GO highlighting_styles_C
Modified: src/symbols.c 12 lines changed, 12 insertions(+), 0 deletions(-) =================================================================== @@ -515,6 +515,18 @@ static void add_top_level_items(GeanyDocument *doc) &tv_iters.tag_macro, _("Keys"), ICON_VAR, NULL); break; + case GEANY_FILETYPES_GDSCRIPT: + { + tag_list_add_groups(tag_store, + &(tv_iters.tag_class), _("Classes"), ICON_CLASS, + &(tv_iters.tag_member), _("Methods"), ICON_MACRO, + &(tv_iters.tag_function), _("Functions"), ICON_METHOD, + &(tv_iters.tag_variable), _("Variables"), ICON_VAR, + &(tv_iters.tag_externvar), _("Imports"), ICON_NAMESPACE, + &(tv_iters.tag_type), _("Enums"), ICON_STRUCT, + NULL); + break; + } case GEANY_FILETYPES_NSIS: tag_list_add_groups(tag_store, &tv_iters.tag_namespace, _("Sections"), ICON_OTHER,
Modified: src/tagmanager/tm_parser.c 17 lines changed, 17 insertions(+), 0 deletions(-) =================================================================== @@ -597,6 +597,17 @@ static TMParserMapEntry map_CPREPROCESSOR[] = { {'h', tm_tag_undef_t}, {'D', tm_tag_undef_t}, }; +static TMParserMapEntry map_GDSCRIPT[] = { + {'c', tm_tag_class_t}, + {'m', tm_tag_method_t}, + {'v', tm_tag_variable_t}, + {'C', tm_tag_variable_t}, + {'g', tm_tag_enum_t}, + {'e', tm_tag_variable_t}, + {'z', tm_tag_other_t}, + {'l', tm_tag_other_t}, + {'s', tm_tag_variable_t}, +};
typedef struct { @@ -662,6 +673,7 @@ static TMParserMap parser_map[] = { MAP_ENTRY(POWERSHELL), MAP_ENTRY(JULIA), MAP_ENTRY(CPREPROCESSOR), + MAP_ENTRY(GDSCRIPT), }; /* make sure the parser map is consistent and complete */ G_STATIC_ASSERT(G_N_ELEMENTS(parser_map) == TM_PARSER_COUNT); @@ -895,6 +907,8 @@ gboolean tm_parser_enable_role(TMParserType lang, gchar kind) { switch (lang) { + case TM_PARSER_GDSCRIPT: + return kind == 'c' ? FALSE : TRUE; case TM_PARSER_GO: /* 'p' is used both for package definition tags and imported package * tags and we can't tell which is which just by kind. By disabling @@ -967,6 +981,7 @@ gchar *tm_parser_format_function(TMParserType lang, const gchar *fname, const gc { switch (lang) { + case TM_PARSER_GDSCRIPT: case TM_PARSER_GO: case TM_PARSER_PASCAL: case TM_PARSER_PYTHON: @@ -978,6 +993,7 @@ gchar *tm_parser_format_function(TMParserType lang, const gchar *fname, const gc case TM_PARSER_PASCAL: sep = ": "; break; + case TM_PARSER_GDSCRIPT: case TM_PARSER_PYTHON: sep = " -> "; break; @@ -1042,6 +1058,7 @@ gboolean tm_parser_has_full_context(TMParserType lang) case TM_PARSER_COBOL: case TM_PARSER_D: case TM_PARSER_FERITE: + case TM_PARSER_GDSCRIPT: case TM_PARSER_GLSL: case TM_PARSER_GO: case TM_PARSER_JAVA:
Modified: src/tagmanager/tm_parser.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -112,6 +112,7 @@ enum TM_PARSER_JULIA, TM_PARSER_BIBTEX, TM_PARSER_CPREPROCESSOR, + TM_PARSER_GDSCRIPT, TM_PARSER_COUNT };
Modified: src/tagmanager/tm_parsers.h 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -67,6 +67,7 @@ PowerShellParser, \ JuliaParser, \ BibtexParser, \ - CPreProParser + CPreProParser, \ + GDScriptParser
#endif
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).