Merge branch 'scripterupdatesfixes' into 'master'
[Scripter] - Prepare for component and bug fixes See merge request gambas/gambas!235
This commit is contained in:
commit
7ae6634069
37 changed files with 872 additions and 124 deletions
|
@ -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"],["-c","-v","-w","/home/brian/Scripts/testLocalStatic.gbs"],["-c","-v","-w","TestExternStructNoMain.gbs"],["-c","-v","-w","TestExternStructWithMain.gbs"]]
|
||||
CurrentArgumentList=["-c","-v","-w","TestExternStructWithMain.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/TestTestAppIncludes"],["-v","~/Projects/TestTimer"],["-c","-v","-w","~/gbs3testwithclass.gbs"],["-c","-v","-w","/home/brian/Scripts/testLocalStatic.gbs"],["-c","-v","-w","TestExternStructNoMain.gbs"],["-c","-v","-w","TestExternStructWithMain.gbs"]]
|
||||
CurrentArgumentList=["-c","-v","-w","~/Scripts/TestTestAppIncludes"]
|
||||
TabSize=2
|
||||
Translate=1
|
||||
Language=en_US
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
' Gambas module file
|
||||
|
||||
Export
|
||||
|
||||
Public Sub _Call(sPath As String, iLine As Integer, sMessage As String)
|
||||
|
||||
Error.Raise(File.Name(Args[0]) & ": " & sPath & "." & iLine & ": " & sMessage)
|
||||
|
|
|
@ -84,5 +84,7 @@ Public Sub _ResetAll()
|
|||
$bDebug = False
|
||||
$bTrace = False
|
||||
$bTerseListing = False
|
||||
$bPlugin = False
|
||||
$bClassAsStartup = False
|
||||
|
||||
End
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
' Gambas module file
|
||||
|
||||
'' returns the addition to the plugin class file to support plugin information
|
||||
'' adds version property to plugin file to get the actual plugin versio not the calls app version
|
||||
'' adds version property to plugin file to get the actual plugin version not the called app version
|
||||
'' adds all #Script entries as read only properties that were defined in the script
|
||||
|
||||
Public Sub _call() As String
|
||||
|
@ -11,13 +11,27 @@ Public Sub _call() As String
|
|||
Dim InfoDefPart As String = ""
|
||||
|
||||
For Each sEntry As String In ScriptPreProcess.ProjectInfo
|
||||
InfoPropertyPart &= "Property Read " & ScriptPreProcess.ProjectInfo.key & " as string\n"
|
||||
|
||||
InfoDefPart &= "Private $s" & ScriptPreProcess.ProjectInfo.key & " as string = " & Quote(sEntry) & "\n"
|
||||
If ScriptPreProcess.PropertyRW.Exist(ScriptPreProcess.ProjectInfo.key) Then
|
||||
InfoDefPart &= "Private $s" & ScriptPreProcess.ProjectInfo.key & " as variant = " & Quote(sEntry) & "\n"
|
||||
InfoPropertyPart &= "Property " & ScriptPreProcess.ProjectInfo.key & " as variant\n"
|
||||
InfoProgPart &= "Function " & ScriptPreProcess.ProjectInfo.key & "_Write(value as variant)\n"
|
||||
InfoProgPart &= "$s" & ScriptPreProcess.ProjectInfo.key & "= value\n"
|
||||
InfoProgPart &= "end\n"
|
||||
InfoProgPart &= "Function " & ScriptPreProcess.ProjectInfo.key & "_Read() as variant\n"
|
||||
InfoProgPart &= "Return $s" & ScriptPreProcess.ProjectInfo.key & "\n"
|
||||
InfoProgPart &= "end\n"
|
||||
Else
|
||||
InfoPropertyPart &= "Property Read " & ScriptPreProcess.ProjectInfo.key & " as string\n"
|
||||
InfoDefPart &= "Private $s" & ScriptPreProcess.ProjectInfo.key & " as string = " & Quote(sEntry) & "\n"
|
||||
InfoProgPart &= "Function " & ScriptPreProcess.ProjectInfo.key & "_Read() as string\n"
|
||||
InfoProgPart &= "Return $s" & ScriptPreProcess.ProjectInfo.key & "\n"
|
||||
InfoProgPart &= "end\n"
|
||||
Endif
|
||||
|
||||
|
||||
|
||||
|
||||
InfoProgPart &= "Function " & ScriptPreProcess.ProjectInfo.key & "_Read() as string\n"
|
||||
InfoProgPart &= "Return $s" & ScriptPreProcess.ProjectInfo.key & "\n"
|
||||
InfoProgPart &= "end\n"
|
||||
|
||||
Next
|
||||
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
' Gambas class file
|
||||
|
||||
Export
|
||||
|
||||
Public Enum rText, rTokens, rTypes, rPosition
|
||||
|
||||
Public ProgramLines As New String[] ' List of all program lines
|
||||
Public ProgramLines As New String[] ' List of all program lines
|
||||
Public ProgramSymbols As New Variant[] ' List of all tokens
|
||||
Public ProgramTypes As New Variant[] ' List of all
|
||||
Public ProgramTypes As New Variant[] ' List of all
|
||||
Public ProgramPositions As New Variant[] ' Position of token text in each line
|
||||
Public GlobalItemPosition As New Integer[] ' Position of each Globaly define variable
|
||||
Public sSourceFile As String = "" ' The Source File
|
||||
Public sSourceFile As String = "" ' The Source File
|
||||
|
||||
Private CurrentLineNumber As New Integer[] ' Current line number of text in a file
|
||||
Private CurrentLineNumber As New Integer[] ' Current line number of text in a file
|
||||
|
||||
Public CurrentLine As Integer = -1 ' current line being processed
|
||||
Public CurrentToken As Integer = -1 ' we have not gotten first token yet
|
||||
|
@ -41,6 +43,7 @@ Private $cBlockTypes As Collection = ["MODULE": ["END", "MODULE"],
|
|||
]
|
||||
Private $sCurrentBlock As String = ""
|
||||
Static Public $sScriptFilter As New Collection
|
||||
Static Public $sScriptAlias As New Collection
|
||||
|
||||
Public Sub _New(cContext As Context, Optional SourceFile As String = "", Sourceprogram As String = "")
|
||||
Dim SourceBuffer As String
|
||||
|
@ -122,6 +125,9 @@ Private Sub TokenizeFile(SourceBuffer As String)
|
|||
Dim MainPos As Integer = 1
|
||||
Dim sline As String
|
||||
Dim bDoFilter As Boolean = ($sScriptFilter.count > 0)
|
||||
Dim bDoAlias As Boolean = ($sScriptAlias.count > 0)
|
||||
Dim bDoLinePreProcess As Boolean = (ScriptSetPreProcessCallBack.HasLinePreProcess())
|
||||
|
||||
Dim bInSub As Boolean = False
|
||||
$cKeywords.default = False
|
||||
$cFuncDef.default = False
|
||||
|
@ -132,17 +138,58 @@ Private Sub TokenizeFile(SourceBuffer As String)
|
|||
CurrentLineNumber.Push(0)
|
||||
|
||||
SourceList = Split(SourceBuffer, "\n", "", True)
|
||||
For Each sLine As String In SourceList
|
||||
|
||||
If ScriptSetPreProcessCallBack.HasProgramPreProcess() Then
|
||||
SourceList = ScriptApplyProgramCallBacks(SourceList)
|
||||
Endif
|
||||
|
||||
Dim SourceIndex As Integer = 0
|
||||
|
||||
While True
|
||||
|
||||
If SourceIndex > SourceList.max Then
|
||||
Break
|
||||
Endif
|
||||
|
||||
If Not SourceList[SourceIndex] Then
|
||||
Inc CurrentLineNumber.last
|
||||
Inc SourceIndex
|
||||
Continue
|
||||
Endif
|
||||
|
||||
If bDoLinePreProcess Then
|
||||
SourceList[SourceIndex] = ScriptApplyLineCallBacks(SourceList[Sourceindex])
|
||||
Endif
|
||||
|
||||
If bDoAlias Then
|
||||
Dim sLines As String[] = ScriptApplyAlias(SourceList[SourceIndex], $sScriptAlias)
|
||||
SourceList[SourceIndex] = sLines[0]
|
||||
If sLines.count > 1 Then
|
||||
For iInsert As Integer = sLines.max DownTo 1
|
||||
SourceList.insert(sLines, SourceIndex + 1)
|
||||
Next
|
||||
Endif
|
||||
Endif
|
||||
|
||||
sLine = SourceList[SourceIndex]
|
||||
Inc SourceIndex
|
||||
|
||||
Inc CurrentLineNumber.last
|
||||
|
||||
If ScriptSetPreProcessCallBack.HasLinePreProcess() Then
|
||||
sLine = ScriptApplyLineCallBacks(sLine)
|
||||
Endif
|
||||
|
||||
If bDoFilter Then
|
||||
If ScriptKeywordFilter(sLine, $sScriptFilter, CurrentLineNumber.last, cIncludeStack.last) Then 'filter the script if needed True means error
|
||||
CompileError(cIncludeStack.last, CurrentLineNumber.last, "Compile Terminated : " & sLine)
|
||||
CompileError(cIncludeStack.last, CurrentLineNumber.last, "Compile Terminated at :\n " & sLine & "\n ")
|
||||
Endif
|
||||
Endif
|
||||
|
||||
If Left(sLine, 3) = "#!/" Then sLine = "' " & sLine ' eliminate the script header
|
||||
If Left(sLine, 3) = "#!/" Then
|
||||
sLine = "' " & sLine ' eliminate the script header
|
||||
Goto ContinueRecord
|
||||
Endif
|
||||
|
||||
Highlight.Analyze(sLine)
|
||||
|
||||
|
@ -236,13 +283,13 @@ Private Sub TokenizeFile(SourceBuffer As String)
|
|||
Else If symbols[0] = "USE"
|
||||
If symbols.count >= 2 Then
|
||||
ProcessUse(sLine)
|
||||
Continue
|
||||
Continue
|
||||
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
|
||||
Else If Not $bInClass And If symbols[0] = "END" And symbols.count = 1 Then
|
||||
If Not bInSub Then
|
||||
CompileError(cIncludeStack.last, CurrentLineNumber.last, "Syntax error : Unexpected : " & sLine)
|
||||
Else
|
||||
|
@ -307,9 +354,10 @@ Private Sub TokenizeFile(SourceBuffer As String)
|
|||
Else If aTypes.count >= 2 And If aTypes[0] = Highlight.Preprocessor Then
|
||||
If symbols[0] == "#SCRIPT" Then
|
||||
Highlight.Analyze(Right(Trim(sline), -1))
|
||||
ScriptPreProcess(Highlight.symbols, Highlight.types, CurrentLineNumber.last, cIncludeStack.last)
|
||||
ScriptPreProcess(Highlight.symbols, Highlight.types, CurrentLineNumber.last, cIncludeStack.last)
|
||||
sLine = "'" & sLine
|
||||
Goto ContinueRecord
|
||||
|
||||
|
||||
Else If symbols[0] == "#INCLUDE" Then
|
||||
ProcessInclude(symbols, atypes, sDefaultFilePath)
|
||||
|
@ -327,8 +375,9 @@ ContinueRecord:
|
|||
ProgramSymbols.Add(Highlight.symbols)
|
||||
ProgramTypes.Add(Highlight.types)
|
||||
ProgramPositions.Add(Highlight.Positions)
|
||||
|
||||
Next
|
||||
|
||||
'Next
|
||||
Wend
|
||||
|
||||
If BlockNames.count > 0 Or If $bInClass Then
|
||||
If $sCurrentBlock == "class" Then
|
||||
|
@ -340,6 +389,10 @@ ContinueRecord:
|
|||
Endif
|
||||
Endif
|
||||
|
||||
If ScriptSetPostProcessCallBack.HasCallBacks() Then
|
||||
ScriptApplyPostProgCallBacks(ProgramLines)
|
||||
Endif
|
||||
|
||||
CurrentLineNumber.Pop()
|
||||
End
|
||||
|
||||
|
|
139
app/src/gbs3/.src/ScriptApplyAlias.module
Normal file
139
app/src/gbs3/.src/ScriptApplyAlias.module
Normal file
|
@ -0,0 +1,139 @@
|
|||
' Gambas module file
|
||||
|
||||
Export
|
||||
|
||||
Class Regexp
|
||||
|
||||
Public Sub _Call(Data As String, aliaslist As Collection) As String[]
|
||||
Dim MyReg As New Regexp
|
||||
Dim MyParams As New String[20]
|
||||
|
||||
Dim s As Variant
|
||||
Dim used As New String[]
|
||||
Dim MyParmsDummy As New String[20] ' Appended to ensure there are enough parameters
|
||||
Dim ReadQueue As New String[]
|
||||
|
||||
DoAliasAgain:
|
||||
|
||||
For Each s In aliaslist
|
||||
Dim akey As String = aliaslist.key
|
||||
akey = Replace(akey, "?", "\\?") ' escape special regex characters
|
||||
akey = Replace(akey, "$", "\\$") ' This too
|
||||
|
||||
If Not used.Exist(akey) Then
|
||||
|
||||
If InStr(aKey, "()") > 0 Then
|
||||
MyReg.compile("^" & Left(aKey, -2) & "([(].*[)])", (RegExp.MultiLine Or RegExp.Caseless))
|
||||
MyReg.Exec(data)
|
||||
If MyReg.Count > 0 Then
|
||||
'Print MyReg[0].text
|
||||
Dim params As New String[]
|
||||
Dim BreakPos As Integer = InStr(MyReg[0].text, "(")
|
||||
Params.Add(Left(MyReg[0].text, BreakPos - 1)) ' add the alias name
|
||||
Dim Parameters As String = Mid(MyReg[0].text, BreakPos + 1, MyReg[0].text.len - BreakPos - 1)
|
||||
'Params.Insert(Parser(Parameters, AliasParms))
|
||||
Params.Insert(Parser(Parameters))
|
||||
MyParams = New String[]
|
||||
For i As Integer = 1 To IIf(params.count - 1 > 20, 19, params.max)
|
||||
If Params[i] = "," Then Continue
|
||||
MyParams.Add(IIf(params[i][0] = "'", Mid(params[i], 2, params[i].len - 2), Params[i]))
|
||||
Next
|
||||
MyParams.Insert(MyParmsDummy)
|
||||
data = Replace(data, MyReg[0].text, Subst(s & " ", MyParams[0], MyParams[1], MyParams[2], MyParams[3], MyParams[4], MyParams[5], MyParams[6], MyParams[7], MyParams[8], MyParams[9], MyParams[10], MyParams[11], MyParams[12], MyParams[13], MyParams[14], MyParams[15], MyParams[16], MyParams[17], MyParams[18], MyParams[19]), RegExp.Caseless)
|
||||
used.Add(aliaslist.key)
|
||||
Goto DoAliasAgain
|
||||
Endif
|
||||
|
||||
Else If aliaslist.key == Trim(data) Then
|
||||
data = s & " "
|
||||
used.Add(aliaslist.key)
|
||||
Goto DoAliasAgain
|
||||
|
||||
Else If RegExp.Match(data, "^" & akey & "[ <>|!&\n\t]", RegExp.Caseless) Then
|
||||
data = RegExp.replace(data, "^" & aKey & "[ <>|!&\n\t]", s & " ", RegExp.Caseless)
|
||||
used.Add(aliaslist.key)
|
||||
Goto DoAliasAgain
|
||||
|
||||
Else If RegExp.Match(data, "[ !|><&]" & akey & "[ <>|!&\n\t]", RegExp.Caseless) Then
|
||||
data = RegExp.replace(data, "[^!| ]" & aKey & "[ <>|!&\n\t]", s & " ", RegExp.Caseless)
|
||||
used.Add(akey)
|
||||
Goto DoAliasAgain
|
||||
Endif
|
||||
Endif
|
||||
Next
|
||||
|
||||
If InStr(data, ":") <> 0 Then
|
||||
used = Split(data, ":", "\"\"", True, True)
|
||||
For i = 0 To used.Max
|
||||
ReadQueue.add(used[i], 0)
|
||||
Next
|
||||
Else
|
||||
ReadQueue.Add(data, 0)
|
||||
Endif
|
||||
|
||||
Return readQueue
|
||||
|
||||
Catch
|
||||
|
||||
Dim errortext As String
|
||||
errortext = Error.where & ":" & Error.text
|
||||
Error.Propagate()
|
||||
End
|
||||
|
||||
Private AliasParms As String[] = ["\"['(", "\"]')"]
|
||||
|
||||
Sub Parser(Parameter As String) As String[]
|
||||
Dim Result As New String[]
|
||||
Dim ParmStart As Integer = 0
|
||||
Dim ParmLen As Integer = 0
|
||||
|
||||
While ParmStart < Parameter.Len
|
||||
ParmLen = GetField(Parameter, ParmStart)
|
||||
Result.Push(Mid(Parameter, ParmStart + 1, ParmLen))
|
||||
ParmStart += ParmLen + 1
|
||||
Wend
|
||||
|
||||
Return Result
|
||||
|
||||
End
|
||||
|
||||
Sub GetField(Source As String, Start As Integer) As Integer
|
||||
Dim CurrentIndex As Integer = start
|
||||
Dim BracketStart As Integer = 0
|
||||
While CurrentIndex < Source.len And Source[CurrentIndex] <> ","
|
||||
BracketStart = InStr(AliasParms[0], Source[CurrentIndex])
|
||||
If BracketStart > 0 Then
|
||||
Inc CurrentIndex
|
||||
CurrentIndex += skip(Source, CurrentIndex, AliasParms[1][BracketStart - 1])
|
||||
Else
|
||||
Inc CurrentIndex
|
||||
Endif
|
||||
Wend
|
||||
|
||||
Return CurrentIndex - Start
|
||||
|
||||
End
|
||||
|
||||
|
||||
Sub skip(Src As String, index As Integer, terminator As String) As Integer
|
||||
|
||||
Dim TotalCars As Integer = 1 ' 0 points to opening escape
|
||||
Dim Pos As Integer = index + 1
|
||||
Dim BracketStart As Integer = 0
|
||||
Dim SkipLen As Integer = 0
|
||||
|
||||
While Src[pos] <> terminator And pos < Src.len
|
||||
BracketStart = InStr(AliasParms[0], Src[Pos])
|
||||
If BracketStart > 0 Then
|
||||
SkipLen = skip(Src, Pos, AliasParms[1][BracketStart - 1])
|
||||
Pos += SkipLen + 1
|
||||
TotalCars += SkipLen
|
||||
Else
|
||||
Inc TotalCars
|
||||
Inc Pos
|
||||
Endif
|
||||
Wend
|
||||
Return TotalCars + 1
|
||||
End
|
||||
|
||||
|
19
app/src/gbs3/.src/ScriptApplyLineCallBacks.module
Normal file
19
app/src/gbs3/.src/ScriptApplyLineCallBacks.module
Normal file
|
@ -0,0 +1,19 @@
|
|||
' Gambas module file
|
||||
|
||||
Export
|
||||
|
||||
''' Apply each of the Line level callbacks
|
||||
''' listed in the line Callback table to the provided program
|
||||
|
||||
'' Apply the Line level callbacks
|
||||
Public Sub _call(sLine As String) As String
|
||||
|
||||
If ScriptSetPreProcessCallBack.HasLinePreProcess() Then
|
||||
For Each oPreProc As Object In ScriptSetPreProcessCallBack.PreLineCallBacks
|
||||
sLine = oPreProc.PreProcessLine(sLine)
|
||||
Next
|
||||
Endif
|
||||
|
||||
Return sLine
|
||||
|
||||
End
|
20
app/src/gbs3/.src/ScriptApplyPostProgCallBacks.module
Normal file
20
app/src/gbs3/.src/ScriptApplyPostProgCallBacks.module
Normal file
|
@ -0,0 +1,20 @@
|
|||
' Gambas module file
|
||||
|
||||
Export
|
||||
''' Apply each of the Program level Post process callbacks
|
||||
''' listed in the Post Program Callback table to the provided program
|
||||
''' The progrm source is provided as a string[] array to be processed
|
||||
'''
|
||||
|
||||
'' Apply the Post Process Program level callbacks
|
||||
Public Sub _call(sProgram As String[]) As String[]
|
||||
|
||||
If ScriptSetPostProcessCallBack.HasCallBacks() Then
|
||||
For Each oPreProc As Object In ScriptSetPostProcessCallBack.PostProgramCallBacks
|
||||
sProgram = oPreProc.PostProcessProgram(sProgram)
|
||||
Next
|
||||
Endif
|
||||
|
||||
Return sProgram
|
||||
|
||||
End
|
20
app/src/gbs3/.src/ScriptApplyProgramCallBacks.module
Normal file
20
app/src/gbs3/.src/ScriptApplyProgramCallBacks.module
Normal file
|
@ -0,0 +1,20 @@
|
|||
' Gambas module file
|
||||
|
||||
Export
|
||||
''' Apply each of the program callbacks
|
||||
''' listed in the Program Callback table to the provided program
|
||||
|
||||
'' Apply the Program level callbacks
|
||||
Public Sub _call(sProgram As String[]) As String[]
|
||||
|
||||
If ScriptSetPreProcessCallBack.HasProgramPreProcess() Then
|
||||
For Each oPreProc As Object In ScriptSetPreProcessCallBack.PreProgramCallBacks
|
||||
sProgram = oPreProc.PreProcessProgram(sProgram)
|
||||
Next
|
||||
Endif
|
||||
|
||||
Return sProgram
|
||||
|
||||
End
|
||||
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
' Gambas module file
|
||||
|
||||
Export
|
||||
|
||||
'' Apply the keyword filter to the passed in source line
|
||||
'' This is an initial implentation, should maybe allow some sort of
|
||||
'' call to plugins or such, but for now just a bunch of
|
||||
|
@ -8,18 +10,17 @@
|
|||
'' Therefore never returns unless all is well
|
||||
'' This is a seperate module so as not to load the gb.prc module if not used by the scripter
|
||||
'' This is expensive the first time a plugin script is processed but of course does not
|
||||
'' effect the cached plugins that have be created, as they are not processed
|
||||
|
||||
'' effect the cached plugins that have been created, as they are not processed again
|
||||
Class RegExp
|
||||
Public Sub _Call(sLine As String, KeywordPatternTable As Collection, iLine As Integer, sPath As String) As Boolean
|
||||
|
||||
For Each Pattern As String In KeywordPatternTable
|
||||
Verbose(Subst("Script Apply Filter : &1 > &2::&3", Quote(KeywordPatternTable.key), Quote(Pattern), Quote(sLine)))
|
||||
If RegExp.Match(sLine, Pattern) Then
|
||||
Verbose(Subst("Plugin Match : &1:&2:&3", sPath, iLine, sLine))
|
||||
warning("Plugin: " & KeywordPatternTable.key, True)
|
||||
Return True
|
||||
If RegExp.Match(sLine, Pattern, RegExp.caseless) Then
|
||||
Verbose(Subst("Script Filter Match : '&1' : '&2' : '&3'", sPath, iLine, sLine))
|
||||
warning("Script Filter: " & KeywordPatternTable.key, True)
|
||||
Return True
|
||||
Endif
|
||||
|
||||
Next
|
||||
|
||||
Return False
|
||||
|
|
|
@ -18,6 +18,7 @@ Public $sLastCompileError As String ' The text of the last eorror message
|
|||
Public Sub _ResetAll()
|
||||
|
||||
$oContext._ResetAll()
|
||||
ScriptPreProcess.reset()
|
||||
$aAppArgs.Clear()
|
||||
$sPath = ""
|
||||
$sPrjPath = ""
|
||||
|
@ -256,9 +257,11 @@ lExecuteProject:
|
|||
Next
|
||||
|
||||
$sArchivePath = sCacheDir &/ "plugins" &/ $sMd5 &/ sFileName
|
||||
Try Mkdir sCacheDir &/ "plugins" &/ $sMd5
|
||||
If Error Then
|
||||
CompileError($sArchivePath, 0, "Unable to create plugin md5 directory:" & Error.text)
|
||||
If Not Exist(sCacheDir &/ "plugins" &/ $sMd5) Then
|
||||
Try Mkdir sCacheDir &/ "plugins" &/ $sMd5
|
||||
If Error Then
|
||||
CompileError($sArchivePath, 0, "Unable to create plugin md5 directory:" & Error.text)
|
||||
Endif
|
||||
Endif
|
||||
Else
|
||||
Try Mkdir sCacheDir &/ $sMd5
|
||||
|
@ -275,6 +278,7 @@ lExecuteProject:
|
|||
Exec ArchiveCmd To sRes
|
||||
|
||||
verbose(sRes)
|
||||
|
||||
If $oContext.$bPlugin Then
|
||||
Try Kill sCacheDir &/ sFileName
|
||||
Try Link $sArchivePath To sCacheDir &/ sFileName
|
||||
|
@ -311,7 +315,7 @@ lExecuteProject:
|
|||
Warning(("Script had Segmentation fault, Code=" & Process.LastValue), True)
|
||||
Endif
|
||||
|
||||
If $oContext.$bTestMode Then
|
||||
If $oContext.$bTestMode Or If $bRunAsPlugin Then
|
||||
Return Process.LastValue
|
||||
Else
|
||||
Quit Process.LastValue
|
||||
|
@ -327,7 +331,8 @@ lExecuteProject:
|
|||
|
||||
Catch
|
||||
|
||||
Error Error.Text; " : "; Error.where ' added for debugging
|
||||
$sLastCompileError = "-2:" & Error.Text & ":" & Error.where
|
||||
Error $sLastCompileError ' added for debugging
|
||||
|
||||
If UseLibComp.HasComponents Then '' added because get circular ref from ccomponent otherwise on exit
|
||||
CComponent.All.Clear()
|
||||
|
@ -339,7 +344,6 @@ Catch
|
|||
Quit -2
|
||||
Endif
|
||||
|
||||
|
||||
End With
|
||||
|
||||
End
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
' Gambas module file
|
||||
|
||||
'' This function will process any compiler options provided
|
||||
'' verify if they are valid and format info to be added to the project file
|
||||
'' Or other #Script commands
|
||||
'' in the script file add the following format
|
||||
Export
|
||||
|
||||
''' This function will process any compiler options provided
|
||||
''' verify if they are valid and format info to be added to the project file
|
||||
''' Or other #Script commands
|
||||
''' in the script file add the following format
|
||||
''' For plugins all Project information entries become
|
||||
''' read properties of the plugin generated class
|
||||
''' This interface may be called from user callbacks to add properties to the propery table
|
||||
|
||||
'' #Script type="Library"
|
||||
'' #Script Vendor="mycompany"
|
||||
'' #SCript Version="1.0.3"
|
||||
|
||||
'' Only for Plugins define any extra properties needed
|
||||
'' #Script Property=MyProp:MyPropValue
|
||||
|
||||
|
||||
Public isLibrary As Boolean = False
|
||||
Public isComponent As Boolean = False
|
||||
|
@ -21,14 +29,16 @@ Public hasOptions As Boolean = False
|
|||
Public PublicFiles As New String[]
|
||||
|
||||
Public ProjectInfo As Collection
|
||||
Public Enum eType, eVersion, eDescription, eMaintainer, eAuthor, eVendor, eLicense, eInstall, eTitle, eName, eNotFound, eIgnored, eStartup, eUseHttpServer, ePublic, eError, eScript
|
||||
Public PropertyRW As New String[]
|
||||
|
||||
Public Enum eType, eVersion, eDescription, eMaintainer, eAuthor, eVendor, eLicense, eInstall, eTitle, eName, eNotFound, eIgnored, eStartup, eUseHttpServer, ePublic, eProperty, eError, eScript
|
||||
' On Goto SYMTYPE, SYMVERSION, SYMDESCRIPTION, SYMMAINTAINER, SYMAUTHORS, SYMVENDOR, SYMLICENSE, SYMINSTALL, SYMTITLE, SYMNAME, SYNOTFOUND, SYMIGNORED, SYMSTARTUP
|
||||
Public KeyWords As Collection = ["TYPE": eType, "VERSION": eVersion, "DESCRIPTION": eDescription,
|
||||
"MAINTAINER": eMaintainer, "AUTHORS": eAuthor, "AUTHOR": eAuthor,
|
||||
"VENDOR": eVendor, "LICENSE": eLicense,
|
||||
"INSTALL": eInstall, "TITLE": eTitle, "NAME": eName, "ERROR": eError,
|
||||
"SCRIPT": eScript, "STARTUP": eStartup, "USEHTTPSERVER": eUseHttpServer,
|
||||
"PUBLIC": ePublic]
|
||||
"PUBLIC": ePublic, "PROPERTY": eProperty]
|
||||
|
||||
Public CompTypes As Collection = ["LIBRARY": 0, "COMPONENT": 1, "PROGRAM": 2]
|
||||
'Private processLine As String[]
|
||||
|
@ -60,7 +70,7 @@ End
|
|||
'' #Script name="xxxx"
|
||||
'' #Script startup="MySub"
|
||||
'' #Script Version ="0.2.3" , ...
|
||||
'' #Script ....
|
||||
'' #Script Property=AppSet:"2.0.0.1"
|
||||
|
||||
Public Sub _call(aSymbols As String[], aTypes As Integer[], LineNumber As Integer, sPath As String)
|
||||
|
||||
|
@ -71,21 +81,22 @@ Public Sub _call(aSymbols As String[], aTypes As Integer[], LineNumber As Intege
|
|||
' If hasOptions Then ' options have already been defined
|
||||
' ScriptMain.CompileError("Options", LineNumber, "Project Options already defined")
|
||||
' Endif
|
||||
|
||||
If aSymbols.count < 2 Then Return
|
||||
|
||||
For i = 1 To aSymbols.Max
|
||||
If aSymbols[i] = "," Then Continue
|
||||
|
||||
KeyIndex = KeyWords[Upper(aSymbols[i])]
|
||||
Inc i
|
||||
If aSymbols[i] <> "=" Or If aTypes[i + 1] <> Highlight.string Then
|
||||
|
||||
If aSymbols[i] <> "=" Or If aTypes[i + 1] <> Highlight.string And aTypes[i + 1] <> Highlight.symbol Then
|
||||
CompileError(sPath, LineNumber, "Invalid #Script PreProcess Command Format :" & aSymbols.Join(" "))
|
||||
Return
|
||||
Endif
|
||||
Inc i
|
||||
|
||||
On KeyIndex Goto SYMTYPE, SYMVERSION, SYMDESCRIPTION, SYMMAINTAINER, SYMAUTHORS, SYMVENDOR, SYMLICENSE, SYMINSTALL, SYMTITLE, SYMNAME, SYNOTFOUND, SYMIGNORED, SYMSTARTUP,
|
||||
SYMUSEHTTPSERVER, SYMPUBLIC
|
||||
SYMUSEHTTPSERVER, SYMPUBLIC, SYMPROPERTY
|
||||
Continue
|
||||
|
||||
SYNOTFOUND:
|
||||
|
@ -165,6 +176,14 @@ Public Sub _call(aSymbols As String[], aTypes As Integer[], LineNumber As Intege
|
|||
PublicFiles.Add(sPublicFilePath)
|
||||
Continue
|
||||
|
||||
SYMPROPERTY: ' Define a Plugin property and value Format #Script Property=Propertyname:value
|
||||
If aSymbols[i + 1] <> ":" Or If aTypes[i + 2] <> Highlight.String Then
|
||||
CompileError(sPath, LineNumber, "Invalid Plugin Property Declaration")
|
||||
Endif
|
||||
PropertyRW.Add(aSymbols[i])
|
||||
ProjectInfo[aSymbols[i]] = UnQuote(aSymbols[i + 2])
|
||||
i += 2
|
||||
|
||||
SYMIGNORED:
|
||||
|
||||
Next
|
||||
|
|
40
app/src/gbs3/.src/ScriptSetAliasTable.module
Normal file
40
app/src/gbs3/.src/ScriptSetAliasTable.module
Normal file
|
@ -0,0 +1,40 @@
|
|||
' Gambas module file
|
||||
|
||||
Export
|
||||
''' This will configure the reader to apply an alias to the input line
|
||||
''' Format is the key is the value to replace and the
|
||||
''' value is the value in the collection
|
||||
''' if an alias is found and the last two characters of the key are
|
||||
''' () then the line is checked for a following open brace
|
||||
''' and every value seperated by a comma, is substitutes into the value string
|
||||
''' Up to a maximum of 20 parameters
|
||||
''' Aliases will only be applied once but will try all until all have been applied
|
||||
''' or there are no more matches
|
||||
'''
|
||||
''' Examples
|
||||
''' "Dog":"MyAnimals.add(\"Dog\")"
|
||||
''' "Animal()":"Animals.add(&1,&2)" in program looks like : Animal("dog","Big")
|
||||
|
||||
''' Any part of the value that is surrounded by {} will be evaluated in the current context
|
||||
''' after all aliases are applied
|
||||
''' Example
|
||||
''' "Dog()":"Animals.add(&1,{quote(str(now))})" In Program dog("Red") expanded to Animals.add("red","2/2/2 19:00:00")
|
||||
|
||||
Public Sub _call(AliasList As Collection)
|
||||
If Not Class.IsLoaded("RegExp") Then
|
||||
Try Component.Load("gb.pcre")
|
||||
If Error Then
|
||||
Warning("Component gb.pcre not found, filter will be ignored")
|
||||
Return
|
||||
Endif
|
||||
Try Class.Load("RegExp")
|
||||
If Error Then
|
||||
Warning("Unable to load regexp, filter will be ignored")
|
||||
Return
|
||||
Endif
|
||||
Endif
|
||||
|
||||
Reader.$sScriptAlias = AliasList
|
||||
|
||||
End
|
||||
|
42
app/src/gbs3/.src/ScriptSetKeywordFilter.module
Normal file
42
app/src/gbs3/.src/ScriptSetKeywordFilter.module
Normal file
|
@ -0,0 +1,42 @@
|
|||
' Gambas module file
|
||||
|
||||
Export
|
||||
'' Allow user to define keyword filter, this will allow to stop certain functions from
|
||||
'' being allowed inside a script file. as need by the pluging user
|
||||
'' This filter set is a set of regular expressions which will be used to match program lines
|
||||
'' Entry would be : "Message if matched":"Regular expression"
|
||||
'' example "File IO not permitted":"*Open* For * Write"
|
||||
'' to prevent opening a file for or input output would look like
|
||||
Public Sub _Call(KeyManagement As Collection)
|
||||
|
||||
If IsNull(KeyManagement) Then
|
||||
Reader.$sScriptFilter.Clear()
|
||||
Return
|
||||
Endif
|
||||
|
||||
If Not Class.IsLoaded("RegExp") Then
|
||||
Try Component.Load("gb.pcre")
|
||||
If Error Then
|
||||
Warning("Component gb.pcre not found, filter will be ignored")
|
||||
Return
|
||||
Endif
|
||||
Try Class.Load("RegExp")
|
||||
If Error Then
|
||||
Warning("Unable to load regexp, filter will be ignored")
|
||||
Return
|
||||
Endif
|
||||
Reader.$sScriptFilter = KeyManagement
|
||||
Else
|
||||
Reader.$sScriptFilter = KeyManagement
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
'' Clear the Script Filters
|
||||
Public Sub Clear()
|
||||
|
||||
Reader.$sScriptFilter.Clear()
|
||||
|
||||
End
|
||||
|
||||
|
40
app/src/gbs3/.src/ScriptSetPostProcessCallBack.module
Normal file
40
app/src/gbs3/.src/ScriptSetPostProcessCallBack.module
Normal file
|
@ -0,0 +1,40 @@
|
|||
' Gambas module file
|
||||
|
||||
Export
|
||||
|
||||
''' Post Process of Program Before it is compiled
|
||||
''' This is called after the program has bee processed
|
||||
''' and before the compiler is called
|
||||
|
||||
Public PostProgramCallBacks As New Object[]
|
||||
|
||||
'' Called to set up the post process table
|
||||
'' each element of the table is called in order in the
|
||||
'' post program process phase.
|
||||
'' Note that successive calls to this SUB
|
||||
'' is cumulative.
|
||||
Public Sub _call(PostProgCallBacks As Object[])
|
||||
|
||||
If PostProgCallBacks.count > 0 Then
|
||||
PostProgramCallBacks.Insert(PostProgCallBacks)
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
|
||||
'' Clears the list of post process callbacks
|
||||
Public Sub clear()
|
||||
|
||||
PostProgramCallBacks.Clear()
|
||||
|
||||
End
|
||||
|
||||
Public Sub HasCallBacks() As Boolean
|
||||
|
||||
If PostProgramCallBacks.count > 0 Then Return True
|
||||
Return False
|
||||
|
||||
End
|
||||
|
||||
|
||||
|
59
app/src/gbs3/.src/ScriptSetPreProcessCallBack.module
Normal file
59
app/src/gbs3/.src/ScriptSetPreProcessCallBack.module
Normal file
|
@ -0,0 +1,59 @@
|
|||
' Gambas module file
|
||||
|
||||
Export
|
||||
''' Pre Process Call Backs are called by the Scripter
|
||||
''' Before the Code Is processed
|
||||
''' Before the line is processed
|
||||
''' The Callback is to an object with the following entry points
|
||||
''' Public sub PreProcessProgram(Program as string[]) string[]
|
||||
''' Public Sub PreProcessLine(sLine as string) as string
|
||||
'''
|
||||
''' It is important to note that the PreProcessing will follow the order found
|
||||
''' in the PreProcessTables
|
||||
|
||||
Public PreProgramCallBacks As New Object[]
|
||||
Public PreLineCallBacks As New Object[]
|
||||
|
||||
'' This function sets the list of pre process call backs
|
||||
'' it has two input lists, one for the program call backs
|
||||
'' and one for the line call backs
|
||||
Public Sub _call(PreProgramCalls As Object[], PreLineCalls As Object[])
|
||||
|
||||
If PreProgramCalls.count > 0 Then
|
||||
PreProgramCallBacks.Insert(PreProgramCalls)
|
||||
Endif
|
||||
|
||||
If PreLineCalls.count > 0 Then
|
||||
PreLineCallBacks.Insert(PreLineCalls)
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
'' This functions Return a boolean true if
|
||||
'' There are Program level pre processes
|
||||
Public Sub HasProgramPreProcess() As Boolean
|
||||
|
||||
If PreProgramCallBacks.count > 0 Then Return True
|
||||
Return False
|
||||
|
||||
End
|
||||
|
||||
'' This functions Return a boolean true if
|
||||
'' There are line level pre processes
|
||||
Public Sub HasLinePreProcess() As Boolean
|
||||
|
||||
If PreLineCallBacks.count > 0 Then Return True
|
||||
Return False
|
||||
|
||||
End
|
||||
|
||||
'' This Function Clears all pre process tables
|
||||
Public Sub Clear()
|
||||
|
||||
PreLineCallBacks.Clear()
|
||||
PreProgramCallBacks.Clear()
|
||||
|
||||
End
|
||||
|
||||
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
' Gambas module file
|
||||
|
||||
Public Filter As Collection = ["Print statement is not allowed in script": ".*Print.*",
|
||||
"Comments not allowed in scripts": ".*'.*$"]
|
||||
|
||||
Public Sub main()
|
||||
Scripter.SetKeyWordFilter(Filter)
|
||||
Dim TestPlugin As Object = Scripter("TestPlugin", ["-w", "-v"], ["NewTestPlugin", "CD", 100, 200])
|
||||
If TestPlugin Then
|
||||
Print TestPlugin("Element 1", 1, 2, "Element 3", "Last Item 4")
|
||||
Else
|
||||
Print "Error in compile of plugin 1:"; Scripter.CompileResult
|
||||
Endif
|
||||
|
||||
Dim TestPlugin2 As Object = Scripter("TestPlugin2", ["-w", "-v"], ["New testPlugin2"])
|
||||
If TestPlugin2 Then
|
||||
Print TestPlugin2()
|
||||
Else
|
||||
Print "Error in compile of plugin 2:"; Scripter.CompileResult
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
|
40
app/src/gbs3/.src/ScripterExecute.class
Normal file
40
app/src/gbs3/.src/ScripterExecute.class
Normal file
|
@ -0,0 +1,40 @@
|
|||
' Gambas class file
|
||||
|
||||
Export
|
||||
|
||||
Static Public $sLastError As String = ""
|
||||
|
||||
|
||||
Static Public Sub _call(ScriptName As String, ScriptSource As String, Optional CompileParameters As String[] = [], ScriptParameters As String[] = []) As Variant
|
||||
|
||||
ScriptMain._ResetAll()
|
||||
|
||||
If Not Component.IsLoaded("gb.eval") Then Component.Load("gb.eval")
|
||||
If Not Class.IsLoaded("ScriptMain") Then Class.load("ScriptMain")
|
||||
If Not Class.IsLoaded("Highlight") Then Class.load("ScriptMain")
|
||||
|
||||
ScriptMain.$bRunAsPlugin = True
|
||||
|
||||
Dim WorkFile As String = Temp(ScriptName)
|
||||
$sLastError = ""
|
||||
Try File.Save(WorkFile, ScriptSource)
|
||||
If Error Then
|
||||
$sLastError = ("Unable to Create Temp Workfile : ") & Error.text
|
||||
CompileError(ScriptName, 0, $sLastError)
|
||||
Endif
|
||||
|
||||
Dim aParms As String[] = CompileParameters
|
||||
aParms.Add("gbs" & System.version, 0)
|
||||
aParms.Push(WorkFile)
|
||||
aParms.insert(ScriptParameters)
|
||||
|
||||
Dim result As Variant = ScriptMain.ScripterMain(aParms)
|
||||
$sLastError = ScriptMain.$sLastCompileError
|
||||
Return result
|
||||
|
||||
Catch
|
||||
$sLastError = Str(-2) & ":" & Error.text & " : " & Error.where
|
||||
ScriptMain._ResetAll()
|
||||
Return $sLastError
|
||||
|
||||
End
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
Export
|
||||
Static Public CompileResult As Integer = 0
|
||||
Static Public CompileError As String = ""
|
||||
Static Public CompileErrorText As String = ""
|
||||
|
||||
|
||||
'' This allows integration of scripter into an application that uses plugins
|
||||
'' the call would be Scripter(MyScript,"-b -c etc these are other parameters")
|
||||
|
@ -10,11 +11,15 @@ Static Public CompileError As String = ""
|
|||
Static Public Sub _call(ScriptPath As String, Optional CompileParameters As String[] = [], PluginNewParameters As Variant[] = Null) As Variant
|
||||
Dim PluginClass As Class
|
||||
Dim PluginObject As Object
|
||||
|
||||
ScriptMain._ResetAll()
|
||||
|
||||
If Not Component.IsLoaded("gb.eval") Then Component.Load("gb.eval")
|
||||
If Not Class.IsLoaded("ScriptMain") Then Class.load("ScriptMain")
|
||||
If Not Class.IsLoaded("Highlight") Then Class.load("ScriptMain")
|
||||
|
||||
ScriptMain.$bRunAsPlugin = True
|
||||
|
||||
Dim aParms As String[] = CompileParameters
|
||||
aParms.Add("gbs" & System.version, 0)
|
||||
aParms.Push("-p")
|
||||
|
@ -22,11 +27,12 @@ Static Public Sub _call(ScriptPath As String, Optional CompileParameters As Stri
|
|||
CompileResult = ScriptMain.ScripterMain(aParms)
|
||||
If CompileResult <> 0 Then
|
||||
Warning("Plugin Compile Failed :" & ScriptMain.$sLastCompileError)
|
||||
CompileError = ScriptMain.$sLastCompileError
|
||||
CompileErrorText = ScriptMain.$sLastCompileError
|
||||
ScriptMain._ResetAll()
|
||||
Return Null
|
||||
Endif
|
||||
Component.Load(ScriptMain.$sExecutable)
|
||||
PlugInClass = Class.Load(ScriptMain.$sStartUpClass)
|
||||
Try Component.Load(ScriptMain.$sExecutable)
|
||||
Try PlugInClass = Class.Load(ScriptMain.$sStartUpClass)
|
||||
If IsNull(PluginNewParameters) Then
|
||||
PlugInObject = PluginClass.New()
|
||||
Else
|
||||
|
@ -36,37 +42,22 @@ Static Public Sub _call(ScriptPath As String, Optional CompileParameters As Stri
|
|||
Return PluginObject
|
||||
End
|
||||
|
||||
'' Allow user to define keyword filter, this will allow to stop certain functions from
|
||||
'' being allowed inside a script file. as need by the pluging user
|
||||
'' This filter set is a set of regular expressions which will be used to match program lines
|
||||
'' Entry would be : "Message if matched":"Regular expression"
|
||||
'' example "File IO not permitted":"*Open* For * Write"
|
||||
'' to prevent opening a file for or input output would look like
|
||||
Static Public Sub SetKeyWordFilter(KeyManagement As Collection)
|
||||
'' Allow a user to provide a string program and build it
|
||||
'' Return the Plugin Object
|
||||
Static Public Sub FromString(PluginName As String, Program As String, Optional CompileParameters As String[] = [], PluginNewParameters As Variant[] = Null) As Variant
|
||||
|
||||
If IsNull(KeyManagement) Then
|
||||
Reader.$sScriptFilter.Clear()
|
||||
Return
|
||||
Endif
|
||||
|
||||
If Not Class.IsLoaded("RegExp") Then
|
||||
Try Component.Load("gb.pcre")
|
||||
If Error Then
|
||||
Warning("Component gb.pcre not found, filter will be ignored")
|
||||
Return
|
||||
Endif
|
||||
Try Class.Load("RegExp")
|
||||
If Error Then
|
||||
Warning("Unable to load regexp, filter will be ignored")
|
||||
Return
|
||||
Endif
|
||||
Reader.$sScriptFilter = KeyManagement
|
||||
Else
|
||||
Reader.$sScriptFilter = KeyManagement
|
||||
Dim WorkFile As String = Temp(PluginName)
|
||||
Try File.Save(WorkFile, Program)
|
||||
If Error Then
|
||||
CompileErrorText = ("Unable to Create Temp Workfile : ") & Error.text
|
||||
CompileError(PluginName, 0, CompileErrorText)
|
||||
Endif
|
||||
|
||||
Return _call(WorkFile, CompileParameters, PluginNewParameters)
|
||||
End
|
||||
|
||||
|
||||
|
||||
''Turn on verbose info during plugin compile
|
||||
Static Public Sub SetVerbose()
|
||||
If Verbose.$bVerboseOn = True Then
|
||||
|
@ -74,4 +65,4 @@ If Verbose.$bVerboseOn = True Then
|
|||
Else
|
||||
Verbose.$bVerboseOn = True
|
||||
Endif
|
||||
End
|
||||
End
|
|
@ -13,6 +13,14 @@ Private ShellScript As String = "#!/bin/bash\n"
|
|||
|
||||
Private $InitDone As Boolean
|
||||
|
||||
Public Sub TeardownTestEnvironment()
|
||||
|
||||
ScriptMain._ResetAll()
|
||||
ScriptMain.$oContext.$bTestmode = False
|
||||
|
||||
End
|
||||
|
||||
|
||||
Public Sub CreateTestEnvironment()
|
||||
|
||||
If $InitDone Then Return
|
||||
|
|
|
@ -10,6 +10,7 @@ End
|
|||
Public Sub _Teardown()
|
||||
|
||||
CComponent.Clear()
|
||||
TSR.TeardownTestEnvironment()
|
||||
|
||||
End
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ End
|
|||
Public Sub _Teardown()
|
||||
|
||||
CComponent.Clear()
|
||||
TSR.TeardownTestEnvironment()
|
||||
|
||||
End
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ End
|
|||
Public Sub _Teardown()
|
||||
|
||||
CComponent.Clear()
|
||||
TSR.TeardownTestEnvironment()
|
||||
|
||||
End
|
||||
|
||||
|
@ -92,6 +93,7 @@ Public Sub FullReadCompileCheck()
|
|||
|
||||
ScriptMain._ResetAll()
|
||||
ScriptMain.$oContext.$bBuildOnly = True
|
||||
ScriptMain.$oContext.$bTestMode = True
|
||||
|
||||
workdir = Temp()
|
||||
Mkdir workdir
|
||||
|
|
42
app/src/gbs3/.src/TestSuite/TeAliases.test
Normal file
42
app/src/gbs3/.src/TestSuite/TeAliases.test
Normal file
|
@ -0,0 +1,42 @@
|
|||
' Gambas test file
|
||||
|
||||
Public AliasList As Collection = New Collection(gb.ignoreCase)
|
||||
|
||||
Public Program As String[] = ["dog",
|
||||
"red(\"apples\",\"orange\")",
|
||||
"grape(frog,\"orange\")",
|
||||
"grape (frog,\"orange\")"]
|
||||
|
||||
Public Results As String[] = ["Big Dogs Are Fun ",
|
||||
"Purple = \"apples\", [\"orange\"] ",
|
||||
"Red_wine = [\"Good\"] ",
|
||||
"Red_wine = [\"Bad\"] (frog,\"orange\")"]
|
||||
|
||||
Public Sub _TearDown()
|
||||
|
||||
|
||||
|
||||
End
|
||||
|
||||
|
||||
|
||||
Public Sub CheckAlias()
|
||||
|
||||
Dim Result As String[]
|
||||
AliasList.add("Big Dogs Are Fun", "dog")
|
||||
AliasList.add("Purple = &1, [&2]", "red()")
|
||||
AliasList.Add("Red_wine", "wine")
|
||||
AliasList.add("Wine = [\"Good\"]", "grape()")
|
||||
AliasList.add("Wine = [\"Bad\"]", "grape")
|
||||
|
||||
|
||||
Dim count As Integer = 0
|
||||
For Each s As String In Program
|
||||
Result = ScriptApplyAlias(s, AliasList)
|
||||
assert.Equals(Result[0], Results[count])
|
||||
Inc count
|
||||
Next
|
||||
|
||||
End
|
||||
|
||||
|
41
app/src/gbs3/.src/TestSuite/TfKeyWordFilter.test
Normal file
41
app/src/gbs3/.src/TestSuite/TfKeyWordFilter.test
Normal file
|
@ -0,0 +1,41 @@
|
|||
' Gambas test file
|
||||
|
||||
''' Test the Keyword filter works correctly in all cases
|
||||
''' Presents a list of program lines to the Filter and
|
||||
''' Calls an error when they fail
|
||||
''' The format ofthe table is
|
||||
''' Key = message to display if matched
|
||||
''' value = the regexp expression to match
|
||||
|
||||
Public Program As String[] = ["Print a, b ,c",
|
||||
"Print #file.out, \"this\"",
|
||||
"Write #file.out,\"This\"",
|
||||
"Read #file.in, buffer"]
|
||||
|
||||
Public Filters As Collection = ["Unable to process read , permission denied": "^Read.*",
|
||||
"No more writing!": "^Write.*",
|
||||
"You can not print to that output sink": "^Print #file.*"]
|
||||
Public Sub _setup()
|
||||
|
||||
'Warning.$bWarningOn = True
|
||||
'Verbose.$bVerboseOn = True
|
||||
|
||||
End
|
||||
|
||||
Public Sub _TearDown()
|
||||
|
||||
'Warning.$bWarningOn = False
|
||||
'Verbose.$bVerboseOn = False
|
||||
ScriptSetKeywordFilter.Clear()
|
||||
End
|
||||
|
||||
|
||||
Public Sub DoFilters()
|
||||
|
||||
Assert.ok(Not ScriptKeywordFilter(Program[0], filters, 10, "TheDummyFIle/now.gbs"), "Found Filtered Value")
|
||||
|
||||
For i As Integer = 1 To Program.max
|
||||
Assert.Ok(ScriptKeywordFilter(Program[i], filters, 10, "TheDummyFIle/now.gbs"), "Found Filtered Value")
|
||||
Next
|
||||
|
||||
End
|
41
app/src/gbs3/.src/TestSuite/TgPluginMode.test
Normal file
41
app/src/gbs3/.src/TestSuite/TgPluginMode.test
Normal file
|
@ -0,0 +1,41 @@
|
|||
' Gambas test file
|
||||
|
||||
Public Filter As Collection = ["Print statement is not allowed in script": ".*Print.*",
|
||||
"Comments not allowed in scripts": ".*'.*$"]
|
||||
|
||||
Public Sub _setup()
|
||||
|
||||
ScriptSetKeyWordFilter(Filter)
|
||||
|
||||
End
|
||||
|
||||
Public Sub _TearDown()
|
||||
|
||||
ScriptSetKeywordFilter.Clear()
|
||||
|
||||
End
|
||||
|
||||
Public Sub DoAPlugin()
|
||||
|
||||
Assert.Equals(ScripterPlugin("TestPlugin", [], ["NewTestPlugin", "CD", 100, 200]), Null, "Bad Compile: Error filter match")
|
||||
|
||||
Dim TestPlugin2 As Object = ScripterPlugin("TestPlugin2", [], ["New testPlugin2"])
|
||||
Assert.Notequals(TestPlugin2, Null, "Good Compile")
|
||||
If TestPlugin2 Then
|
||||
Assert.Equals(TestPlugin2(1, 300, 5, 7, 20, 300, 455), "Sum [1088] AnotherTest : Defined Version = 5.9.3, New Parminfo = \"New testPlugin2\"",
|
||||
"Verify Parameters are Passed correctly and return value is correct")
|
||||
Else
|
||||
Assert.Fail("Script TestPlugin2 is Unable to be compiled")
|
||||
Endif
|
||||
|
||||
Assert.Equals(ScripterExecute("MyTestScript", File.load("TestPlugin3.gbs"), ["-c"], ["Parm1", "Parm2"]), 5, "Execute a valid script")
|
||||
|
||||
Assert.Equals(TestPlugin2.Version, "5.9.3", "Verify that Plugin Properties Where Created - Version")
|
||||
Assert.Equals(TestPlugin2.Name, "AnotherTest", "Verify that Plugin Properties Where Created - Plugin Name")
|
||||
Assert.Equals(TestPlugin2.Title, "Plugin tester Too{str(now)}", "Verify that Plugin Properties Where Created - Title")
|
||||
Assert.Equals(TestPlugin2.Description, "This plugin is a test for the scripter too", "Verify that Plugin Properties Where Created - Description")
|
||||
'Test of special plugin property
|
||||
Assert.Equals(TestPlugin2.MyProp, "Added Plugin Special prop", "Verify that Plugin User Defined Properties Where Created - MyProp")
|
||||
|
||||
|
||||
End
|
94
app/src/gbs3/.src/TestSuite/ThPrePostProcessCallBacks.test
Normal file
94
app/src/gbs3/.src/TestSuite/ThPrePostProcessCallBacks.test
Normal file
|
@ -0,0 +1,94 @@
|
|||
' Gambas test file
|
||||
|
||||
Private TestPlugin As Object
|
||||
Private ResultPlugin As Object
|
||||
Private RealPlugin As Object
|
||||
|
||||
Private OriginalSource As String
|
||||
Private TestSource As String
|
||||
Private TestProgram As String[]
|
||||
Private ResultProgram As String[]
|
||||
|
||||
Public Sub aLoadThePrePostProcessPlugin()
|
||||
|
||||
TestPlugin = ScripterPlugin("PrePostProcessPlugin")
|
||||
Assert.Notequals(TestPlugin, Null, "Good Compile")
|
||||
|
||||
If TestPlugin Then
|
||||
Assert.ok(True, "Pre and Post Process plugin is loaded")
|
||||
Else
|
||||
Assert.Fail("Script Load of pre and post process plugin is Unable to be compiled")
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
Public Sub bSetupPreAndPostTables()
|
||||
If Not TestPlugin Then
|
||||
Assert.Fail("Plugin not generated")
|
||||
Else
|
||||
ScriptSetPreProcessCallBack([TestPlugin], [TestPlugin])
|
||||
ScriptSetPostProcessCallBack([TestPlugin])
|
||||
|
||||
Assert.Ok(ScriptSetPreProcessCallBack.HasProgramPreProcess(), "Preprocess Program Table Correctly loaded")
|
||||
Assert.Ok(ScriptSetPreProcessCallBack.HasLinePreProcess(), "Preprocess Line Table Correctly loaded")
|
||||
Assert.Ok(ScriptSetPostProcessCallBack.HasCallBacks(), "PostProcess Program Table Correctly loaded")
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
Public Sub cProcessAProgram()
|
||||
|
||||
If Not TestPlugin Then
|
||||
Assert.Fail("Plugin not generated")
|
||||
Else
|
||||
TestProgram = Split(File.Load("TestPrePostProcess.gbs"), "\n", "\"\"", True, True)
|
||||
TestSource = TestProgram.Join("\n")
|
||||
Assert.Equals(TestProgram.count, 12, "Verify number of lines loaded")
|
||||
Assert.Equals(ScriptApplyProgramCallBacks(testProgram), testprogram, "Ensure the process was called for pre process program")
|
||||
OriginalSource = testProgram.Join("\n")
|
||||
Assert.Equals(TestProgram.Count, 14, "Verify Callback added two lines")
|
||||
ResultProgram = New String[]
|
||||
For Each sLine As String In TestProgram
|
||||
ResultProgram.Push(ScriptApplyLineCallBacks(sLine))
|
||||
Next
|
||||
Assert.NotEquals(testProgram, ResultProgram, "Verify we made the changes")
|
||||
ScriptApplyPostProgCallBacks(ResultProgram)
|
||||
Assert.Equals(ResultProgram.count, testProgram.count + 5, "Verify we have correct number of lines")
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
Public Sub dBuildTheGeneratedCode()
|
||||
|
||||
ScriptSetPreProcessCallBack.Clear()
|
||||
ScriptSetPostProcessCallBack.clear()
|
||||
|
||||
ResultPlugin = ScripterPlugin.FromString("MyResult", ResultProgram.Join("\n"))
|
||||
Assert.Notequals(ResultPlugin, Null, "Good Build")
|
||||
If resultplugin Then
|
||||
Assert.Equals(ResultPlugin(), OriginalSource, "Verify Generated plugin executes returns original source")
|
||||
Else
|
||||
Assert.Fail("Unable to compile new plugin")
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
Public Sub eDoRealProcess()
|
||||
ScriptSetPreProcessCallBack([TestPlugin], [TestPlugin])
|
||||
ScriptSetPostProcessCallBack([TestPlugin])
|
||||
|
||||
RealPLugin = ScripterPlugin.FromString("OriginalSource", TestSource)
|
||||
|
||||
Assert.Notequals(ResultPlugin, Null, "Good Build")
|
||||
If resultplugin Then
|
||||
Assert.Equals(RealPlugin(), OriginalSource, "Verify Generated plugin executes returns original source")
|
||||
Else
|
||||
Assert.Fail("Unable to compile new plugin")
|
||||
Endif
|
||||
|
||||
ScriptSetPreProcessCallBack.Clear()
|
||||
ScriptSetPostProcessCallBack.clear()
|
||||
|
||||
End
|
||||
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
' Gambas module file
|
||||
|
||||
Export
|
||||
|
||||
Public $bVerboseOn As Boolean = False
|
||||
|
||||
Public Sub _Call(sMsg As String)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
' Gambas module file
|
||||
|
||||
Export
|
||||
|
||||
Public $bWarningOn As Boolean = False
|
||||
|
||||
Public Sub _Call(sMsg As String, Optional bIsError As Boolean = False)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[TestSuites]
|
||||
Count=0
|
||||
TestWith=0
|
||||
Default="TaMServerPages.RunWebPageGeneratedProgram;WebPageProgramCreation,TbCommandLinePrograms.CreateProgramFromCommandLineArgs;ExecuteACommandLineProgram,TcMMainFunctions.CheckLibraryVersions;CheckProcessLibrary;Components;FullReadCompileCheck;FullReadCompileCheckWithMain;ValidFileRebuildCheck,TdGeneralCompile.LazyApps"
|
||||
Default="TgPluginMode.DoAPlugin"
|
||||
|
||||
|
|
20
app/src/gbs3/PrePostProcessPlugin
Normal file
20
app/src/gbs3/PrePostProcessPlugin
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
public sub PreProcessProgram(sProgram as string[]) as string[]
|
||||
sProgram.add("Begin Story",0)
|
||||
sProgram.push("End Story")
|
||||
return sProgram
|
||||
end
|
||||
|
||||
Public sub PostProcessProgram(sProgram as string[]) as string[]
|
||||
sProgram.add("Dim StoryTime as new String[]",0)
|
||||
sProgram.Push("For each sLine as string in StoryTime")
|
||||
sProgram.Push("'Error sLine")
|
||||
sProgram.Push("next")
|
||||
sProgram.Push("Return StoryTime.join(\"\\n\")")
|
||||
return sProgram
|
||||
end
|
||||
|
||||
Public sub PreProcessLine(sLine as string) as string
|
||||
sline = "StoryTime.push(" & quote(sline) & ")"
|
||||
return sLine
|
||||
end
|
|
@ -32,6 +32,7 @@ Public c[20] As Struct Hello
|
|||
|
||||
Sub test()
|
||||
'Static xx As Struct Hello
|
||||
Static Bogon As Integer = 99
|
||||
Print "Test Sub"
|
||||
End
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ Public c[20] As Struct Hello
|
|||
|
||||
Sub test()
|
||||
'Static xx As Struct Hello
|
||||
Static Bogon As Integer = 0
|
||||
Print "Test Sub"
|
||||
End
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#Script Version="8.9.3"
|
||||
#Script Title="Plugin tester"
|
||||
#Script Description="This plugin is a test for the scripter"
|
||||
#Script Property=APPINTERFACE:"20.0.2"
|
||||
|
||||
Public $sParmInfo as string = ""
|
||||
|
||||
|
|
|
@ -1,42 +1,28 @@
|
|||
#Script Version="5.9.3"
|
||||
#Script Name="AnotherTest"
|
||||
#Script Title="Plugin tester Too"
|
||||
#Script Title="Plugin tester Too{str(now)}"
|
||||
#Script Description="This plugin is a test for the scripter too"
|
||||
#Script Property=MyProp:"Added Plugin Special prop"
|
||||
|
||||
Public $sParmInfo as string = ""
|
||||
|
||||
Dim s As String = "Class Info String"
|
||||
Dim i As Variant = s
|
||||
Dim s as string
|
||||
Dim sSum as string= ""
|
||||
|
||||
print "*************************************************"
|
||||
testptr(i)
|
||||
Dim Adder as integer = 0
|
||||
|
||||
for each s as string in param
|
||||
testptr(s)
|
||||
sSum &= s & " , "
|
||||
adder += cinteger(s)
|
||||
next
|
||||
sSum = str(adder)
|
||||
return "Sum ["&sSum&"] " & $sParmInfo
|
||||
|
||||
return "Sum ["&sSum&"]"
|
||||
|
||||
Public Sub testptr(data As Variant)
|
||||
Dim j As Pointer
|
||||
|
||||
j = VarPtr(data)
|
||||
|
||||
Print "Input =", j, data
|
||||
|
||||
print "New Parm was : ";;Quote($sParminfo)
|
||||
|
||||
End
|
||||
|
||||
public sub _new(...)
|
||||
dim parminfo as string = ""
|
||||
|
||||
for each v as variant in param
|
||||
ParmInfo &= quote(cstr(v)) & ","
|
||||
ParmInfo &= quote(cstr(v)) & " "
|
||||
next
|
||||
print "defined Version = "& $sVersion &" Parminfo = ";ParmInfo
|
||||
Print $sName
|
||||
$sParmInfo = parminfo
|
||||
|
||||
$sParmInfo = trim($sName&" : "&"Defined Version = "& $sVersion &", New Parminfo = "&ParmInfo)
|
||||
|
||||
end
|
||||
|
|
12
app/src/gbs3/TestPlugin3.gbs
Normal file
12
app/src/gbs3/TestPlugin3.gbs
Normal file
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/gbs3
|
||||
|
||||
Dim j As Integer = 0
|
||||
Dim Result As String = ""
|
||||
For i As Integer = 0 To 100
|
||||
j += i * 4
|
||||
Next
|
||||
For Each s As String In param
|
||||
Result &= " [" & s & "]"
|
||||
Next
|
||||
|
||||
Quit 5
|
12
app/src/gbs3/TestPrePostProcess.gbs
Normal file
12
app/src/gbs3/TestPrePostProcess.gbs
Normal file
|
@ -0,0 +1,12 @@
|
|||
Yeah
|
||||
I feel you too
|
||||
Feel
|
||||
Those things you Do
|
||||
In your eyes I see a fire that burns
|
||||
To free the you that 's running through
|
||||
Deep inside you know
|
||||
Seeds I plant will grow
|
||||
One day you will see
|
||||
And dare To come down To Me
|
||||
Yeah, come On , come On Now take the chance
|
||||
That 's right, let's dance
|
Loading…
Reference in a new issue