File: regexp.rb

package info (click to toggle)
ruby-unparser 0.6.13-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 936 kB
  • sloc: ruby: 7,691; sh: 6; makefile: 4
file content (35 lines) | stat: -rw-r--r-- 704 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

module Unparser
  class Emitter
    # Emitter for regexp literals
    class Regexp < self
      handle :regexp

      define_group(:body, 0..-2)

    private

      def dispatch
        parentheses('/', '/') do
          body.each(&method(:emit_body))
        end
        emit_options
      end

      def emit_options
        write(children.last.children.join)
      end

      def emit_body(node)
        if n_begin?(node)
          write('#{')
          node.children.each(&method(:visit))
          write('}')
        else
          buffer.append_without_prefix(node.children.first.gsub('/', '\/'))
        end
      end
    end # Regexp
  end # Emitter
end # Unparser