Skip to main content

ironwork_rt/
vocab.rs

1//! The vocabulary the front end, the interpreter and a compiled program share: source positions
2//! and the small enums of the data division, INSPECT and OPEN.
3
4use std::fmt;
5
6/// Where a diagnostic points: 1-based source line and column.
7#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
8pub struct Pos {
9    /// Index into the program's file table: 0 for the program itself, then each COPY member.
10    pub file: u16,
11    pub line: u32,
12    pub col: u32,
13}
14
15impl fmt::Display for Pos {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        write!(f, "{}:{}", self.line, self.col)
18    }
19}
20
21#[derive(Clone, Copy, Debug, PartialEq, Eq)]
22pub enum SignPosition {
23    Leading,
24    Trailing,
25}
26
27#[derive(Clone, Copy, Debug, PartialEq, Eq)]
28pub struct SignClause {
29    pub position: SignPosition,
30    pub separate: bool,
31}
32
33#[derive(Clone, Copy, Debug, PartialEq, Eq)]
34pub enum InspectMode {
35    Characters,
36    All,
37    Leading,
38    First,
39    /// GnuCOBOL's TRAILING under `--compliance extended`: the occurrences that run on to the end of
40    /// the phrase's region.
41    Trailing,
42}
43
44#[derive(Clone, Copy, Debug, PartialEq, Eq)]
45pub enum Figurative {
46    Zero,
47    Space,
48    HighValue,
49    LowValue,
50    Quote,
51    Null,
52}
53
54#[derive(Clone, Copy, Debug, PartialEq, Eq)]
55pub enum BinOp {
56    Add,
57    Sub,
58    Mul,
59    Div,
60    Pow,
61}
62
63#[derive(Clone, Copy, Debug, PartialEq, Eq)]
64pub enum RelOp {
65    Eq,
66    Ne,
67    Lt,
68    Le,
69    Gt,
70    Ge,
71}
72
73#[derive(Clone, Copy, Debug, PartialEq, Eq)]
74pub enum OpenMode {
75    Input,
76    Output,
77    Extend,
78    InputOutput,
79}
80
81/// The phrases CLOSE can write after a file-name.
82#[derive(Clone, Copy, Debug, PartialEq, Eq)]
83pub enum Closing {
84    /// REEL or UNIT, with FOR REMOVAL, WITH NO REWIND or neither: the volume, not the file.
85    Volume,
86    NoRewind,
87    /// WITH LOCK: the file cannot be opened again while the program is in the run unit.
88    Lock,
89}
90
91#[derive(Clone, Copy, Debug, PartialEq, Eq)]
92pub enum AcceptFrom {
93    Sysin,
94    Date { four_digit_year: bool },
95    Day { four_digit_year: bool },
96    DayOfWeek,
97    Time,
98    /// Under `--compliance extended`, the job step's PARM program arguments, as Micro Focus and
99    /// GnuCOBOL give the command line.
100    CommandLine,
101    /// Under `--compliance extended`, how many words the PARM's program arguments hold.
102    ArgumentNumber,
103    /// Under `--compliance extended`, the next word of the PARM's program arguments.
104    ArgumentValue,
105    /// Under `--compliance extended`, the value of the environment variable DISPLAY UPON
106    /// ENVIRONMENT-NAME named.
107    EnvironmentValue,
108}