#[pspp(add_lifetime)]
enum Setting<'a> {
File(Equals, File<'a>),
- Encoding(&'a String),
+ Encoding(Equals, &'a String),
Fixed,
Free(Option<InParens<Punctuated<Delimiter<'a>>>>),
List(Option<InParens<Punctuated<Delimiter<'a>>>>),
Handle(&'a Identifier),
}
-#[derive(Debug)]
+#[derive(Debug, pspp_derive::FromTokens)]
+#[pspp(add_lifetime)]
struct Record<'a> {
slash: Slash,
record: Option<Integer>,
variables: Seq0<Variable<'a>>,
}
-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> {
#[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/.
+",
);
}
}