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}
40
41#[derive(Clone, Copy, Debug, PartialEq, Eq)]
42pub enum Figurative {
43    Zero,
44    Space,
45    HighValue,
46    LowValue,
47    Quote,
48    Null,
49}
50
51#[derive(Clone, Copy, Debug, PartialEq, Eq)]
52pub enum BinOp {
53    Add,
54    Sub,
55    Mul,
56    Div,
57    Pow,
58}
59
60#[derive(Clone, Copy, Debug, PartialEq, Eq)]
61pub enum RelOp {
62    Eq,
63    Ne,
64    Lt,
65    Le,
66    Gt,
67    Ge,
68}
69
70#[derive(Clone, Copy, Debug, PartialEq, Eq)]
71pub enum OpenMode {
72    Input,
73    Output,
74    Extend,
75    InputOutput,
76}
77
78#[derive(Clone, Copy, Debug, PartialEq, Eq)]
79pub enum AcceptFrom {
80    Sysin,
81    Date { four_digit_year: bool },
82    Day { four_digit_year: bool },
83    DayOfWeek,
84    Time,
85}