compiles
[pspp] / rust / src / cooked.rs
index b7802e91cd1e58526b059e416782e59101867508..3e4677e71c1bbbe80191617e92f8e935ece67fe4 100644 (file)
@@ -8,7 +8,7 @@ use crate::{
     endian::Endian,
     format::{Error as FormatError, Spec, UncheckedSpec},
     identifier::{Error as IdError, Identifier},
-    raw::{self, RawDocumentLine, RawStr, RawString, VarDisplayRecord, VarType, ProductInfoRecord},
+    raw::{self, ProductInfoRecord, RawDocumentLine, RawStr, RawString, VarDisplayRecord, VarType},
 };
 use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
 use encoding_rs::{DecoderResult, Encoding};
@@ -214,7 +214,7 @@ struct Headers<'a> {
     float_info: Option<&'a raw::FloatInfoRecord>,
     variable_sets: Vec<&'a raw::VariableSetRecord>,
     var_display: Option<&'a raw::VarDisplayRecord>,
-    multiple_response: Vec<&'a raw::MultipleResponseRecord<RawString>>,
+    multiple_response: Vec<&'a raw::MultipleResponseRecord<RawString, RawString>>,
     long_string_value_labels: Vec<&'a raw::LongStringValueLabelRecord<RawString>>,
     long_string_missing_values: Vec<&'a raw::LongStringMissingValueRecord<RawString, RawStr<8>>>,
     encoding: Option<&'a raw::EncodingRecord>,
@@ -271,7 +271,6 @@ impl<'a> Headers<'a> {
                 raw::Record::ZTrailer(_) => (),
                 raw::Record::Cases(record) => set_or_warn(&mut h.cases, record, warn),
                 raw::Record::Text(_) => todo!(),
-                
             }
         }
         h
@@ -339,82 +338,82 @@ pub fn decode(
     if let Some(raw) = h.number_of_cases {
         output.push(Record::NumberOfCases(raw.clone()))
     }
-/*
-    for &raw in &h.file_attributes {
-        let s = decoder.decode_string_cow(&raw.text.0, warn);
-        output.push(Record::FileAttributes(FileAttributeRecord::parse(
-            &decoder, &s, warn,
-        )?));
-    }
-    for &raw in &h.other_extensions {
-        output.push(Record::OtherExtension(raw.clone()));
-    }
-    // Decode the variable records, which are the basis of almost everything
-    // else.
-    for &raw in &h.variables {
-        if let Some(variable) = VariableRecord::try_decode(&mut decoder, raw, warn)? {
-            output.push(Record::Variable(variable));
+    /*
+        for &raw in &h.file_attributes {
+            let s = decoder.decode_string_cow(&raw.text.0, warn);
+            output.push(Record::FileAttributes(FileAttributeRecord::parse(
+                &decoder, &s, warn,
+            )?));
+        }
+        for &raw in &h.other_extensions {
+            output.push(Record::OtherExtension(raw.clone()));
+        }
+        // Decode the variable records, which are the basis of almost everything
+        // else.
+        for &raw in &h.variables {
+            if let Some(variable) = VariableRecord::try_decode(&mut decoder, raw, warn)? {
+                output.push(Record::Variable(variable));
+            }
         }
-    }
 
-    // Decode value labels and weight variable.  These use indexes into the
-    // variable records, so we need to parse them before those indexes become
-    // invalidated by very long string variables.
-    for &raw in &h.value_labels {
-        if let Some(value_label) = ValueLabelRecord::try_decode(&mut decoder, raw, warn)? {
-            output.push(Record::ValueLabel(value_label));
+        // Decode value labels and weight variable.  These use indexes into the
+        // variable records, so we need to parse them before those indexes become
+        // invalidated by very long string variables.
+        for &raw in &h.value_labels {
+            if let Some(value_label) = ValueLabelRecord::try_decode(&mut decoder, raw, warn)? {
+                output.push(Record::ValueLabel(value_label));
+            }
+        }
+        // XXX weight
+        if let Some(raw) = h.var_display {
+            output.push(Record::VarDisplay(raw.clone()));
         }
-    }
-    // XXX weight
-    if let Some(raw) = h.var_display {
-        output.push(Record::VarDisplay(raw.clone()));
-    }
 
-    // Decode records that use short names.
-        for &raw in &h.multiple_response {
-            if let Some(mrr) = MultipleResponseRecord::try_decode(&mut decoder, raw, warn)? {
-                output.push(Record::MultipleResponse(mrr))
+        // Decode records that use short names.
+            for &raw in &h.multiple_response {
+                if let Some(mrr) = MultipleResponseRecord::try_decode(&mut decoder, raw, warn)? {
+                    output.push(Record::MultipleResponse(mrr))
+                }
             }
+        for &raw in &h.very_long_strings {
+            let s = decoder.decode_string_cow(&raw.text.0, warn);
+            output.push(Record::VeryLongStrings(VeryLongStringRecord::parse(
+                &decoder, &s, warn,
+            )?));
         }
-    for &raw in &h.very_long_strings {
-        let s = decoder.decode_string_cow(&raw.text.0, warn);
-        output.push(Record::VeryLongStrings(VeryLongStringRecord::parse(
-            &decoder, &s, warn,
-        )?));
-    }
 
-    // Rename variables to their long names.
-    for &raw in &h.long_names {
-        let s = decoder.decode_string_cow(&raw.text.0, warn);
-        output.push(Record::LongNames(LongNameRecord::parse(
-            &mut decoder,
-            &s,
-            warn,
-        )?));
-    }
+        // Rename variables to their long names.
+        for &raw in &h.long_names {
+            let s = decoder.decode_string_cow(&raw.text.0, warn);
+            output.push(Record::LongNames(LongNameRecord::parse(
+                &mut decoder,
+                &s,
+                warn,
+            )?));
+        }
 
-    // Decode recods that use long names.
-    for &raw in &h.variable_attributes {
-        let s = decoder.decode_string_cow(&raw.text.0, warn);
-        output.push(Record::VariableAttributes(VariableAttributeRecord::parse(
-            &decoder, &s, warn,
-        )?));
-    }
-    for &raw in &h.long_string_value_labels {
-        if let Some(mrr) = LongStringValueLabelRecord::try_decode(&mut decoder, raw, warn)? {
-            output.push(Record::LongStringValueLabels(mrr))
+        // Decode recods that use long names.
+        for &raw in &h.variable_attributes {
+            let s = decoder.decode_string_cow(&raw.text.0, warn);
+            output.push(Record::VariableAttributes(VariableAttributeRecord::parse(
+                &decoder, &s, warn,
+            )?));
         }
-    }
-    for &raw in &h.long_string_missing_values {
-        if let Some(mrr) = LongStringMissingValuesRecord::try_decode(&mut decoder, raw, warn)? {
-            output.push(Record::LongStringMissingValues(mrr))
+        for &raw in &h.long_string_value_labels {
+            if let Some(mrr) = LongStringValueLabelRecord::try_decode(&mut decoder, raw, warn)? {
+                output.push(Record::LongStringValueLabels(mrr))
+            }
         }
-    }
-    for &raw in &h.variable_sets {
-        let s = decoder.decode_string_cow(&raw.text.0, warn);
-        output.push(Record::VariableSets(VariableSetRecord::parse(&s, warn)?));
-    }
-*/
+        for &raw in &h.long_string_missing_values {
+            if let Some(mrr) = LongStringMissingValuesRecord::try_decode(&mut decoder, raw, warn)? {
+                output.push(Record::LongStringMissingValues(mrr))
+            }
+        }
+        for &raw in &h.variable_sets {
+            let s = decoder.decode_string_cow(&raw.text.0, warn);
+            output.push(Record::VariableSets(VariableSetRecord::parse(&s, warn)?));
+        }
+    */
     Ok(output)
 }
 
@@ -1218,21 +1217,12 @@ pub struct MultipleResponseSet {
 impl MultipleResponseSet {
     fn decode(
         decoder: &Decoder,
-        input: &raw::MultipleResponseSet<Cow<str>>,
+        input: &raw::MultipleResponseSet<Identifier, Cow<str>>,
         warn: &impl Fn(Error),
     ) -> Result<Self, Error> {
-        let mr_set_name =
-            Identifier::new(&input.name, decoder.encoding).map_err(Error::InvalidMrSetName)?;
-
+        let mr_set_name = input.name.clone();
         let mut dict_indexes = Vec::with_capacity(input.short_names.len());
         for short_name in input.short_names.iter() {
-            let short_name = match Identifier::new(&short_name, decoder.encoding) {
-                Ok(name) => name,
-                Err(error) => {
-                    warn(Error::InvalidMrSetName(error));
-                    continue;
-                }
-            };
             let Some(&dict_index) = decoder.var_names.get(&short_name) else {
                 warn(Error::UnknownMrSetVariable {
                     mr_set: mr_set_name.clone(),
@@ -1276,7 +1266,7 @@ impl MultipleResponseSet {
 pub struct MultipleResponseRecord(pub Vec<MultipleResponseSet>);
 
 impl TryDecode for MultipleResponseRecord {
-    type Input<'a> = raw::MultipleResponseRecord<Cow<'a, str>>;
+    type Input<'a> = raw::MultipleResponseRecord<Identifier, Cow<'a, str>>;
 
     fn try_decode(
         decoder: &mut Decoder,