[ruby/prism] Consolidate integer fields into a single reflection class
https://github.com/ruby/prism/commit/0156057580
This commit is contained in:
parent
f77618c1fa
commit
aa5b53d232
@ -65,14 +65,16 @@ module Prism
|
|||||||
class OptionalLocationField < Field
|
class OptionalLocationField < Field
|
||||||
end
|
end
|
||||||
|
|
||||||
# A uint8 field represents an unsigned 8-bit integer value on a node. It
|
# An integer field represents an integer value. It is used to represent the
|
||||||
# resolves to an Integer in Ruby.
|
# value of an integer literal, the depth of local variables, and the number
|
||||||
class UInt8Field < Field
|
# of a numbered reference. It resolves to an Integer in Ruby.
|
||||||
|
class IntegerField < Field
|
||||||
end
|
end
|
||||||
|
|
||||||
# A uint32 field represents an unsigned 32-bit integer value on a node. It
|
# A float field represents a double-precision floating point value. It is
|
||||||
# resolves to an Integer in Ruby.
|
# used exclusively to represent the value of a floating point literal. It
|
||||||
class UInt32Field < Field
|
# resolves to a Float in Ruby.
|
||||||
|
class FloatField < Field
|
||||||
end
|
end
|
||||||
|
|
||||||
# A flags field represents a bitset of flags on a node. It resolves to an
|
# A flags field represents a bitset of flags on a node. It resolves to an
|
||||||
@ -90,18 +92,6 @@ module Prism
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# An integer field represents an arbitrarily-sized integer value. It is used
|
|
||||||
# exclusively to represent the value of an integer literal. It resolves to
|
|
||||||
# an Integer in Ruby.
|
|
||||||
class IntegerField < Field
|
|
||||||
end
|
|
||||||
|
|
||||||
# A double field represents a double-precision floating point value. It is
|
|
||||||
# used exclusively to represent the value of a floating point literal. It
|
|
||||||
# resolves to a Float in Ruby.
|
|
||||||
class DoubleField < Field
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns the fields for the given node.
|
# Returns the fields for the given node.
|
||||||
def self.fields_for(node)
|
def self.fields_for(node)
|
||||||
case node.type
|
case node.type
|
||||||
@ -127,17 +117,13 @@ module Prism
|
|||||||
"LocationField.new(:#{field.name})"
|
"LocationField.new(:#{field.name})"
|
||||||
when Prism::Template::OptionalLocationField
|
when Prism::Template::OptionalLocationField
|
||||||
"OptionalLocationField.new(:#{field.name})"
|
"OptionalLocationField.new(:#{field.name})"
|
||||||
when Prism::Template::UInt8Field
|
when Prism::Template::UInt8Field, Prism::Template::UInt32Field, Prism::Template::IntegerField
|
||||||
"UInt8Field.new(:#{field.name})"
|
"Integer.new(:#{field.name})"
|
||||||
when Prism::Template::UInt32Field
|
when Prism::Template::DoubleField
|
||||||
"UInt32Field.new(:#{field.name})"
|
"FloatField.new(:#{field.name})"
|
||||||
when Prism::Template::FlagsField
|
when Prism::Template::FlagsField
|
||||||
found = flags.find { |flag| flag.name == field.kind }.tap { |found| raise "Expected to find #{field.kind}" unless found }
|
found = flags.find { |flag| flag.name == field.kind }.tap { |found| raise "Expected to find #{field.kind}" unless found }
|
||||||
"FlagsField.new(:#{field.name}, [#{found.values.map { |value| ":#{value.name.downcase}?" }.join(", ")}])"
|
"FlagsField.new(:#{field.name}, [#{found.values.map { |value| ":#{value.name.downcase}?" }.join(", ")}])"
|
||||||
when Prism::Template::IntegerField
|
|
||||||
"IntegerField.new(:#{field.name})"
|
|
||||||
when Prism::Template::DoubleField
|
|
||||||
"DoubleField.new(:#{field.name})"
|
|
||||||
else
|
else
|
||||||
raise field.class.name
|
raise field.class.name
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user