Skip to content

Commit 3d3b786

Browse files
Revert "Add support for large JSON documents (> Int32::MAX) (#16144)" (#16202)
This reverts commit c4b8bbf.
1 parent c4b8bbf commit 3d3b786

File tree

6 files changed

+18
-93
lines changed

6 files changed

+18
-93
lines changed

src/json.cr

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -120,41 +120,16 @@ module JSON
120120

121121
# Exception thrown on a JSON parse error.
122122
class ParseException < Error
123-
@line_number : Int64
124-
@column_number : Int64
123+
getter line_number : Int32
124+
getter column_number : Int32
125125

126-
def line_number : Int32
127-
@line_number.to_i32
128-
end
129-
130-
def column_number : Int32
131-
@column_number.to_i32
132-
end
133-
134-
@[Experimental]
135-
def line_number_i64 : Int64
136-
@line_number
137-
end
138-
139-
@[Experimental]
140-
def column_number_i64
141-
@column_number
142-
end
143-
144-
def initialize(message, line_number, column_number, cause = nil)
145-
@line_number = line_number.to_i64
146-
@column_number = column_number.to_i64
126+
def initialize(message, @line_number, @column_number, cause = nil)
147127
super "#{message} at line #{@line_number}, column #{@column_number}", cause
148128
end
149129

150130
def location : {Int32, Int32}
151131
{line_number, column_number}
152132
end
153-
154-
@[Experimental]
155-
def location_i64 : {Int64, Int64}
156-
{line_number_i64, column_number_i64}
157-
end
158133
end
159134

160135
# Parses a JSON document as a `JSON::Any`.

src/json/from_json.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ end
138138
} %}
139139
def {{type.id}}.new(pull : JSON::PullParser)
140140
# TODO: use `PullParser#read?` instead
141-
location = pull.location_i64
141+
location = pull.location
142142
value =
143143
{% if type == "UInt64" || type == "UInt128" || type == "Int128" %}
144144
pull.read_raw
@@ -282,7 +282,7 @@ def NamedTuple.new(pull : JSON::PullParser)
282282
{% end %}
283283
{% end %}
284284

285-
location = pull.location_i64
285+
location = pull.location
286286

287287
pull.read_object do |key|
288288
case key
@@ -389,7 +389,7 @@ module Enum::ValueConverter(T)
389389
end
390390

391391
def Union.new(pull : JSON::PullParser)
392-
location = pull.location_i64
392+
location = pull.location
393393

394394
{% begin %}
395395
case pull.kind

src/json/lexer.cr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ abstract class JSON::Lexer
1212
getter token : Token
1313
property skip : Bool
1414

15-
@line_number : Int64
16-
@column_number : Int64
17-
1815
def initialize
1916
@token = Token.new
2017
@line_number = 1

src/json/pull_parser.cr

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class JSON::PullParser
104104
@raw_value = ""
105105
@object_stack = [] of ObjectStackKind
106106
@skip_count = 0
107-
@location = {0_i64, 0_i64}
107+
@location = {0, 0}
108108

109109
next_token
110110
case token.kind
@@ -577,39 +577,19 @@ class JSON::PullParser
577577
end
578578

579579
# Returns the current line number.
580-
@[Experimental]
581-
def line_number_i64 : Int64
580+
def line_number
582581
@location[0]
583582
end
584583

585-
# Returns the current line number.
586-
def line_number : Int32
587-
@location[0].to_i32
588-
end
589-
590-
# Returns the current column number.
591-
@[Experimental]
592-
def column_number_i64
593-
@location[1]
594-
end
595-
596584
# Returns the current column number.
597585
def column_number
598-
@location[1].to_i32
586+
@location[1]
599587
end
600588

601589
# Returns the current location.
602590
#
603591
# The location is a tuple `{line number, column number}`.
604592
def location : Tuple(Int32, Int32)
605-
{line_number, column_number}
606-
end
607-
608-
# Returns the current location.
609-
#
610-
# The location is a tuple `{line number, column number}`.
611-
@[Experimental]
612-
def location_i64 : Tuple(Int64, Int64)
613593
@location
614594
end
615595

@@ -674,12 +654,12 @@ class JSON::PullParser
674654
end
675655

676656
private def next_token
677-
@location = {@lexer.token.line_number_i64, @lexer.token.column_number_i64}
657+
@location = {@lexer.token.line_number, @lexer.token.column_number}
678658
@lexer.next_token
679659
end
680660

681661
private def next_token_expect_object_key
682-
@location = {@lexer.token.line_number_i64, @lexer.token.column_number_i64}
662+
@location = {@lexer.token.line_number, @lexer.token.column_number}
683663
@lexer.next_token_expect_object_key
684664
end
685665

src/json/serialization.cr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,14 @@ module JSON
210210
%found{name} = false
211211
{% end %}
212212

213-
%location = pull.location_i64
213+
%location = pull.location
214214
begin
215215
pull.read_begin_object
216216
rescue exc : ::JSON::ParseException
217217
raise ::JSON::SerializableError.new(exc.message, self.class.to_s, nil, *%location, exc)
218218
end
219219
until pull.kind.end_object?
220-
%key_location = pull.location_i64
220+
%key_location = pull.location
221221
key = pull.read_object_key
222222
case key
223223
{% for name, value in properties %}
@@ -421,7 +421,7 @@ module JSON
421421
{% end %}
422422

423423
def self.new(pull : ::JSON::PullParser)
424-
location = pull.location_i64
424+
location = pull.location
425425

426426
discriminator_value = nil
427427

@@ -486,7 +486,7 @@ module JSON
486486
getter klass : String
487487
getter attribute : String?
488488

489-
def initialize(message : String?, @klass : String, @attribute : String?, line_number, column_number, cause)
489+
def initialize(message : String?, @klass : String, @attribute : String?, line_number : Int32, column_number : Int32, cause)
490490
message = String.build do |io|
491491
io << message
492492
io << "\n parsing "
@@ -497,7 +497,7 @@ module JSON
497497
end
498498
super(message, line_number, column_number, cause)
499499
if cause
500-
@line_number, @column_number = cause.location_i64
500+
@line_number, @column_number = cause.location
501501
end
502502
end
503503
end

src/json/token.cr

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,8 @@ class JSON::Token
3030
raise ParseException.new(exc.message, line_number, column_number)
3131
end
3232

33-
@line_number : Int64
34-
@column_number : Int64
35-
36-
def line_number : Int32
37-
@line_number.to_i32
38-
end
39-
40-
@[Experimental]
41-
def line_number_i64 : Int64
42-
@line_number
43-
end
44-
45-
def line_number=(line_number)
46-
@line_number = line_number.to_i64
47-
end
48-
49-
def column_number : Int32
50-
@column_number.to_i32
51-
end
52-
53-
@[Experimental]
54-
def column_number_i64
55-
@column_number
56-
end
57-
58-
def column_number=(column_number)
59-
@column_number = column_number.to_i64
60-
end
61-
33+
property line_number : Int32
34+
property column_number : Int32
6235
property raw_value : String
6336

6437
def initialize

0 commit comments

Comments
 (0)