[ruby/prism] Provide heredoc? queries
https://github.com/ruby/prism/commit/e148e8fe6a
This commit is contained in:
parent
2a8d9c59ff
commit
ec83bd7356
@ -14,8 +14,49 @@ module Prism
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class InterpolatedMatchLastLineNode < Node
|
||||||
|
include RegularExpressionOptions
|
||||||
|
end
|
||||||
|
|
||||||
|
class InterpolatedRegularExpressionNode < Node
|
||||||
|
include RegularExpressionOptions
|
||||||
|
end
|
||||||
|
|
||||||
|
class MatchLastLineNode < Node
|
||||||
|
include RegularExpressionOptions
|
||||||
|
end
|
||||||
|
|
||||||
|
class RegularExpressionNode < Node
|
||||||
|
include RegularExpressionOptions
|
||||||
|
end
|
||||||
|
|
||||||
private_constant :RegularExpressionOptions
|
private_constant :RegularExpressionOptions
|
||||||
|
|
||||||
|
module HeredocQuery # :nodoc:
|
||||||
|
# Returns true if this node was represented as a heredoc in the source code.
|
||||||
|
def heredoc?
|
||||||
|
opening&.start_with?("<<")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class InterpolatedStringNode < Node
|
||||||
|
include HeredocQuery
|
||||||
|
end
|
||||||
|
|
||||||
|
class InterpolatedXStringNode < Node
|
||||||
|
include HeredocQuery
|
||||||
|
end
|
||||||
|
|
||||||
|
class StringNode < Node
|
||||||
|
include HeredocQuery
|
||||||
|
end
|
||||||
|
|
||||||
|
class XStringNode < Node
|
||||||
|
include HeredocQuery
|
||||||
|
end
|
||||||
|
|
||||||
|
private_constant :HeredocQuery
|
||||||
|
|
||||||
class FloatNode < Node
|
class FloatNode < Node
|
||||||
# Returns the value of the node as a Ruby Float.
|
# Returns the value of the node as a Ruby Float.
|
||||||
def value
|
def value
|
||||||
@ -37,18 +78,6 @@ module Prism
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class InterpolatedMatchLastLineNode < Node
|
|
||||||
include RegularExpressionOptions
|
|
||||||
end
|
|
||||||
|
|
||||||
class InterpolatedRegularExpressionNode < Node
|
|
||||||
include RegularExpressionOptions
|
|
||||||
end
|
|
||||||
|
|
||||||
class MatchLastLineNode < Node
|
|
||||||
include RegularExpressionOptions
|
|
||||||
end
|
|
||||||
|
|
||||||
class RationalNode < Node
|
class RationalNode < Node
|
||||||
# Returns the value of the node as a Ruby Rational.
|
# Returns the value of the node as a Ruby Rational.
|
||||||
def value
|
def value
|
||||||
@ -56,10 +85,6 @@ module Prism
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class RegularExpressionNode < Node
|
|
||||||
include RegularExpressionOptions
|
|
||||||
end
|
|
||||||
|
|
||||||
class ConstantReadNode < Node
|
class ConstantReadNode < Node
|
||||||
# Returns the list of parts for the full name of this constant.
|
# Returns the list of parts for the full name of this constant.
|
||||||
# For example: [:Foo]
|
# For example: [:Foo]
|
||||||
|
@ -103,6 +103,18 @@ module Prism
|
|||||||
assert_equal 7, location.end_character_column
|
assert_equal 7, location.end_character_column
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_heredoc?
|
||||||
|
refute parse_expression("\"foo\"").heredoc?
|
||||||
|
refute parse_expression("\"foo \#{1}\"").heredoc?
|
||||||
|
refute parse_expression("`foo`").heredoc?
|
||||||
|
refute parse_expression("`foo \#{1}`").heredoc?
|
||||||
|
|
||||||
|
assert parse_expression("<<~HERE\nfoo\nHERE\n").heredoc?
|
||||||
|
assert parse_expression("<<~HERE\nfoo \#{1}\nHERE\n").heredoc?
|
||||||
|
assert parse_expression("<<~`HERE`\nfoo\nHERE\n").heredoc?
|
||||||
|
assert parse_expression("<<~`HERE`\nfoo \#{1}\nHERE\n").heredoc?
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def parse_expression(source)
|
def parse_expression(source)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user