1use crate::error::SourceLoc;
8
9#[derive(Debug, Clone)]
11pub struct Program {
12 pub clauses: Vec<Clause>,
13}
14
15#[derive(Debug, Clone)]
17pub struct Clause {
18 pub kind: ClauseKind,
19 pub loc: SourceLoc,
20}
21
22#[derive(Debug, Clone)]
23pub enum ClauseKind {
24 Label(String),
26
27 Assignment { target: AssignTarget, expr: Expr },
29
30 Say(Expr),
32
33 Call { name: String, args: Vec<Expr> },
35
36 Do(Box<DoBlock>),
38
39 If {
41 condition: Expr,
42 then_clause: Box<Clause>,
43 else_clause: Option<Box<Clause>>,
44 },
45
46 Select {
48 when_clauses: Vec<(Expr, Vec<Clause>)>,
49 otherwise: Option<Vec<Clause>>,
50 },
51
52 Return(Option<Expr>),
54
55 Exit(Option<Expr>),
57
58 Iterate(Option<String>),
60
61 Leave(Option<String>),
63
64 Nop,
66
67 Parse {
69 upper: bool,
70 source: ParseSource,
71 template: ParseTemplate,
72 },
73
74 Signal(SignalAction),
76
77 Numeric(NumericSetting),
79
80 Address(AddressAction),
82
83 Drop(Vec<String>),
85
86 Procedure(Option<Vec<String>>),
88
89 Push(Option<Expr>),
91
92 Pull(Option<ParseTemplate>),
94
95 Queue(Option<Expr>),
97
98 Trace(Expr),
100
101 Interpret(Expr),
103
104 Arg(ParseTemplate),
106
107 Command(Expr),
109}
110
111#[derive(Debug, Clone)]
113pub enum AssignTarget {
114 Simple(String),
116 Stem {
118 stem: String,
119 tail: Vec<TailElement>,
120 },
121}
122
123#[derive(Debug, Clone)]
125pub enum TailElement {
126 Const(String),
127 Var(String),
128}
129
130#[derive(Debug, Clone)]
132pub struct DoBlock {
133 pub kind: DoKind,
134 pub body: Vec<Clause>,
135 pub name: Option<String>,
137}
138
139#[derive(Debug, Clone)]
140pub enum DoKind {
141 Simple,
143 Forever,
145 Count(Expr),
147 While(Expr),
149 Until(Expr),
151 Controlled(Box<ControlledLoop>),
153}
154
155#[derive(Debug, Clone)]
157pub struct ControlledLoop {
158 pub var: String,
159 pub start: Expr,
160 pub to: Option<Expr>,
161 pub by: Option<Expr>,
162 pub r#for: Option<Expr>,
163 pub while_cond: Option<Expr>,
164 pub until_cond: Option<Expr>,
165}
166
167#[derive(Debug, Clone)]
169pub enum ParseSource {
170 Arg,
172 Pull,
174 Source,
176 Version,
178 LineIn,
180 Value(Expr),
182 Var(String),
184}
185
186#[derive(Debug, Clone)]
188pub struct ParseTemplate {
189 pub elements: Vec<TemplateElement>,
190}
191
192#[derive(Debug, Clone)]
193pub enum TemplateElement {
194 Variable(String),
196 Literal(String),
198 AbsolutePos(Expr),
200 RelativePos(i32),
202 VariablePattern(String),
204 Dot,
206 Comma,
208}
209
210#[derive(Debug, Clone)]
212pub enum SignalAction {
213 Label(String),
215 Value(Expr),
217 On {
219 condition: Condition,
220 name: Option<String>,
221 },
222 Off(Condition),
224}
225
226#[derive(Debug, Clone, PartialEq, Eq, Hash)]
228pub enum Condition {
229 Error,
230 Failure,
231 Halt,
232 NoValue,
233 NotReady,
234 Syntax,
235 LostDigits,
236}
237
238#[derive(Debug, Clone)]
240pub enum NumericSetting {
241 Digits(Option<Expr>),
242 Form(NumericFormSetting),
243 Fuzz(Option<Expr>),
244}
245
246#[derive(Debug, Clone)]
247pub enum NumericFormSetting {
248 Scientific,
249 Engineering,
250 Value(Expr),
251}
252
253#[derive(Debug, Clone)]
255pub enum AddressAction {
256 SetEnvironment(String),
258 Temporary { environment: String, command: Expr },
260 Value(Expr),
262}
263
264#[derive(Debug, Clone)]
266pub enum Expr {
267 StringLit(String),
269 Number(String),
271 Symbol(String),
273 Compound {
275 stem: String,
276 tail: Vec<TailElement>,
277 },
278 BinOp {
280 left: Box<Expr>,
281 op: BinOp,
282 right: Box<Expr>,
283 },
284 UnaryOp { op: UnaryOp, operand: Box<Expr> },
286 FunctionCall { name: String, args: Vec<Expr> },
288 Paren(Box<Expr>),
290}
291
292#[derive(Debug, Clone, Copy, PartialEq, Eq)]
293pub enum BinOp {
294 Add,
295 Sub,
296 Mul,
297 Div,
298 IntDiv,
299 Remainder,
300 Power,
301 Concat, ConcatBlank, Eq,
306 NotEq,
307 Gt,
308 Lt,
309 GtEq,
310 LtEq,
311 StrictEq,
312 StrictNotEq,
313 StrictGt,
314 StrictLt,
315 StrictGtEq,
316 StrictLtEq,
317
318 And,
320 Or,
321 Xor,
322}
323
324#[derive(Debug, Clone, Copy, PartialEq, Eq)]
325pub enum UnaryOp {
326 Plus,
327 Minus,
328 Not,
329}