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.
This commit is contained in:
gambas 2021-03-05 17:10:59 +01:00 committed by Christof Thalhofer
parent 1662aec5f2
commit 321809c4c7
4 changed files with 57 additions and 14 deletions

View file

@ -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[]

View file

@ -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

View file

@ -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

View file

@ -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
};