Class: Vernacular::AST::ASTParser

Inherits:
Object
  • Object
show all
Defined in:
lib/vernacular/ast/ast_parser.rb

Overview

Handles monkeying around with the ‘parser` gem to get it to handle the various modifications that users can configure `Vernacular` to perform.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(string) ⇒ Object



23
24
25
26
27
28
# File 'lib/vernacular/ast/ast_parser.rb', line 23

def parse(string)
  parser.reset
  buffer = Parser::Base.send(:setup_source_buffer, '(string)', 1,
                             string, @parser.default_encoding)
  parser.parse(buffer)
end

.parserObject



30
31
32
# File 'lib/vernacular/ast/ast_parser.rb', line 30

def parser
  @parser ||= new.parser
end

Instance Method Details

#parserObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vernacular/ast/ast_parser.rb', line 8

def parser
  source = parser_source

  ast_modifiers.each do |modifier|
    modifier.parser_extensions.each do |parser_extension|
      source = extend_parser(source, parser_extension)
    end
  end

  write_parser(source)
  load 'vernacular/ast/parser.rb'
  Parser::Vernacular.new(builder)
end