Here are my first PureBasic Syntax Extension. Hope you find it valuable.
Compile this soure as 'StructurePointer.exe' and add it to the Tools Settings.
'StrucurePointer.pb": The Syntax Extension source file for 'StructurePointer as return values:
Code: Select all
;-------------------------------------------------
:
; PureBasic Syntax Extension 1.0 (20130220)
; Supports a new StructurePointer syntax like:
;
; Declare.*<Struct> foo()
; DeclareC.*<Struct> foo()
; DeclareCDLL.*<Struct> foo()
; DeclareDLL.*<Struct> foo()
;
; Procedure.*<Struct> foo()
; ProcedureC.*<Struct> foo()
; ProcedureCDLL.*<Struct> foo()
; ProcedureDLL.*<Struct> foo()
;
; ImportC
; foo.*<Struct>() As "foo@16"
; EndImport
;
; Import
; foo.*<Struct>() As "foo@16"
; EndImport
;
; Prototype.*<Struct> foo()
; PrototypeC.*<Struct> foo()
;
;-------------------------------------------------
NewList aSourceLine.s()
file$ = ProgramParameter(0)
CreateRegularExpression(0, "\.\*.*?\(")
CreateRegularExpression(1, "\.\*.*? ")
If ReadFile(0, file$)
While Eof(0) = 0
AddElement(aSourceLine())
aSourceLine() = ReadString(0)
Wend
CloseFile(0)
EndIf
ResetList(aSourceLine())
If CreateFile(0, file$)
s.s = ""
ForEach aSourceLine()
s = aSourceLine()
If MatchRegularExpression(1, aSourceLine())
s = ReplaceRegularExpression(1, aSourceLine(), ".i ")
ElseIf MatchRegularExpression(0, aSourceLine())
s = ReplaceRegularExpression(0, aSourceLine(), ".i(")
EndIf
WriteStringN(0, s)
Next
CloseFile(0)
EndIf

Please test the new Syntax Extension with this small example too:
Code: Select all
; Small example 4 StructurePointer syntax extension
Structure myBigStructure
a.b
b.s
c.s
d.i
e.l
f.q
EndStructure
;- Declare with StructurePointer syntax:
Declare.*myBigStructure foo()
;- Normal way with pointers
*a.myBigStructure = foo()
Debug *a\a ; 120
Debug *a\b ; myBigStructure
Debug *a\d ; 4321
Debug *a\e ; 999
Debug *a\f ; 1234567890
End
;- Procedure with StructurePointer syntax:
Procedure.*myBigStructure foo()
*a.myBigStructure = AllocateMemory(SizeOf(myBigStructure))
*a\a = 120
*a\b = "myBigStructure"
*a\d = 4321
*a\e = 999
*a\f = 1234567890
ProcedureReturn *a
EndProcedure