Class: RbJSON5::Parser Private
- Inherits:
-
Object
- Object
- RbJSON5::Parser
- Extended by:
- Parslet
- Defined in:
- lib/rb_json5/parser.rb,
lib/rb_json5/parser/misc.rb,
lib/rb_json5/parser/null.rb,
lib/rb_json5/parser/array.rb,
lib/rb_json5/parser/space.rb,
lib/rb_json5/parser/number.rb,
lib/rb_json5/parser/object.rb,
lib/rb_json5/parser/string.rb,
lib/rb_json5/parser/boolean.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
JSON5 parser implementation using Parslet
Parsing process:
- parses a JSON5 string into the intermediate structure by using Parser.parser
- convert the intermediate structure into Ruby objects by using Parser.transform
Defined Under Namespace
Classes: ObjectMember
Constant Summary collapse
- WHITE_SPACE_CODES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
list of character codes of white space
[ "\u0009", "\u000b", "\u000c", "\u0020", "\u00a0", "\ufeff" ].freeze
- IDENTIFIER_START_PATTERNS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
list of patterns for start character of identifier
[ /[$_]/, /\p{Letter}/, /\p{Letter_Number}/ ].freeze
- IDENTIFIER_PART_PATTERNS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
list of patterns for part character of identifier
[ /[\u200c\u200d]/, /\p{Nonspacing_Mark}/, /\p{Spacing_Mark}/, /\p{Decimal_Number}/, /\p{Connector_Punctuation}/, *IDENTIFIER_START_PATTERNS ].freeze
- INVALID_CHARACTER_FOR_IDENTIFIER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
call back block called when character unescaped from Unicode escape sequence is not allowed for identifier
lambda do |character, sequence| Parslet::Cause.format( sequence.line_cache, sequence.position.bytepos, "#{character.inspect} cannot be used for identifier" ).raise end
Class Method Summary collapse
-
.parser ⇒ Object
private
returns the class to parse a JSON5 string.
-
.transform ⇒ Object
private
returns the class to convert the intermediate structure into Ruby objects.
Instance Method Summary collapse
-
#initialize(root = nil) ⇒ Parser
constructor
private
A new instance of Parser.
-
#parse(string_or_io, symbolize_names = false) ⇒ Object
private
parses a JSON5 string into the Ruby.
Constructor Details
Class Method Details
.parser ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
returns the class to parse a JSON5 string
17 18 19 |
# File 'lib/rb_json5/parser.rb', line 17 def parser @parser ||= Class.new(Parslet::Parser) end |
.transform ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
returns the class to convert the intermediate structure into Ruby objects
22 23 24 |
# File 'lib/rb_json5/parser.rb', line 22 def transform @transform ||= Class.new(Parslet::Transform) end |
Instance Method Details
#parse(string_or_io, symbolize_names = false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
parses a JSON5 string into the Ruby
57 58 59 60 61 62 |
# File 'lib/rb_json5/parser.rb', line 57 def parse(string_or_io, symbolize_names = false) tree = parser.parse(read_json5(string_or_io), reporter: error_reporter) transform.apply(tree, symbolize_names: symbolize_names) rescue Parslet::ParseFailed => e raise ParseError.new(e., e.parse_failure_cause) end |