lib/cucumber/ast/py_string.rb in cucumber-0.6.4 vs lib/cucumber/ast/py_string.rb in cucumber-0.7.0.beta.1
- old
+ new
@@ -15,27 +15,44 @@
# example above, that would return: <tt>"I like\nCucumber sandwich"</tt>
#
# Note how the indentation from the source is stripped away.
#
class PyString #:nodoc:
+ class Builder
+ attr_reader :string
+
+ def initialize
+ @string = ''
+ end
+
+ def py_string(string, line_number)
+ @string = string
+ end
+
+ def eof
+ end
+ end
+
attr_accessor :file
def self.default_arg_name
"string"
end
- def initialize(start_line, end_line, string, quotes_indent)
- @start_line, @end_line = start_line, end_line
- @string, @quotes_indent = string.gsub(/\\"/, '"'), quotes_indent
+ def self.parse(text)
+ builder = Builder.new
+ lexer = Gherkin::I18nLexer.new(builder)
+ lexer.scan(text)
+ new(builder.string)
end
+ def initialize(string)
+ @string = string
+ end
+
def to_s
- # Assume all whitespace before the first triple quote is the same.
- # Also assume the contents of the pystring is indented with the same prefix.
- # This allows indentation with both " " and "\t" characters.
- return @string if @quotes_indent == ""
- @string.gsub(/^#{@quotes_indent[0..0]}{0,#{@quotes_indent.length}}/, "")
+ @string
end
def accept(visitor)
return if Cucumber.wants_to_quit
visitor.visit_py_string(to_s)
@@ -45,10 +62,10 @@
string = @string
arguments.each do |name, value|
value ||= ''
string = string.gsub(name, value)
end
- PyString.new(@start_line, @end_line, string, @quotes_indent)
+ PyString.new(string)
end
def has_text?(text)
@string.index(text)
end