finished getting rid of textrecord
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 16 Jun 2025 03:33:57 +0000 (20:33 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 16 Jun 2025 03:33:57 +0000 (20:33 -0700)
some tests still fail

rust/pspp/src/sys/cooked.rs
rust/pspp/src/sys/raw.rs

index aa7e65fbb300ef5a1252190668aebee1e6e04ebe..d1ee09ebff3f10714072b3bc46d9927630998568 100644 (file)
@@ -18,7 +18,7 @@ use crate::{
             LongNamesRecord, LongStringMissingValueRecord, LongStringValueLabelRecord,
             MissingValues, MissingValuesError, MultipleResponseRecord, NumberOfCasesRecord,
             ProductInfoRecord, RawStrArray, RawString, RawWidth, ValueLabel, ValueLabelRecord,
-            VarDisplayRecord, VariableAttributeRecord, VariableRecord, VariableSetRecord,
+            VarDisplayRecord, VariableAttributesRecord, VariableRecord, VariableSetRecord,
             VeryLongStringsRecord, ZHeader, ZTrailer,
         },
     },
@@ -215,7 +215,7 @@ pub struct Headers {
     pub long_names: Vec<LongNamesRecord>,
     pub very_long_strings: Vec<VeryLongStringsRecord>,
     pub file_attributes: Vec<FileAttributesRecord>,
-    pub variable_attributes: Vec<VariableAttributeRecord>,
+    pub variable_attributes: Vec<VariableAttributesRecord>,
     pub other_extension: Vec<Extension>,
     pub end_of_headers: Option<u32>,
     pub z_header: Option<ZHeader>,
index 9c010ccbe98675cd53d0fbbe57e5b23612a2d467..7b8970a1af57b26e6c7bfa3496105e3296e15a80 100644 (file)
@@ -292,7 +292,7 @@ pub enum Record {
     LongNames(RawLongNamesRecord),
     VeryLongStrings(RawVeryLongStringsRecord),
     FileAttributes(RawFileAttributesRecord),
-    Text(TextRecord),
+    VariableAttributes(RawVariableAttributesRecord),
     OtherExtension(Extension),
     EndOfHeaders(u32),
     ZHeader(ZHeader),
@@ -319,7 +319,7 @@ pub enum DecodedRecord {
     LongNames(LongNamesRecord),
     VeryLongStrings(VeryLongStringsRecord),
     FileAttributes(FileAttributesRecord),
-    VariableAttributes(VariableAttributeRecord),
+    VariableAttributes(VariableAttributesRecord),
     OtherExtension(Extension),
     EndOfHeaders(u32),
     ZHeader(ZHeader),
@@ -378,7 +378,9 @@ impl Record {
                 DecodedRecord::VeryLongStrings(record.decode(decoder))
             }
             Record::FileAttributes(record) => DecodedRecord::FileAttributes(record.decode(decoder)),
-            Record::Text(record) => record.decode(decoder),
+            Record::VariableAttributes(record) => {
+                DecodedRecord::VariableAttributes(record.decode(decoder))
+            }
             Record::OtherExtension(record) => DecodedRecord::OtherExtension(record.clone()),
             Record::EndOfHeaders(record) => DecodedRecord::EndOfHeaders(record),
             Record::ZHeader(record) => DecodedRecord::ZHeader(record.clone()),
@@ -2682,18 +2684,10 @@ impl RawLongNamesRecord {
 pub struct TextRecord {
     pub offsets: Range<u64>,
 
-    /// Type of record.
-    pub rec_type: TextRecordType,
-
     /// The text content of the record.
     pub text: RawString,
 }
 
-#[derive(Clone, Copy, Debug)]
-pub enum TextRecordType {
-    VariableAttributes,
-}
-
 impl TextRecord {
     fn parse(extension: Extension, name: &str) -> Result<TextRecord, Warning> {
         extension.check_size(&ExtensionRecord {
@@ -2701,21 +2695,10 @@ impl TextRecord {
             count: None,
             name,
         })?;
-        Ok(Self::new(extension, TextRecordType::VariableAttributes))
-    }
-    fn new(extension: Extension, rec_type: TextRecordType) -> Self {
-        Self {
+        Ok(Self {
             offsets: extension.offsets,
-            rec_type,
             text: extension.data.into(),
-        }
-    }
-    pub fn decode(self, decoder: &mut Decoder) -> DecodedRecord {
-        match self.rec_type {
-            TextRecordType::VariableAttributes => {
-                DecodedRecord::VariableAttributes(VariableAttributeRecord::decode(&self, decoder))
-            }
-        }
+        })
     }
 }
 
@@ -2887,11 +2870,20 @@ impl VarAttributes {
 }
 
 #[derive(Clone, Debug)]
-pub struct VariableAttributeRecord(pub Vec<VarAttributes>);
+pub struct RawVariableAttributesRecord(TextRecord);
+
+#[derive(Clone, Debug)]
+pub struct VariableAttributesRecord(pub Vec<VarAttributes>);
 
-impl VariableAttributeRecord {
-    fn decode(source: &TextRecord, decoder: &mut Decoder) -> Self {
-        let decoded = decoder.decode(&source.text);
+impl RawVariableAttributesRecord {
+    fn parse(extension: Extension) -> Result<Record, Warning> {
+        Ok(Record::VariableAttributes(Self(TextRecord::parse(
+            extension,
+            "variable attributes record",
+        )?)))
+    }
+    fn decode(self, decoder: &mut Decoder) -> VariableAttributesRecord {
+        let decoded = decoder.decode(&self.0.text);
         let mut input = decoded.as_ref();
         let mut var_attribute_sets = Vec::new();
         while !input.is_empty() {
@@ -2903,7 +2895,7 @@ impl VariableAttributeRecord {
             var_attribute_sets.push(var_attribute);
             input = rest;
         }
-        VariableAttributeRecord(var_attribute_sets)
+        VariableAttributesRecord(var_attribute_sets)
     }
 }
 
@@ -3075,10 +3067,7 @@ impl Extension {
             13 => RawLongNamesRecord::parse(extension),
             14 => RawVeryLongStringsRecord::parse(extension),
             17 => RawFileAttributesRecord::parse(extension),
-            18 => Ok(Record::Text(TextRecord::new(
-                extension,
-                TextRecordType::VariableAttributes,
-            ))),
+            18 => RawVariableAttributesRecord::parse(extension),
             _ => Ok(Record::OtherExtension(extension)),
         };
         match result {