Method: JSON5::Parser#array

Defined in:
lib/json5/parser.rb

#arrayObject



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/json5/parser.rb', line 325

def array
  # Parse an array value.

  array = []

  if (@ch == '[')
    get_next('[')
    white
    while (@ch) do
      if (@ch == ']')
        get_next(']')
          return array;   # Potentially empty array
        end
      # ES5 allows omitting elements in arrays, e.g. [,] and
      # [,null]. We don't allow this in JSON5.
      if (@ch == ',')
        error("Missing array element")
      else
        array.push(value)
      end
      white
      # If there's no comma after this value, this needs t
      # be the end of the array.
      if (@ch != ',')
        get_next(']')
        return array
      end
      get_next(',')
      white
    end
  end
  error("Bad array")
end