I'm simply asking for input on how you'ed parse a text file
what i'm trying to do is reformat the files text in to something that will be loadable in to an AHK Object, so the text format needed is open as long as i can use a ready build AHK Library or function like JSON or XML or whatever makes to loadable.
sample data from a sub part one of the files
1:
Spoiler
2:Code: Select all
AABB m_Bounds
Vector3f m_Center
float x = 0
float y = 0
float z = 0
Vector3f m_Extent
float x = 0
float y = 0
float z = 0
Spoiler
3:Code: Select all
[19]
float data = -1.490116E-08
float m_Override = 0
float m_CloseOpen = 0
float m_InOut = 0
float m_Grab = 0
staticvector m_DoFArray
Array Array
int size = 52
[0]
float data = -0.0007235631
[1]
float data = 0.0008346718
Spoiler
4:Code: Select all
[49]
float data = -0.04953884
OffsetPtr m_Binding
ValueArrayConstant data
vector m_ValueArray
Array Array
int size = 0
float m_StartTime = 0
float m_StopTime = 2.333333
float m_OrientationOffsetY = 0
float m_Level = 0
float m_CycleOffset = 0
float m_AverageAngularSpeed = 0
staticvector m_IndexArray
Array Array
int size = 155
[0]
int data = -1
Spoiler
this is just some of the overall text from the filesCode: Select all
vector m_Events
Array Array
int size = 32
[0]
AnimationEvent data
float time = 0.002333333
string functionName = "OnModifyEnvironmentLighting"
string data = "move_special_0"
PPtr<Object> objectReferenceParameter
int m_FileID = 0
SInt64 m_PathID = 0
float floatParameter = 0
int intParameter = 13
int messageOptions = 1
[1]
AnimationEvent data
float time = 0.002333333
string functionName = "OnPlayParticle"
string data = "move_special_0"
PPtr<Object> objectReferenceParameter
int m_FileID = 0
SInt64 m_PathID = 0
float floatParameter = 0
int intParameter = 6
int messageOptions = 1
the white space is tabs in the files not spaces
hope you can find a simple way to do it
example of one of my tests
Spoiler
Code: Select all
#SingleInstance force
#Include JSON.ahk
f3::
var =
(
bool m_Legacy = False
bool m_Compressed = False
bool m_UseHighQualityCurve = False
vector m_RotationCurves
Array Array
int size = 0
vector m_CompressedRotationCurves
Array Array
int size = 0
vector m_EulerCurves
Array Array
int size = 0
vector m_PositionCurves
Array Array
int size = 0
vector m_ScaleCurves
Array Array
int size = 0
vector m_FloatCurves
Array Array
int size = 0
vector m_PPtrCurves
Array Array
int size = 0
float m_SampleRate = 30
int m_WrapMode = 0
AABB m_Bounds
Vector3f m_Center
float x = 0
float y = 0
float z = 0
Vector3f m_Extent
float x = 0
float y = 0
float z = 0
vector m_Events
Array Array
int size = 32
[0]
AnimationEvent data
float time = 0.002333333
string functionName = "OnModifyEnvironmentLighting"
string data = "move_special_0"
PPtr<Object> objectReferenceParameter
int m_FileID = 0
SInt64 m_PathID = 0
float floatParameter = 0
int intParameter = 13
int messageOptions = 1
[1]
AnimationEvent data
float time = 0.002333333
string functionName = "OnPlayParticle"
string data = "move_special_0"
PPtr<Object> objectReferenceParameter
int m_FileID = 0
SInt64 m_PathID = 0
float floatParameter = 0
int intParameter = 6
int messageOptions = 1
)
new_json_format := "{"
first:=true
number_of_spaces_pr_brace := 1
last_obj_level:= 0
Loop, parse, var, `n, `r
{
if RegExMatch(A_LoopField, "Array", match)
continue
if RegExMatch(A_LoopField, "\[(\d+)\]", match)
{
new_json_format .= ",{"
continue
}
if RegExMatch(A_LoopField, "^(\s*)", match)
{
;~ ;msgbox % strlen(match1)
starts_with_white_space := true
if (strlen(match1) > Last_amount_of_whitespace)
{
if (first)
{
first :=false
new_json_format .= "{"
}
else
new_json_format .= ":{"
}
else if (strlen(match1) = Last_amount_of_whitespace)
{
new_json_format .= ","
}
else if (strlen(match1) < Last_amount_of_whitespace)
{
;~ ;msgbox % ((Last_amount_of_whitespace-strlen(match1))/number_of_spaces_pr_brace)
loop % ((Last_amount_of_whitespace-strlen(match1))/number_of_spaces_pr_brace)
new_json_format .= "}"
new_json_format .= ","
}
Last_amount_of_whitespace := strlen(match1)
is_sub_array := false
}
else
{
starts_with_white_space := false
if (Last_amount_of_whitespace != 0)
{
loop % (Last_amount_of_whitespace/number_of_spaces_pr_brace)
new_json_format .= "}"
new_json_format .= ","
Last_amount_of_whitespace := 0
}
}
if instr(A_LoopField, "=")
{
if RegExMatch(A_LoopField, "\s(\S*)\s=\s(\S*)$", match)
{
;~ ;MsgBox % "1:" match1 "`n2:" match2
new_json_format .= Chr(34) . match1 . Chr(34) . ":"
If (match2+0) ; only evaluates to true if userinput is a number
new_json_format .= match2
else if instr(match2, chr(34))
new_json_format .= match2
else
new_json_format .= Chr(34) . match2 . Chr(34)
}
}
else
if RegExMatch(A_LoopField, "\s(\S*)$", match)
{
new_json_format .= Chr(34) . match1 . Chr(34)
}
pre_line := A_LoopField
}
new_json_format .= "}"
msgbox % new_json_format
return