Module: Opal::Parser::DefaultConfig

Included in:
WithRubyLexer
Defined in:
opal/lib/opal/parser/default_config.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



18
19
20
21
22
23
24
25
# File 'opal/lib/opal/parser/default_config.rb', line 18

def self.included(klass)
  klass.extend(ClassMethods)
  klass.diagnostics_consumer = ->(diagnostic) do
    if RUBY_ENGINE != 'opal'
      $stderr.puts(diagnostic.render)
    end
  end
end

Instance Method Details

#initializeObject



27
28
29
# File 'opal/lib/opal/parser/default_config.rb', line 27

def initialize(*)
  super(Opal::AST::Builder.new)
end

#parse(source_buffer) ⇒ Object



31
32
33
34
35
36
# File 'opal/lib/opal/parser/default_config.rb', line 31

def parse(source_buffer)
  parsed = super || ::Opal::AST::Node.new(:nil)
  wrapped = ::Opal::AST::Node.new(:top, [parsed])
  rewriten = rewrite(wrapped)
  rewriten
end

#rewrite(node) ⇒ Object



38
39
40
# File 'opal/lib/opal/parser/default_config.rb', line 38

def rewrite(node)
  Opal::Rewriter.new(node).process
end