Browse Source

Change JSON parsing to not change confirmed state

pull/8/head
Anton Tarasenko 4 years ago
parent
commit
65bbfb0e26
  1. 15
      sources/Data/JSON/JArray.uc
  2. 16
      sources/Data/JSON/JObject.uc

15
sources/Data/JSON/JArray.uc

@ -548,12 +548,12 @@ public function JSON Clone()
public function bool ParseIntoSelfWith(Parser parser) public function bool ParseIntoSelfWith(Parser parser)
{ {
local bool parsingSucceeded; local bool parsingSucceeded;
local Parser.ParserState initState; local Parser.ParserState initState, confirmedState;
local JStorageAtom nextAtom; local JStorageAtom nextAtom;
local array<JStorageAtom> parsedAtoms; local array<JStorageAtom> parsedAtoms;
if (parser == none) return false; if (parser == none) return false;
initState = parser.GetCurrentState(); initState = parser.GetCurrentState();
parser.Skip().Match("[").Confirm(); confirmedState = parser.Skip().Match("[").GetCurrentState();
if (!parser.Ok()) if (!parser.Ok())
{ {
parser.RestoreState(initState); parser.RestoreState(initState);
@ -561,18 +561,19 @@ public function bool ParseIntoSelfWith(Parser parser)
} }
while (parser.Ok() && !parser.HasFinished()) while (parser.Ok() && !parser.HasFinished())
{ {
parser.Skip().Confirm(); confirmedState = parser.Skip().GetCurrentState();
if (parser.Match("]").Ok()) { if (parser.Match("]").Ok()) {
parsingSucceeded = true; parsingSucceeded = true;
break; break;
} }
if (parsedAtoms.length > 0 && !parser.R().Match(",").Skip().Ok()) { if ( parsedAtoms.length > 0
&& !parser.RestoreState(confirmedState).Match(",").Skip().Ok()) {
break; break;
} }
else { else if (parser.Ok()) {
parser.Confirm(); confirmedState = parser.GetCurrentState();
} }
nextAtom = ParseAtom(parser.R()); nextAtom = ParseAtom(parser.RestoreState(confirmedState));
if (nextAtom.type == JSON_Undefined) { if (nextAtom.type == JSON_Undefined) {
break; break;
} }

16
sources/Data/JSON/JObject.uc

@ -537,12 +537,12 @@ public function JSON Clone()
public function bool ParseIntoSelfWith(Parser parser) public function bool ParseIntoSelfWith(Parser parser)
{ {
local bool parsingSucceeded; local bool parsingSucceeded;
local Parser.ParserState initState; local Parser.ParserState initState, confirmedState;
local JProperty nextProperty; local JProperty nextProperty;
local array<JProperty> parsedProperties; local array<JProperty> parsedProperties;
if (parser == none) return false; if (parser == none) return false;
initState = parser.GetCurrentState(); initState = parser.GetCurrentState();
parser.Skip().Match("{").Confirm(); confirmedState = parser.Skip().Match("{").GetCurrentState();
if (!parser.Ok()) if (!parser.Ok())
{ {
parser.RestoreState(initState); parser.RestoreState(initState);
@ -550,19 +550,21 @@ public function bool ParseIntoSelfWith(Parser parser)
} }
while (parser.Ok() && !parser.HasFinished()) while (parser.Ok() && !parser.HasFinished())
{ {
parser.Skip().Confirm(); confirmedState = parser.Skip().GetCurrentState();
if (parser.Match("}").Ok()) if (parser.Match("}").Ok())
{ {
parsingSucceeded = true; parsingSucceeded = true;
break; break;
} }
if (parsedProperties.length > 0 && !parser.R().Match(",").Skip().Ok()) { if ( parsedProperties.length > 0
&& !parser.RestoreState(confirmedState).Match(",").Skip().Ok()) {
break; break;
} }
else { else if (parser.Ok()) {
parser.Confirm(); confirmedState = parser.GetCurrentState();
} }
parser.R().Skip().MStringLiteral(nextProperty.name).Skip().Match(":"); parser.RestoreState(confirmedState).Skip();
parser.MStringLiteral(nextProperty.name).Skip().Match(":");
nextProperty.value = ParseAtom(parser.Skip()); nextProperty.value = ParseAtom(parser.Skip());
if (!parser.Ok() || nextProperty.value.type == JSON_Undefined) { if (!parser.Ok() || nextProperty.value.type == JSON_Undefined) {
break; break;

Loading…
Cancel
Save