From c7303759f86142f3900fc0bd16b24cb5e34ce7b0 Mon Sep 17 00:00:00 2001 From: Brian G Date: Sat, 12 Jun 2021 19:26:00 -0700 Subject: [PATCH] * NEW Add support for STATIC def within a function --- app/src/gbs3/.project | 4 +- .../gbs3/.src/GenerateFromLazyScript.module | 4 ++ app/src/gbs3/.src/Reader.class | 52 +++++++++++++++---- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/app/src/gbs3/.project b/app/src/gbs3/.project index 7d39535b7..889c10ad7 100644 --- a/app/src/gbs3/.project +++ b/app/src/gbs3/.project @@ -8,8 +8,8 @@ Component=gb.eval Component=gb.pcre Description="Gambas Script" Authors="Fabien Bodard, Benoit Minisini, Brian G" -Arguments=[["--help"],["--use","'gb.notify,gb.web'","-e","For i as Integer = 0 To 10:Print \"Hello World\":Next"],["~/bin/who"],["-c","-T","~/bin/mytest"],["-v","TestApp"],["--verbose","TestAppWithMain"],["--verbose","TestLazyApp"],["-c","~/testerror.gbs"],["~/Scripts/TestQuoteAtEnd"],["-c","~/Scripts/AForm"],["-c","-v","-w","~/Scripts/GambasHelpSearch"],["-c","-v","-w","~/Scripts/AMain"],["-c","-v","-w","~/Scripts/gshoutput"],["-c","-v","-w","~/Scripts/TestSets/TestWebApp.gbs"],["--convert-project","~/Projects/TestPrograms/testerror"],["--convert-project","~/Projects/TestPrograms/testusingtxthighlight","~/Scripts/TestSets"],["-c","-v","~/Scripts/TestSets/testusingtxthighlight.gbs"],["-l","library"],["-c","-v","-w","~/Scripts/TestScripterNoMain"],["-c","-v","-w","~/Scripts/TestGUI.gbs"],["-c","-v","-w","~/Scripts/TestSets/CPU_Test.gbs"],["-c","-v","-w","~/Scripts/TestSets/TestWebPage.gbs"],["-c","-v","-w","--convert-script","~/Scripts/TestSets/CPU_Test.gbs","~/Scripts"],["-c","-v","-w","~/Scripts/CPU_Test"],["-c","-v","-w","-p","~/Scripts/TestPlugin","~/myplugins"],["-c","-v","-w","~/Scripts/RunComponent"],["-c","-v","-w","~/Scripts/testshell.gbs"],["-v","~/Projects/TestTimer"],["-c","-v","-w","~/gbs3testwithclass.gbs"]] -CurrentArgumentList=["-c","-v","-w","~/gbs3testwithclass.gbs"] +Arguments=[["--help"],["--use","'gb.notify,gb.web'","-e","For i as Integer = 0 To 10:Print \"Hello World\":Next"],["~/bin/who"],["-c","-T","~/bin/mytest"],["-v","TestApp"],["--verbose","TestAppWithMain"],["--verbose","TestLazyApp"],["-c","~/testerror.gbs"],["~/Scripts/TestQuoteAtEnd"],["-c","~/Scripts/AForm"],["-c","-v","-w","~/Scripts/GambasHelpSearch"],["-c","-v","-w","~/Scripts/AMain"],["-c","-v","-w","~/Scripts/gshoutput"],["-c","-v","-w","~/Scripts/TestSets/TestWebApp.gbs"],["--convert-project","~/Projects/TestPrograms/testerror"],["--convert-project","~/Projects/TestPrograms/testusingtxthighlight","~/Scripts/TestSets"],["-c","-v","~/Scripts/TestSets/testusingtxthighlight.gbs"],["-l","library"],["-c","-v","-w","~/Scripts/TestScripterNoMain"],["-c","-v","-w","~/Scripts/TestGUI.gbs"],["-c","-v","-w","~/Scripts/TestSets/CPU_Test.gbs"],["-c","-v","-w","~/Scripts/TestSets/TestWebPage.gbs"],["-c","-v","-w","--convert-script","~/Scripts/TestSets/CPU_Test.gbs","~/Scripts"],["-c","-v","-w","~/Scripts/CPU_Test"],["-c","-v","-w","-p","~/Scripts/TestPlugin","~/myplugins"],["-c","-v","-w","~/Scripts/RunComponent"],["-c","-v","-w","~/Scripts/testshell.gbs"],["-v","~/Projects/TestTimer"],["-c","-v","-w","~/gbs3testwithclass.gbs"],["-c","-v","-w","/home/brian/Scripts/testLocalStatic.gbs"]] +CurrentArgumentList=["-c","-v","-w","/home/brian/Scripts/testLocalStatic.gbs"] TabSize=2 Translate=1 Language=en_US diff --git a/app/src/gbs3/.src/GenerateFromLazyScript.module b/app/src/gbs3/.src/GenerateFromLazyScript.module index b1488e270..1610d16be 100644 --- a/app/src/gbs3/.src/GenerateFromLazyScript.module +++ b/app/src/gbs3/.src/GenerateFromLazyScript.module @@ -28,6 +28,10 @@ Public Sub _call(oContext As Context, Program As Reader) As String $iAdjustedOffset = 0 For Each i As Integer In Program.GlobalItemPosition + If i < $iAdjustedOffset Then + Warning("Warning : Block Skipped seems to be included in previous block:" & i) + Continue + Endif For Each s As String In Program.ProgramSymbols[i - $iAdjustedOffset] If Not aDefwords[s] Then If Not aDefFunc[s] Then diff --git a/app/src/gbs3/.src/Reader.class b/app/src/gbs3/.src/Reader.class index bde912f3f..da29c3890 100644 --- a/app/src/gbs3/.src/Reader.class +++ b/app/src/gbs3/.src/Reader.class @@ -33,12 +33,12 @@ Private $oContext As Context Private $sEntryPoint As String = "MAIN" 'Defines the default type of entry point for the generated program Private $cBlockTypes As Collection = ["MODULE": ["END", "MODULE"], - "CLASS": ["END", "CLASS"], - "FORM": ["END", "FORM"], - "CONNECTION": ["END", "CONNECTION"], - "WEBFORM": ["END", "WEBFORM"], - "WEBPAGE": ["END", "WEBPAGE"] - ] + "CLASS": ["END", "CLASS"], + "FORM": ["END", "FORM"], + "CONNECTION": ["END", "CONNECTION"], + "WEBFORM": ["END", "WEBFORM"], + "WEBPAGE": ["END", "WEBPAGE"] + ] Private $sCurrentBlock As String = "" Static Public $sScriptFilter As New Collection @@ -100,6 +100,20 @@ Private Sub GetFile(SourceFile As String) As String End Private $cKeywords As Collection = ["PRIVATE": True, "PUBLIC": True, "STATIC": True, "SUB": True, "FUNCTION": True, "PROCEDURE": True, "STRUCT": True, "ENUM": True, "CLASSREF": True] +Private $cFuncDef As Collection = ["SUB": True, "FUNCTION": True, "PROCUDURE": True] +Private $cAllowedInSub As Collection = ["STATIC": True] + +Private Sub IsFunction(Symbols As String[]) As Boolean + Dim Counter As Integer = 0 + For Each s As String In Symbols + If counter > 2 Then Break + If $cFuncDef[s] Then + Return True + Endif + Inc counter + Next + Return False +End Private Sub TokenizeFile(SourceBuffer As String) Dim SourceList As String[] @@ -107,8 +121,10 @@ Private Sub TokenizeFile(SourceBuffer As String) Dim MainPos As Integer = 1 Dim sline As String Dim bDoFilter As Boolean = ($sScriptFilter.count > 0) - + Dim bInSub As Boolean = False $cKeywords.default = False + $cFuncDef.default = False + $cAllowedInSub.default = False If $oContext.$bPlugin Then $sEntryPoint = "_Call" @@ -170,10 +186,20 @@ Private Sub TokenizeFile(SourceBuffer As String) Goto ContinueRecord Else If Not $bInClass And If $cKeywords[symbols[0]] Then + If Not bInsub Then + If isFunction(Symbols) Then + bInSub = True + Endif + Else If $cAllowedInSub[symbols[0]] Then + aWarnings.Add("Warning : Defined In Sub : " & symbols[0] & ":" & File.name(cIncludeStack.last) & "." & CurrentLineNumber.last & " : " & sline) + Goto ContinueRecord + Endif + aWarnings.Add("Warning : Defined without " & $sEntryPoint & " : " & symbols[0] & ":" & File.name(cIncludeStack.last) & "." & CurrentLineNumber.last & " : " & sline) + bPublicOrSubDef = True GlobalItemPosition.Add(ProgramLines.count) - Goto ContinueRecord + Goto ContinueRecord Else If Not $bInClass And If symbols[0] = "FAST" Then @@ -213,7 +239,15 @@ Private Sub TokenizeFile(SourceBuffer As String) Else CompileError(cIncludeStack.last, CurrentLineNumber.last, "USE statement without component or library definitions") Endif - + + '' Check for the end of a SUB/FUNCTION/Procedure definition + Else If symbols[0] = "END" And symbols.count = 1 Then + If Not bInSub Then + CompileError(cIncludeStack.last, CurrentLineNumber.last, "Syntax error : Unexpected : " & sLine) + Else + bInSub = False + Endif + '' Check for the end of a class definition Else If symbols[0] = "END" And symbols.count = 2 Then