Class: JSON5::Lexer
- Inherits:
-
Object
- Object
- JSON5::Lexer
- Defined in:
- lib/json5/lexer.rb
Constant Summary collapse
- SIMPLE_ESCAPES =
{ 0x27 => 0x27, 0x22 => 0x22, 0x5c => 0x5c, 0x62 => 0x08, 0x66 => 0x0c, 0x6e => 0x0a, 0x72 => 0x0d, 0x74 => 0x09, 0x76 => 0x0b }.freeze
- KEYWORDS =
{ "true" => :TRUE, "false" => :FALSE, "null" => :NULL, "Infinity" => :INFINITY, "NaN" => :NAN }.freeze
- PUNCTUATORS =
{ 0x7b => "{", 0x7d => "}", 0x5b => "[", 0x5d => "]", 0x3a => ":", 0x2c => "," }.freeze
- ASCII =
ASCIIClassification::TABLE
- ASCII_WHITESPACE =
ASCIIClassification::WHITESPACE
- ASCII_DIGIT =
ASCIIClassification::DIGIT
- ASCII_HEX_DIGIT =
ASCIIClassification::HEX_DIGIT
- ASCII_IDENTIFIER_START =
ASCIIClassification::IDENTIFIER_START
- ASCII_IDENTIFIER_PART =
ASCIIClassification::IDENTIFIER_PART
- ASCII_QUOTE =
ASCIIClassification::QUOTE
- ASCII_PUNCTUATOR =
ASCIIClassification::PUNCTUATOR
- ASCII_SLASH =
ASCIIClassification::SLASH
- ASCII_BACKSLASH =
ASCIIClassification::BACKSLASH
- ASCII_LINE_TERMINATOR =
ASCIIClassification::LINE_TERMINATOR
- ASCII_STRING_STOP =
ASCII_BACKSLASH | ASCII_LINE_TERMINATOR
- EMPTY_TRIVIA =
[].freeze
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#last_token ⇒ Object
readonly
Returns the value of attribute last_token.
-
#last_token_container ⇒ Object
readonly
Returns the value of attribute last_token_container.
-
#last_token_nesting_depth ⇒ Object
readonly
Returns the value of attribute last_token_nesting_depth.
-
#nesting_depth ⇒ Object
readonly
Returns the value of attribute nesting_depth.
Instance Method Summary collapse
- #current_container ⇒ Object
-
#initialize(input, limits: Limits.default, diagnostics: nil, filename: nil, preserve_trivia: false) ⇒ Lexer
constructor
A new instance of Lexer.
- #next_token ⇒ Object
Constructor Details
#initialize(input, limits: Limits.default, diagnostics: nil, filename: nil, preserve_trivia: false) ⇒ Lexer
Returns a new instance of Lexer.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/json5/lexer.rb', line 48 def initialize(input, limits: Limits.default, diagnostics: nil, filename: nil, preserve_trivia: false) @input = input @limits = limits @diagnostics = DiagnosticSink.build(diagnostics, filename: filename) @filename = filename @preserve_trivia = preserve_trivia @leading_trivia = [] @container_stack = [] @nesting_depth = 0 end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
45 46 47 |
# File 'lib/json5/lexer.rb', line 45 def input @input end |
#last_token ⇒ Object (readonly)
Returns the value of attribute last_token.
45 46 47 |
# File 'lib/json5/lexer.rb', line 45 def last_token @last_token end |
#last_token_container ⇒ Object (readonly)
Returns the value of attribute last_token_container.
45 46 47 |
# File 'lib/json5/lexer.rb', line 45 def last_token_container @last_token_container end |
#last_token_nesting_depth ⇒ Object (readonly)
Returns the value of attribute last_token_nesting_depth.
45 46 47 |
# File 'lib/json5/lexer.rb', line 45 def last_token_nesting_depth @last_token_nesting_depth end |
#nesting_depth ⇒ Object (readonly)
Returns the value of attribute nesting_depth.
45 46 47 |
# File 'lib/json5/lexer.rb', line 45 def nesting_depth @nesting_depth end |
Instance Method Details
#current_container ⇒ Object
120 121 122 123 124 125 |
# File 'lib/json5/lexer.rb', line 120 def current_container case @container_stack.last when 0x7b then "{" when 0x5b then "[" end end |
#next_token ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/json5/lexer.rb', line 59 def next_token skip_trivia @last_token_container = current_container @last_token_nesting_depth = @nesting_depth start_byte = input.index start_line = input.line start_column = input.column kind, value = scan_token finish_token(kind, value, start_byte, start_line, start_column) end |