Module: Cucumber::Parser::TreetopExt

Included in:
Treetop::Runtime::CompiledParser
Defined in:
lib/cucumber/parser/treetop_ext.rb

Constant Summary collapse

FILE_LINE_PATTERN =
/^([\w\W]*?):([\d:]+)$/

Instance Method Summary collapse

Instance Method Details

#parse_file(file) ⇒ Object

Parses a file and returns a Cucumber::Ast



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cucumber/parser/treetop_ext.rb', line 19

def parse_file(file)
  _, path, lines = *FILE_LINE_PATTERN.match(file)
  if path
    lines = lines.split(':').map { |line| line.to_i }
  else
    path = file
    lines = []
  end

  loader = lambda { |io| parse_or_fail(io.read, path) }
  feature = if path =~ /^http/
    require 'open-uri'
    open(path, &loader)
  else
    File.open(path, Cucumber.file_mode('r'), &loader) 
  end
  feature.lines = lines
  feature
end