lib/cucumber/parser/treetop_ext.rb in aslakhellesoy-cucumber-0.1.99.23 vs lib/cucumber/parser/treetop_ext.rb in aslakhellesoy-cucumber-0.1.100.1
- old
+ new
@@ -11,15 +11,15 @@
end
module Cucumber
module Parser
module TreetopExt
- FILE_LINE_PATTERN = /^([\w\W]*?):([\d:]+)$/
+ FILE_COLON_LINE_PATTERN = /^([\w\W]*?):([\d:]+)$/
# Parses a file and returns a Cucumber::Ast
def parse_file(file)
- _, path, lines = *FILE_LINE_PATTERN.match(file)
+ _, path, lines = *FILE_COLON_LINE_PATTERN.match(file)
if path
lines = lines.split(':').map { |line| line.to_i }
else
path = file
lines = []
@@ -33,10 +33,21 @@
File.open(path, Cucumber.file_mode('r'), &loader)
end
feature.lines = lines
feature
end
+
+ def parse_or_fail(s, file=nil, line_offset=0)
+ parse_tree = parse(s)
+ if parse_tree.nil?
+ raise Cucumber::Parser::SyntaxError.new(self, file, line_offset)
+ else
+ ast = parse_tree.build
+ ast.file = file
+ ast
+ end
+ end
end
class SyntaxError < StandardError
def initialize(parser, file, line_offset)
tf = parser.terminal_failures
@@ -57,19 +68,8 @@
end
end
class CompiledParser
include Cucumber::Parser::TreetopExt
-
- def parse_or_fail(s, file=nil, line=0)
- parse_tree = parse(s)
- if parse_tree.nil?
- raise Cucumber::Parser::SyntaxError.new(self, file, line)
- else
- ast = parse_tree.build
- ast.file = file
- ast
- end
- end
end
end
end
\ No newline at end of file