for anyone watching something I’ve been tinkering with
a converter that uses a full grammar for Xojo (that I’ve by hand verified & verified by testing it without about 500 actual code examples from Xojo)
it took this code (in a plain text Xojo text project file)
#tag Class
Protected Class CComputedProperty
Inherits CProperty
#tag Method, Flags = &h0
Sub Constructor(declLine as string, stream as ProperTextInputStream)
// oddly Xojo write a computed wit hte property def LAST not first
// like
// #tag ComputedProperty, Flags = &h0
// #tag Setter
// Set
// // setter
// End Set
// #tag EndSetter
// SetOnly19 As Integer
// #tag EndComputedProperty
Dim mSourceLines() as string
Try
ParseDeclaration(declLine)
Dim inNote As Boolean
Do
Dim line As String = stream.readline()
If line.Matches("^\s*#tag\s+EndComputedProperty") = StringExtensions.MatchPositions.AtStart Then
Exit
Elseif line.Matches("^\s*#tag\s+Getter") = StringExtensions.MatchPositions.AtStart Then
ReadGetter(line, stream)
Elseif line.Matches("^\s*#tag\s+Setter") = StringExtensions.MatchPositions.AtStart Then
ReadSetter(line, stream)
Elseif line.Trim = "#tag Note" Then
// properties can contain "notes"
inNote = True
Continue
Elseif line.trim = "#tag EndNote" Then
inNote = False
Else
mSourceLines.Append line
End If
Loop Until stream.EndOfFile
While mSourceLines(0).Trim = ""
mSourceLines.RemoveAt 0
Wend
debug.Assert mSourceLines.Count = 1, CurrentMethodName + " got incorrect # of lines for event definition"
Dim scope As String
Dim isShared As Boolean
Dim propName As String
Dim type As String
Dim optionalDefault As String
If LanguageUtils.CrackPropertyDeclaration(mSourceLines(0), scope, isshared, propName, type, optionalDefault) = False Then
Break
End If
Self.mScope = scope
Self.mIsShared = isshared
Self.Name = propName
Self.mType = type
Self.mOptionalDefault = optionalDefault
Catch
Break
End Try
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub ParseDeclaration(declLine as string)
// #tag ComputedProperty, Flags = &h0, CompatibilityFlags = (TargetConsole and (Target32Bit or Target64Bit)) or (TargetDesktop and (Target32Bit or Target64Bit)) or (TargetIOS and (Target64Bit))
Try
Dim tokens() As String = LanguageUtils.TokenizeLine(declLine, False)
If tokens.Ubound < 0 Then
Return
End If
If tokens(0) <> "#tag" Then
Break
End If
tokens.RemoveAt 0
If tokens(0) <> "ComputedProperty" Then
Break
End If
tokens.RemoveAt 0
If tokens.count = 0 Then
Return
End If
If tokens(0) <> "," Then
Break
End If
tokens.RemoveAt 0
If tokens.Count <= 0 Then
Return
End If
ParseFlags(tokens)
ParseCompatFlags(tokens)
ParseDescription(tokens)
Catch
Break
End Try
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub ParseGetterDeclaration(getterDecl as string)
// there actually isnt anything to do here !
// Break
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub ParseSetterDeclaration(setterDecl as string)
// there actually isnt anything to do here !
// Break
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub ReadGetter(declLine as string, stream as ProperTextInputStream)
Try
ParseGetterDeclaration(declLine)
Do
Dim line As String = stream.readline()
If line.Matches("^\s*#tag\s+EndComputedProperty") = StringExtensions.MatchPositions.AtStart Then
Exit
Elseif line.Matches("^\s*#tag\s+EndGetter") = StringExtensions.MatchPositions.AtStart Then
Exit
Elseif line.Matches("^\s*#tag\s+Setter") = StringExtensions.MatchPositions.AtStart Then
Exit
Elseif line.Matches("^\s*#tag\s+EndSetter") = StringExtensions.MatchPositions.AtStart Then
Exit
Else
mGetterLines.Append line
End If
Loop Until stream.EndOfFile
Catch
Break
End Try
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub ReadSetter(declLine as string, stream as ProperTextInputStream)
Try
ParseGetterDeclaration(declLine)
Do
Dim line As String = stream.readline()
If line.Matches("^\s*#tag\s+EndComputedProperty") = StringExtensions.MatchPositions.AtStart Then
Exit
Elseif line.Matches("^\s*#tag\s+EndSetter") = StringExtensions.MatchPositions.AtStart Then
Exit
Elseif line.Matches("^\s*#tag\s+Getter") = StringExtensions.MatchPositions.AtStart Then
Exit
Elseif line.Matches("^\s*#tag\s+EndGetter") = StringExtensions.MatchPositions.AtStart Then
Exit
Else
mSetterLines.Append line
End If
Loop Until stream.EndOfFile
Catch
Break
End Try
End Sub
#tag EndMethod
#tag Method, Flags = &h1
Protected Sub WriteTo(tos as ProperTextOutputStream)
Dim parts() As String
parts.Append mScope
If mIsShared Then
parts.Append "Shared"
End If
parts.append "ComputedProperty"
parts.append mName
If mType <> "" Then
parts.append "As " + mType
End If
tos.writeline Join(parts," ")
tos.Indent
If mGetterLines.Count > 0 Then
tos.Writeline "Get() As " + mType
tos.indent
For Each line As String In mGetterLines
tos.Writeline line
Next
tos.Outdent
tos.Writeline "End Get"
End If
If mSetterLines.Count > 0 Then
tos.Writeline "Set(value As " + mType + ")"
tos.indent
For Each line As String In mSetterLines
tos.Writeline line
Next
tos.Outdent
tos.Writeline "End Set"
End If
tos.Outdent
tos.Writeline "End ComputedProperty"
End Sub
#tag EndMethod
#tag Property, Flags = &h1
Protected mGetterLines() As string
#tag EndProperty
#tag Property, Flags = &h1
Protected mSetterLines() As string
#tag EndProperty
#tag ViewBehavior
#tag ViewProperty
Name="Type"
Visible=false
Group="Behavior"
InitialValue=""
Type="String"
EditorType="MultiLineEditor"
#tag EndViewProperty
#tag ViewProperty
Name="ID"
Visible=false
Group="Behavior"
InitialValue=""
Type="Uint64"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InitialValue="-2147483648"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag EndViewBehavior
End Class
#tag EndClass
and converted it to
protected class CComputedProperty : CProperty
{
public void Constructor(string declLine, ProperTextInputStream stream)
{
string
mSourceLines;
try
{
bool inNote;
do
{
string line = stream.readline();
if (line.Matches(“^\s*#tag\s+EndComputedProperty”)=StringExtensions.MatchPositions.AtStart)
{
return;
}
else if (line.Matches(“^\s*#tag\s+Getter”)=StringExtensions.MatchPositions.AtStart)
{
}
else if (line.Matches(“^\s*#tag\s+Setter”)=StringExtensions.MatchPositions.AtStart)
{
}
else if (line.Trim = “#tag Note”)
{
inNote = true;
continue;
}
else if (line.trim = “#tag EndNote”)
{
inNote = false;
}
else
{
}
} while (!(stream.EndOfFile));
while (mSourceLines(0).Trim=“”)
{
}
string scope;
bool isShared;
string propName;
string type;
string optionalDefault;
if (LanguageUtils.CrackPropertyDeclaration(mSourceLines(0),scope,isshared,propName,type,optionalDefault)=False)
{
System.Diagnostics.Debugger.Break();
}
Self.mScope = scope;
Self.mIsShared = isshared;
Self.Name = propName;
Self.mType = type;
Self.mOptionalDefault = optionalDefault;
}
catch
{
System.Diagnostics.Debugger.Break();
}
}
protected void ParseDeclaration(string declLine)
{
try
{
string[] tokens = LanguageUtils.TokenizeLine(declLine,False);
if (tokens.Ubound < 0)
{
return;
}
if (tokens(0)<>"#tag")
{
System.Diagnostics.Debugger.Break();
}
if (tokens(0)<>"ComputedProperty")
{
System.Diagnostics.Debugger.Break();
}
if (tokens.count = 0)
{
return;
}
if (tokens(0)<>",")
{
System.Diagnostics.Debugger.Break();
}
if (tokens.Count <= 0)
{
return;
}
}
catch
{
System.Diagnostics.Debugger.Break();
}
}
protected void ParseGetterDeclaration(string getterDecl)
{
}
protected void ParseSetterDeclaration(string setterDecl)
{
}
protected void ReadGetter(string declLine, ProperTextInputStream stream)
{
try
{
do
{
string line = stream.readline();
if (line.Matches("^\s*#tag\s+EndComputedProperty")=StringExtensions.MatchPositions.AtStart)
{
return;
}
else if (line.Matches("^\s*#tag\s+EndGetter")=StringExtensions.MatchPositions.AtStart)
{
return;
}
else if (line.Matches("^\s*#tag\s+Setter")=StringExtensions.MatchPositions.AtStart)
{
return;
}
else if (line.Matches("^\s*#tag\s+EndSetter")=StringExtensions.MatchPositions.AtStart)
{
return;
}
else
{
}
} while (!(stream.EndOfFile));
}
catch
{
System.Diagnostics.Debugger.Break();
}
}
protected void ReadSetter(string declLine, ProperTextInputStream stream)
{
try
{
do
{
string line = stream.readline();
if (line.Matches("^\s*#tag\s+EndComputedProperty")=StringExtensions.MatchPositions.AtStart)
{
return;
}
else if (line.Matches("^\s*#tag\s+EndSetter")=StringExtensions.MatchPositions.AtStart)
{
return;
}
else if (line.Matches("^\s*#tag\s+Getter")=StringExtensions.MatchPositions.AtStart)
{
return;
}
else if (line.Matches("^\s*#tag\s+EndGetter")=StringExtensions.MatchPositions.AtStart)
{
return;
}
else
{
}
} while (!(stream.EndOfFile));
}
catch
{
System.Diagnostics.Debugger.Break();
}
}
protected void WriteTo(ProperTextOutputStream tos)
{
string[] parts;
if (mIsShared)
{
}
if (mType != "")
{
}
if (mGetterLines.Count > 0)
{
foreach (string line in mGetterLines)
{
}
}
if (mSetterLines.Count > 0)
{
foreach (string line in mSetterLines)
{
}
}
}
}