Skip to main content

ironwork_syntax/
report.rs

1//! The REPORT SECTION as written: report descriptions with their report groups, the INITIATE,
2//! GENERATE, TERMINATE and SUPPRESS statements, and USE BEFORE REPORTING procedures.
3
4use crate::Pos;
5use crate::ast::{Expr, Literal, Ref, SignClause};
6
7#[derive(Clone, Debug, Default, PartialEq, Eq)]
8pub struct ReportWriter {
9    pub reports: Vec<Report>,
10    pub uses: Vec<UseBeforeReporting>,
11    /// Paragraphs before this index are the DECLARATIVES, which run only when invoked.
12    pub procedure_start: usize,
13}
14
15/// An RD entry and the report groups that follow it.
16#[derive(Clone, Debug, PartialEq, Eq)]
17pub struct Report {
18    pub name: String,
19    /// CODE literal: prefixed to every record the report writes.
20    pub code: Option<Literal>,
21    /// CONTROL identifiers, major to minor. FINAL is always the highest level, written or not.
22    pub controls: Vec<Ref>,
23    pub page: Option<u32>,
24    pub heading: Option<u32>,
25    pub first_detail: Option<u32>,
26    pub last_detail: Option<u32>,
27    pub footing: Option<Footing>,
28    pub line_limit: Option<u32>,
29    pub groups: Vec<Group>,
30    pub pos: Pos,
31}
32
33/// FOOTING, or LAST CONTROL FOOTING: a line, or lines below LAST DETAIL.
34#[derive(Clone, Copy, Debug, PartialEq, Eq)]
35pub enum Footing {
36    Line(u32),
37    Plus(u32),
38}
39
40#[derive(Clone, Debug, PartialEq, Eq)]
41pub enum ControlName {
42    Final,
43    Item(Ref),
44}
45
46#[derive(Clone, Debug, PartialEq, Eq)]
47pub enum GroupType {
48    ReportHeading,
49    PageHeading,
50    /// CONTROL HEADING, for the control named or the only one there is.
51    ControlHeading(Option<ControlName>),
52    Detail,
53    ControlFooting(Option<ControlName>),
54    PageFooting,
55    ReportFooting,
56}
57
58#[derive(Clone, Copy, Debug, PartialEq, Eq)]
59pub enum NextGroup {
60    Line(u32),
61    Plus(u32),
62    NextPage,
63}
64
65#[derive(Clone, Copy, Debug, PartialEq, Eq)]
66pub enum LineNumber {
67    Line(u32),
68    Plus(u32),
69    /// NEXT PAGE, with the absolute line when one is written.
70    NextPage(Option<u32>),
71}
72
73#[derive(Clone, Copy, Debug, PartialEq, Eq)]
74pub enum ColumnNumber {
75    Left(u32),
76    Plus(u32),
77    Right(u32),
78    Center(u32),
79}
80
81#[derive(Clone, Debug, PartialEq, Eq)]
82pub struct SumClause {
83    pub operands: Vec<Ref>,
84    /// UPON: the DETAIL groups whose GENERATE adds the operands.
85    pub upon: Vec<Ref>,
86    pub reset: Option<ControlName>,
87}
88
89#[derive(Clone, Debug, PartialEq, Eq)]
90pub enum Content {
91    Source(Expr),
92    Value(Literal),
93    Sum(Vec<SumClause>),
94}
95
96/// A report group: its 01-level entry, then every entry below it, in order.
97#[derive(Clone, Debug, PartialEq, Eq)]
98pub struct Group {
99    pub name: Option<String>,
100    pub kind: GroupType,
101    pub next_group: Option<NextGroup>,
102    pub entries: Vec<Entry>,
103    pub pos: Pos,
104}
105
106#[derive(Clone, Debug, PartialEq, Eq)]
107pub struct Entry {
108    pub level: u8,
109    pub name: Option<String>,
110    pub line: Option<LineNumber>,
111    pub column: Option<ColumnNumber>,
112    pub picture: Option<String>,
113    pub content: Option<Content>,
114    pub rounded: bool,
115    pub group_indicate: bool,
116    pub blank_when_zero: bool,
117    pub justified: bool,
118    pub sign: Option<SignClause>,
119    pub pos: Pos,
120}
121
122#[derive(Clone, Debug, PartialEq, Eq)]
123pub enum ReportStmt {
124    Initiate { reports: Vec<String>, pos: Pos },
125    /// GENERATE a DETAIL group, or a report for summary reporting; `qualifier` is IN report-name.
126    Generate { name: String, qualifier: Option<String>, pos: Pos },
127    Terminate { reports: Vec<String>, pos: Pos },
128    Suppress { pos: Pos },
129}
130
131/// A DECLARATIVES section that runs just before a report group is produced.
132#[derive(Clone, Debug, PartialEq, Eq)]
133pub struct UseBeforeReporting {
134    /// The section's header among the program's paragraphs.
135    pub section: usize,
136    pub group: String,
137    pub qualifier: Option<String>,
138    /// USE GLOBAL: it serves the same group name in contained programs too.
139    pub global: bool,
140    pub pos: Pos,
141}