Skip to content

Commit

Permalink
Fixed issue #113
Browse files Browse the repository at this point in the history
Fixed issue #111
Fixed issue #110
  • Loading branch information
onryldz committed Aug 23, 2017
1 parent 7311ed8 commit 4e60eb8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 17 additions & 13 deletions XSuperJSON.pas
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ interface
TJSONNull = class;
TLexGenerator = class;
TRoute = class;
PPosition = ^TPosition;
TPosition = record
Col: Integer;
Line: Integer;
Expand All @@ -62,8 +63,8 @@ TPosition = record

TJSONSyntaxError = class(Exception)
public
constructor Create(const Msg: String; Pos: TPosition);
constructor CreateFmt(const Msg: String; const Args: array of TVarRec; Pos: TPosition);
constructor Create(const Msg: String; Pos: PPosition);
constructor CreateFmt(const Msg: String; const Args: array of TVarRec; Pos: PPosition);
end;

// ## JSONWriter
Expand Down Expand Up @@ -517,7 +518,7 @@ TLexGenerator = class
FBuffer: TLexBuff;
FEscapeBuff: TLexBuff;
FCurr: PWideChar;
FCurrPos: TPosition;
FCurrPos: PPosition;
FLexem: ILexeme;
FLexG: TLexGrammar;
FEscapeSupport: Boolean;
Expand All @@ -536,6 +537,7 @@ TLexGenerator = class
function CheckKill(LTyp: TLexemType): Boolean; overload;
function CheckKill(LTyp: TLexemTypes): TLexemType; overload;
function Current: ILexeme; inline;
property CurrPos: PPosition read FCurrPos;
end;

TSuperParser = class
Expand Down Expand Up @@ -1179,8 +1181,9 @@ constructor TLexGenerator.Create(LexG: TLexGrammar; ExceptBlock: Boolean);
FEscapeRoute := LexG.EscapeRoute;
FEscapeBuff := TLexBuff.Create;
end;


New(FCurrPos);
FCurrPos.Line := 1;
FCurrPos.Col := 0;
end;

procedure TLexGenerator.CreateLexeme;
Expand All @@ -1202,6 +1205,7 @@ destructor TLexGenerator.Destroy;
FBuffer.Free;
if FEscapeSupport then
FEscapeBuff.Free;
Dispose(FCurrPos);
inherited;
end;

Expand Down Expand Up @@ -1278,7 +1282,7 @@ procedure TLexGenerator.NextLex;
FBuffer.Add(FCurr^);

if Trigger.BF and (FLexem.Pos.Col = 0) then
FLexem.Pos := FCurrPos;
FLexem.Pos := FCurrPos^;

if not Trigger.BK then
begin
Expand Down Expand Up @@ -1391,7 +1395,7 @@ procedure TJSONBuilder.ReadArray(var Val: IJSONAncestor);
until not LGen.CheckKill(ltVirgule);

if not LGen.CheckKill(ltCRight) then
raise TJSONSyntaxError.Create(Err_UnexpectedEndOfInput, LGen.Current.Pos);
raise TJSONSyntaxError.Create(Err_UnexpectedEndOfInput, LGen.CurrPos);
end;

procedure TJSONBuilder.ReadFalse(var Val: IJSONAncestor);
Expand Down Expand Up @@ -1429,13 +1433,13 @@ procedure TJSONBuilder.ReadObject(var Val: IJSONAncestor);
begin
LGen.KillLex;
if not LGen.CheckKill(ltColon) then
raise TJSONSyntaxError.CreateFmt(Err_Expected, [':'], LGen.Current.Pos);
raise TJSONSyntaxError.CreateFmt(Err_Expected, [':'], LGen.CurrPos);
TJSONObject(Val).AddPair(TJSONPair.Create(Name, ReadValue));
end
until not LGen.CheckKill(ltVirgule);

if not LGen.CheckKill(ltBRight) then
raise TJSONSyntaxError.Create(Err_UnexpectedEndOfInput, LGen.Current.Pos);
raise TJSONSyntaxError.Create(Err_UnexpectedEndOfInput, LGen.CurrPos);
end;

procedure TJSONBuilder.ReadString(var Val: IJSONAncestor);
Expand Down Expand Up @@ -1701,13 +1705,13 @@ procedure TJSONPair.SetValue(const Value: IJSONAncestor);

{ TJSONSyntaxError }

constructor TJSONSyntaxError.Create(const Msg: String; Pos: TPosition);
constructor TJSONSyntaxError.Create(const Msg: String; Pos: PPosition);
begin
inherited CreateFmt(Msg + '. (Line: %d Col: %d)', [Pos.Line, Pos.Col]);
end;

constructor TJSONSyntaxError.CreateFmt(const Msg: String; const Args: array of TVarRec;
Pos: TPosition);
Pos: PPosition);
begin
Create( Format(Msg, Args), Pos );
end;
Expand Down Expand Up @@ -1859,15 +1863,15 @@ procedure TJSONInterpreter.CreateExcept(const S: String;
if FExceptionBlock then
Abort
else
raise TJSONSyntaxError.CreateFmt(S, Args, LGen.Current.Pos);
raise TJSONSyntaxError.CreateFmt(S, Args, LGen.CurrPos);
end;

procedure TJSONInterpreter.CreateExcept(const S: String);
begin
if FExceptionBlock then
Abort
else
raise TJSONSyntaxError.Create(S, LGen.Current.Pos);
raise TJSONSyntaxError.Create(S, LGen.CurrPos);
end;

destructor TJSONInterpreter.Destroy;
Expand Down
2 changes: 1 addition & 1 deletion XSuperObject.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3400,7 +3400,7 @@ class function TJSON.SuperObject(Value: TDataSet): ISuperObject;
Rec.D[FieldName] := AsDateTime;
ftWideString:
Rec.S[FieldName] := AsWideString;
ftLargeint:
ftLargeint, ftAutoInc:
Rec.I[FieldName] := AsLargeInt;
ftVariant:
Rec.V[FieldName] := AsVariant;
Expand Down

0 comments on commit 4e60eb8

Please sign in to comment.