From 321809c4c7d196fe16d159a33157e4cc479a190b Mon Sep 17 00:00:00 2001 From: gambas Date: Fri, 5 Mar 2021 17:10:59 +0100 Subject: [PATCH] Keywords and subroutines are now returned by two different properties of the System class. [GB.EVAL] * NEW: Keywords and subroutines are now returned by two different properties of the System class. * NEW: System properties Keywords, Subroutines and Datatypes now return a read-only array. [GB.EVAL.HIGHLIGHT] * NEW: Support for the new System Keywords and Subroutines properties. --- comp/src/gb.eval.highlight/.src/Main.module | 15 +++++++ .../.src/TextHighlighter.class | 4 +- .../.src/TextHighlighter_Gambas.class | 9 +++- main/lib/eval/c_system.c | 43 ++++++++++++++----- 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/comp/src/gb.eval.highlight/.src/Main.module b/comp/src/gb.eval.highlight/.src/Main.module index ad5a53835..7836dd7a8 100644 --- a/comp/src/gb.eval.highlight/.src/Main.module +++ b/comp/src/gb.eval.highlight/.src/Main.module @@ -47,9 +47,24 @@ End Public Sub Main() Dim hHighlighter As TextHighlighter + Dim sLine As String + Dim L As Integer hHighlighter = TextHighlighter["gambas"] + '#Include "toto\n" + + ' For Each sLine In Split(File.Load("~/gambas/git/master/comp/src/gb.form.editor/.src/TextEditor.class"), "\n") + ' Print L + ' Highlight.Analyze(sLine, True) + ' Inc L + ' Next + + Highlight.Analyze(" #If Test", True) + + Print + Print Highlight.Symbols.Join("\n") + 'Print hHighlighter.ToHTML(File.Load("src.txt")) ' TextHighlighter._Highlight = New Byte[] diff --git a/comp/src/gb.eval.highlight/.src/TextHighlighter.class b/comp/src/gb.eval.highlight/.src/TextHighlighter.class index 9865fd8bf..5103613cc 100644 --- a/comp/src/gb.eval.highlight/.src/TextHighlighter.class +++ b/comp/src/gb.eval.highlight/.src/TextHighlighter.class @@ -70,8 +70,8 @@ End Static Public Sub _get(Type As String) As TextHighlighter - Try Return Class.Load("TextHighlighter_" & Type).AutoCreate() - Error.Raise("Cannot load highlighter: '" & Type & "'") + Try Return Class.Load("TextHighlighter_" & Type).AutoCreate() + Error.Raise("Cannot load highlighter: '" & Type & "'") End diff --git a/comp/src/gb.eval.highlight/.src/TextHighlighter_Gambas.class b/comp/src/gb.eval.highlight/.src/TextHighlighter_Gambas.class index 0de531230..0edc5b909 100644 --- a/comp/src/gb.eval.highlight/.src/TextHighlighter_Gambas.class +++ b/comp/src/gb.eval.highlight/.src/TextHighlighter_Gambas.class @@ -6,6 +6,8 @@ Public Const Name As String = "gambas" Class Highlight +Static Private $aKeywords As String[] + Static Public Sub _init() Component.Load("gb.eval") @@ -14,7 +16,12 @@ End Public Sub GetKeywords() As String[] - Return System.Keywords + If Not $aKeywords Then + $aKeywords = System.Keywords.Copy() + $aKeywords.Insert(System.Subroutines) + Endif + + Return $aKeywords End diff --git a/main/lib/eval/c_system.c b/main/lib/eval/c_system.c index 9a38072d3..bc3e03424 100644 --- a/main/lib/eval/c_system.c +++ b/main/lib/eval/c_system.c @@ -30,11 +30,11 @@ static GB_ARRAY _keywords = 0; static GB_ARRAY _datatypes = 0; +static GB_ARRAY _subroutines = 0; -BEGIN_PROPERTY(CSYSTEM_keywords) +BEGIN_PROPERTY(System_Keywords) COMP_INFO *info; - SUBR_INFO *subr; char *str; if (!_keywords) @@ -50,12 +50,7 @@ BEGIN_PROPERTY(CSYSTEM_keywords) } } - for (subr = &COMP_subr_info[0]; subr->name; subr++) - { - str = GB.NewZeroString(subr->name); - *((char **)GB.Array.Add(_keywords)) = str; - } - + GB.Array.SetReadOnly(_keywords); GB.Ref(_keywords); } @@ -63,7 +58,30 @@ BEGIN_PROPERTY(CSYSTEM_keywords) END_PROPERTY -BEGIN_PROPERTY(CSYSTEM_datatypes) +BEGIN_PROPERTY(System_Subroutines) + + SUBR_INFO *subr; + char *str; + + if (!_subroutines) + { + GB.Array.New(&_subroutines, GB_T_STRING, 0); + + for (subr = &COMP_subr_info[0]; subr->name; subr++) + { + str = GB.NewZeroString(subr->name); + *((char **)GB.Array.Add(_subroutines)) = str; + } + + GB.Array.SetReadOnly(_subroutines); + GB.Ref(_subroutines); + } + + GB.ReturnObject(_subroutines); + +END_PROPERTY + +BEGIN_PROPERTY(System_Datatypes) COMP_INFO *info; char *str; @@ -81,6 +99,7 @@ BEGIN_PROPERTY(CSYSTEM_datatypes) } } + GB.Array.SetReadOnly(_datatypes); GB.Ref(_datatypes); } @@ -92,6 +111,7 @@ BEGIN_METHOD_VOID(CSYSTEM_exit) GB.Unref((void **)&_keywords); GB.Unref((void **)&_datatypes); + GB.Unref((void **)&_subroutines); END_METHOD @@ -102,8 +122,9 @@ GB_DESC CSystemDesc[] = GB_STATIC_METHOD("_exit", NULL, CSYSTEM_exit, NULL), - GB_STATIC_PROPERTY_READ("Keywords", "String[]", CSYSTEM_keywords), - GB_STATIC_PROPERTY_READ("Datatypes", "String[]", CSYSTEM_datatypes), + GB_STATIC_PROPERTY_READ("Keywords", "String[]", System_Keywords), + GB_STATIC_PROPERTY_READ("Datatypes", "String[]", System_Datatypes), + GB_STATIC_PROPERTY_READ("Subroutines", "String[]", System_Subroutines), GB_END_DECLARE };