Module: Cucumber::Parser::TreetopExt
- Included in:
- Treetop::Runtime::CompiledParser
- Defined in:
- lib/cucumber/parser/treetop_ext.rb
Constant Summary collapse
- FILE_COLON_LINE_PATTERN =
/^([\w\W]*?):([\d:]+)$/
Instance Method Summary collapse
-
#parse_file(file, options) ⇒ Object
Parses a file and returns a Cucumber::Ast.
- #parse_or_fail(string, filter = nil, file = nil, line_offset = 0) ⇒ Object
Instance Method Details
#parse_file(file, options) ⇒ Object
Parses a file and returns a Cucumber::Ast
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cucumber/parser/treetop_ext.rb', line 59 def parse_file(file, ) _, path, lines = *FILE_COLON_LINE_PATTERN.match(file) if path lines = lines.split(':').map { |line| line.to_i } else path = file end filter = Filter.new(lines, ) loader = lambda { |io| parse_or_fail(io.read, filter, path) } feature = if path =~ /^http/ require 'open-uri' open(path, &loader) else File.open(path, Cucumber.file_mode('r'), &loader) end feature end |
#parse_or_fail(string, filter = nil, file = nil, line_offset = 0) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cucumber/parser/treetop_ext.rb', line 78 def parse_or_fail(string, filter=nil, file=nil, line_offset=0) parse_tree = parse(string) if parse_tree.nil? raise Cucumber::Parser::SyntaxError.new(self, file, line_offset) else ast = parse_tree.build(filter) # may return nil if it doesn't match filter. ast.file = file unless ast.nil? ast end end |