summaryrefslogtreecommitdiff
path: root/lib/prism/pack.rb
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2023-10-30 15:11:24 -0400
committerKevin Newton <[email protected]>2023-11-01 13:10:29 -0400
commit4490979615338ea21619c2f1287759172c9a2437 ()
tree542d1941faee46e2652f9e78648bfa0e04d52fd9 /lib/prism/pack.rb
parent79034fbd503769ed2742003e31920733e9300909 (diff)
[ruby/prism] Finish Ruby documentation
https://.com/ruby/prism/commit/dfdcc98a3c
-rw-r--r--lib/prism/pack.rb42
1 files changed, 39 insertions, 3 deletions
@@ -57,8 +57,34 @@ module Prism
# A directive in the pack template language.
class Directive
- attr_reader :version, :variant, :source, :type, :signed, :endian, :size, :length_type, :length
def initialize(version, variant, source, type, signed, endian, size, length_type, length)
@version = version
@variant = variant
@@ -71,6 +97,7 @@ module Prism
@length = length
end
ENDIAN_DESCRIPTIONS = {
AGNOSTIC_ENDIAN: "agnostic",
LITTLE_ENDIAN: "little-endian (VAX)",
@@ -79,12 +106,14 @@ module Prism
ENDIAN_NA: "n/a"
}
SIGNED_DESCRIPTIONS = {
UNSIGNED: "unsigned",
SIGNED: "signed",
SIGNED_NA: "n/a"
}
SIZE_DESCRIPTIONS = {
SIZE_SHORT: "short",
SIZE_INT: "int-width",
@@ -97,6 +126,7 @@ module Prism
SIZE_P: "pointer-width"
}
def describe
case type
when SPACE
@@ -161,15 +191,21 @@ module Prism
end
end
- # A class used to describe what a pack template does.
class Format
- attr_reader :directives, :encoding
def initialize(directives, encoding)
@directives = directives
@encoding = encoding
end
def describe
source_width = directives.map { |d| d.source.inspect.length }.max
directive_lines = directives.map do |directive|