#[derive(Debug, pspp_derive::FromTokens)]
struct Crosstabs(Subcommands<CrosstabsSubcommand>);
-#[derive(Debug, pspp_derive::FromTokens)]
-#[pspp(syntax = "COUNT")]
-struct CountKw;
+mod keyword {
+ use crate::command::{FromTokens, ParseResult, TokenSlice};
+
+ #[derive(Debug, pspp_derive::FromTokens)]
+ pub struct Count;
+}
#[derive(Debug, pspp_derive::FromTokens)]
enum CrosstabsSubcommand {
Tables(Option<Equals>, Punctuated<VarList, By>),
Missing(Equals, Missing),
Write(Option<(Equals, Write)>),
- HideSmallCounts(CountKw, Equals, Integer),
+ HideSmallCounts(keyword::Count, Equals, Integer),
ShowDim(Equals, Integer),
Statistics(Equals, Punctuated<Statistic>),
Cells(Equals, Punctuated<Cell>),
+use std::fmt::Debug;
+
use either::Either;
use flagset::FlagSet;
enum CTablesSubcommand {
Table(Table),
Format(Seq1<Format>),
- VLabels(Seq1<VLabels>),
+ VLabels(Seq1<VLabel>),
SMissing(SMissing),
PCompute(And, Identifier, Equals, keyword::Expr, InParens<Expression>),
+ PProperties(And, Identifier, Seq0<PProperties>),
+ Weight(keyword::Variable, Equals, Identifier),
+ HideSmallCounts(keyword::Count, Equals, Integer),
+ SLabels(Seq1<SLabel>),
+ CLabels(CLabel),
+ Categories(Seq1<Category>),
}
#[derive(Debug, pspp_derive::FromTokens)]
Nest(Box<Axis>, Gt, Box<Axis>),
Stack(Box<Axis>, Plus, Box<Axis>),
Parens(InParens<Box<Axis>>),
- Annotate(InSquares<Punctuated<Annotation>>),
+ Summary(InSquares<Punctuated<Summary>>),
}
#[derive(Debug, pspp_derive::FromTokens)]
}
#[derive(Debug, pspp_derive::FromTokens)]
-struct Annotation {
+struct Summary {
function: Identifier,
percentile: Option<Number>,
label: Option<String>,
}
#[derive(Debug, pspp_derive::FromTokens)]
-enum VLabels {
+enum VLabel {
Variables(Equals, VarList),
Display(Display),
}
Listwise,
}
-#[derive(Debug, pspp_derive::FromTokens)]
+#[derive(pspp_derive::FromTokens)]
struct Expression(MulExpression, Seq0<(Either<Plus, Dash>, Expression)>);
-#[derive(Debug, pspp_derive::FromTokens)]
-struct MulExpression(PowExpression, Seq0<(Either<Asterisk, Slash>, PowExpression)>);
+impl Debug for Expression {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ if self.1 .0.is_empty() {
+ self.0.fmt(f)
+ } else {
+ write!(f, "(")?;
+ self.0.fmt(f)?;
+ for (operator, operand) in &self.1 .0 {
+ if operator.is_left() {
+ write!(f, " + ")?;
+ } else {
+ write!(f, " - ")?;
+ }
+ operand.fmt(f)?;
+ }
+ write!(f, ")")
+ }
+ }
+}
-#[derive(Debug, pspp_derive::FromTokens)]
+#[derive(pspp_derive::FromTokens)]
+struct MulExpression(
+ PowExpression,
+ Seq0<(Either<Asterisk, Slash>, PowExpression)>,
+);
+
+impl Debug for MulExpression {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ if self.1 .0.is_empty() {
+ self.0.fmt(f)
+ } else {
+ write!(f, "(")?;
+ self.0.fmt(f)?;
+ for (operator, operand) in &self.1 .0 {
+ if operator.is_left() {
+ write!(f, " * ")?;
+ } else {
+ write!(f, " / ")?;
+ }
+ operand.fmt(f)?;
+ }
+ write!(f, ")")
+ }
+ }
+}
+
+#[derive(pspp_derive::FromTokens)]
struct PowExpression(Terminal, Seq0<(Exp, PowExpression)>);
+impl Debug for PowExpression {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ if self.1 .0.is_empty() {
+ self.0.fmt(f)
+ } else {
+ write!(f, "(")?;
+ self.0.fmt(f)?;
+ for (_operator, operand) in &self.1 .0 {
+ write!(f, " ** {operand:?}")?;
+ }
+ write!(f, ")")
+ }
+ }
+}
+
#[derive(Debug, pspp_derive::FromTokens)]
#[pspp(no_selector)]
enum Terminal {
String(String),
}
+#[derive(Debug, pspp_derive::FromTokens)]
+enum PProperties {
+ Label(Equals, String),
+ Format(Equals, Seq1<Summary>),
+ HideSourceCats(Equals, Boolean),
+}
+
+#[derive(Debug, pspp_derive::FromTokens)]
+enum Boolean {
+ Yes,
+ No,
+}
+
+#[derive(Debug, pspp_derive::FromTokens)]
+enum SLabel {
+ Position(Equals, Position),
+ Visible(Equals, Boolean),
+}
+
+#[derive(Debug, pspp_derive::FromTokens)]
+enum Position {
+ Column,
+ Row,
+ Layer,
+}
+
+#[derive(Debug, pspp_derive::FromTokens)]
+enum CLabel {
+ Auto,
+ RowLabels(Equals, LabelDestination),
+ ColLabels(Equals, LabelDestination),
+}
+
+#[derive(Debug, pspp_derive::FromTokens)]
+enum LabelDestination {
+ Opposite,
+ Layer,
+}
+
+#[derive(Debug, pspp_derive::FromTokens)]
+enum Category {
+ Variables(Equals, VarList),
+ Order(Equals, Direction),
+ Key(Equals, Key),
+}
+
+#[derive(Debug, pspp_derive::FromTokens)]
+enum Direction {
+ #[pspp(syntax = "A")]
+ Ascending,
+ #[pspp(syntax = "D")]
+ Descending,
+}
+
+#[derive(Debug, pspp_derive::FromTokens)]
+enum Key {
+ Value,
+ Label,
+
+}
+
mod keyword {
use crate::command::{FromTokens, ParseResult, TokenSlice};
#[derive(Debug, pspp_derive::FromTokens)]
- #[pspp(syntax = "default")]
pub struct Default;
#[derive(Debug, pspp_derive::FromTokens)]
- #[pspp(syntax = "expr")]
pub struct Expr;
#[derive(Debug, pspp_derive::FromTokens)]
- #[pspp(syntax = "zero")]
pub struct Zero;
#[derive(Debug, pspp_derive::FromTokens)]
- #[pspp(syntax = "blank")]
pub struct Blank;
#[derive(Debug, pspp_derive::FromTokens)]
- #[pspp(syntax = "thru")]
pub struct Thru;
#[derive(Debug, pspp_derive::FromTokens)]
- #[pspp(syntax = "hi")]
pub struct Hi;
#[derive(Debug, pspp_derive::FromTokens)]
- #[pspp(syntax = "lo")]
pub struct Lo;
#[derive(Debug, pspp_derive::FromTokens)]
- #[pspp(syntax = "missing")]
pub struct Missing;
#[derive(Debug, pspp_derive::FromTokens)]
- #[pspp(syntax = "othernm")]
pub struct OtherNm;
#[derive(Debug, pspp_derive::FromTokens)]
- #[pspp(syntax = "subtotal")]
pub struct Subtotal;
#[derive(Debug, pspp_derive::FromTokens)]
- #[pspp(syntax = "total")]
pub struct Total;
+
+ #[derive(Debug, pspp_derive::FromTokens)]
+ pub struct Variable;
+
+ #[derive(Debug, pspp_derive::FromTokens)]
+ pub struct Count;
}
#[cfg(test)]
#[test]
fn basics() {
test(
- "ctables /pcompute &all_drivers =expr([1 thru 2])
+ "ctables /pcompute &all_drivers =expr(1+2*3+4)
/pcompute &all_drivers =expr(1).",
);
}