From 6b28fbf81ae1da4ff9c3325a166f69df9fb35c1e Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 6 Dec 2024 09:59:36 -0800 Subject: [PATCH] data list --- rust/pspp/src/command/data_list.rs | 86 ++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/rust/pspp/src/command/data_list.rs b/rust/pspp/src/command/data_list.rs index 9c1cb33ada..5fdd9112b7 100644 --- a/rust/pspp/src/command/data_list.rs +++ b/rust/pspp/src/command/data_list.rs @@ -42,7 +42,7 @@ struct DataList<'a>(Seq1>, Seq1>); #[pspp(add_lifetime)] enum Setting<'a> { File(Equals, File<'a>), - Encoding(&'a String), + Encoding(Equals, &'a String), Fixed, Free(Option>>>), List(Option>>>), @@ -67,37 +67,14 @@ enum File<'a> { Handle(&'a Identifier), } -#[derive(Debug)] +#[derive(Debug, pspp_derive::FromTokens)] +#[pspp(add_lifetime)] struct Record<'a> { slash: Slash, record: Option, variables: Seq0>, } -impl<'a> FromTokens<'a> for Record<'a> { - fn from_tokens(input: TokenSlice<'a>) -> ParseResult<'a, Self> { - println!("{input:?}"); - println!("{}:{}", file!(), line!()); - let mut diagnostics = crate::command::Diagnostics::default(); - println!("{}:{}", file!(), line!()); - let (field0, input) = FromTokens::from_tokens(input)?.take_diagnostics(&mut diagnostics); - println!("{}:{}", file!(), line!()); - let (field1, input) = FromTokens::from_tokens(input)?.take_diagnostics(&mut diagnostics); - println!("{}:{}", file!(), line!()); - let (field2, input) = FromTokens::from_tokens(input)?.take_diagnostics(&mut diagnostics); - println!("{}:{}", file!(), line!()); - Ok(Parsed::new( - Record { - slash: field0, - record: field1, - variables: field2, - }, - input, - diagnostics, - )) - } -} - #[derive(Debug, pspp_derive::FromTokens)] #[pspp(add_lifetime)] struct Variable<'a> { @@ -142,9 +119,60 @@ mod tests { #[test] fn basics() { test( - r#"DATA LIST FILE="/data/hubdata.txt" RECORDS=3 -/1 DEPT 19 SEX 20 MOHIRED YRHIRED 12-15 -/2 SALARY 21-25."#, + "data list fixed notable + /1 start 1-20 (adate) + /2 end 1-20 (adate) + /3 count 1-3.", + ); + } + + #[test] + fn syntax_errors() { + test( + "DATA LIST FILE=**. +DATA LIST ENCODING=**. +DATA LIST RECORDS=1 RECORDS=2. +DATA LIST RECORDS=0. +DATA LIST SKIP=-1. +DATA LIST END=**. +INPUT PROGRAM. +DATA LIST END=xyzzy END=xyzzy. +END INPUT PROGRAM. +INPUT PROGRAM. +DATA LIST END=**. +END INPUT PROGRAM. +DATA LIST XYZZY. +DATA LIST FREE LIST. +DATA LIST LIST (**). +DATA LIST **. +DATA LIST ENCODING='xyzzy'/x. +INPUT PROGRAM. +DATA LIST LIST END=xyzzy/x. +END INPUT PROGRAM. +DATA LIST FIXED/0. +DATA LIST FIXED/ **. +DATA LIST FIXED/x 1.5. +DATA LIST FIXED/x -1. +DATA LIST FIXED/x 5-3. +DATA LIST FIXED/x y 1-3. +DATA LIST FIXED/x 1-5 (xyzzy). +DATA LIST FIXED/x 1-5 (**). +DATA LIST FIXED/x 1 (F,5). +DATA LIST FIXED/x (2F8.0). +DATA LIST FIXED/x **. +DATA LIST FIXED/x 1 x 2. +INPUT PROGRAM. +DATA LIST FIXED/x 1. +DATA LIST FIXED/x 1 (a). +END INPUT PROGRAM. +INPUT PROGRAM. +DATA LIST FIXED/y 2 (a). +DATA LIST FIXED/y 3-4 (a). +END INPUT PROGRAM. +DATA LIST FIXED RECORDS=1/x y(F2/F3). +DATA LIST FIXED RECORDS=1//. +DATA LIST FIXED RECORDS=1/. +", ); } } -- 2.30.2