Skip to content

Instantly share code, notes, and snippets.

@tsukanov-as
Last active August 6, 2018 09:20
Show Gist options
  • Save tsukanov-as/ef91ea05cdeb074be5bf600cac8aa345 to your computer and use it in GitHub Desktop.
Save tsukanov-as/ef91ea05cdeb074be5bf600cac8aa345 to your computer and use it in GitHub Desktop.
Function Parse(Src, Pos = 1)
List = New Array;
Pos = Pos + 1; Chr = Mid(Src, Pos, 1);
If Chr = Chars.LF Then Pos = Pos + 1; Chr = Mid(Src, Pos, 1); EndIf;
Beg = Pos;
While Chr <> "" Do
If Chr = "{" Then
List.Add(Parse(Src, Pos));
Pos = Pos + 1; Chr = Mid(Src, Pos, 1);
If Chr = Chars.LF Then Pos = Pos + 1; Chr = Mid(Src, Pos, 1); EndIf;
Beg = Pos;
ElsIf Chr = "," Then
If Beg < Pos Then
List.Add(Mid(Src, Beg, Pos - Beg));
EndIf;
Pos = Pos + 1; Chr = Mid(Src, Pos, 1);
If Chr = Chars.LF Then Pos = Pos + 1; Chr = Mid(Src, Pos, 1); EndIf;
Beg = Pos;
ElsIf Chr = "}" Then
If Beg < Pos Then
List.Add(Mid(Src, Beg, Pos - Beg));
EndIf;
Break;
ElsIf Chr = """" Then
While Chr = """" Do
Pos = Pos + 1; While Mid(Src, Pos, 1) <> """" Do Pos = Pos + 1; EndDo;
Pos = Pos + 1; Chr = Mid(Src, Pos, 1);
EndDo;
Else
Pos = Pos + 1; Chr = Mid(Src, Pos, 1);
EndIf;
EndDo;
Return List;
EndFunction // Parse()
res = Parse(src);
JSONWriter = New JSONWriter;
JSONWriter.SetString(New JSONWriterSettings(, Chars.Tab));
WriteJSON(JSONWriter, res);
Result.SetText(JSONWriter.Close());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment