Class: JSONC::Parser::CommentRemover

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonc/parser/comment_remover.rb

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ CommentRemover

Returns a new instance of CommentRemover.



6
7
8
9
10
11
# File 'lib/jsonc/parser/comment_remover.rb', line 6

def initialize(string)
  @string = string
  @index = 0
  @result = String.new
  @state = :normal
end

Instance Method Details

#parse ⇒ Object

Raises:

  • (JSON::ParserError)


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jsonc/parser/comment_remover.rb', line 13

def parse
  while @index < @string.length
    case @state
    when :normal then parse_normal
    when :in_string then parse_string
    when :in_line_comment then parse_line_comment
    when :in_block_comment then parse_block_comment
    end
  end
  raise JSON::ParserError, "Unclosed block comment" if @state == :in_block_comment

  @result
end