tremor-script 0.8.0

Tremor Script Interpreter
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
// Copyright 2018-2020, Wayfair GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// We want to keep the names here
#![allow(clippy::module_name_repetitions)]

use super::super::raw::{
    reduce2, BaseExpr, ExprRaw, IdentRaw, ImutExprRaw, ModuleRaw, ScriptRaw, WithExprsRaw,
};
use super::{
    error_generic, error_no_consts, error_no_locals, AggrRegistry, Builder, Cow, GroupBy,
    GroupByInt, HashMap, Helper, ImutExpr, Location, NodeMetas, OperatorDecl, OperatorKind,
    OperatorStmt, Query, Registry, Result, ScriptDecl, ScriptStmt, Select, SelectStmt, Serialize,
    Stmt, StreamStmt, Upable, Value, Warning, WindowDecl, WindowKind, ARGS_CONST_ID,
    GROUP_CONST_ID, WINDOW_CONST_ID,
};
use crate::impl_expr;

fn up_params<'script, 'registry>(
    params: WithExprsRaw<'script>,
    helper: &mut Helper<'script, 'registry>,
) -> Result<HashMap<String, Value<'script>>> {
    params
        .into_iter()
        .map(|(name, value)| Ok((name.id.to_string(), reduce2(value.up(helper)?, &helper)?)))
        .collect()
}

fn up_maybe_params<'script, 'registry>(
    params: Option<WithExprsRaw<'script>>,
    helper: &mut Helper<'script, 'registry>,
) -> Result<Option<HashMap<String, Value<'script>>>> {
    params.map(|params| up_params(params, helper)).transpose()
}

#[derive(Debug, PartialEq, Serialize)]
#[allow(clippy::module_name_repetitions)]
pub struct QueryRaw<'script> {
    pub(crate) config: WithExprsRaw<'script>,
    pub(crate) stmts: StmtsRaw<'script>,
}
impl<'script> QueryRaw<'script> {
    pub(crate) fn up_script<'registry>(
        self,
        mut helper: &mut Helper<'script, 'registry>,
    ) -> Result<(Query<'script>, usize, Vec<Warning>)> {
        let mut stmts = vec![];
        for (_i, e) in self.stmts.into_iter().enumerate() {
            match e {
                StmtRaw::ModuleStmt(m) => {
                    m.define(helper.reg, helper.aggr_reg, &mut vec![], &mut helper)?;
                }
                other => {
                    stmts.push(other.up(&mut helper)?);
                }
            }
        }

        Ok((
            Query {
                config: up_params(self.config, helper)?,
                stmts,
                node_meta: helper.meta.clone(),
                windows: helper.windows.clone(),
                scripts: helper.scripts.clone(),
                operators: helper.operators.clone(),
            },
            helper.locals.len(),
            helper.warnings.clone(),
        ))
    }
}

/// we're forced to make this pub because of lalrpop
#[derive(Clone, Debug, PartialEq, Serialize)]
pub enum StmtRaw<'script> {
    /// we're forced to make this pub because of lalrpop
    WindowDecl(WindowDeclRaw<'script>),
    /// we're forced to make this pub because of lalrpop
    OperatorDecl(Box<OperatorDeclRaw<'script>>),
    /// we're forced to make this pub because of lalrpop
    ScriptDecl(ScriptDeclRaw<'script>),
    /// we're forced to make this pub because of lalrpop
    Stream(StreamStmtRaw),
    /// we're forced to make this pub because of lalrpop
    Operator(OperatorStmtRaw<'script>),
    /// we're forced to make this pub because of lalrpop
    Script(ScriptStmtRaw<'script>),
    /// we're forced to make this pub because of lalrpop
    Select(Box<SelectRaw<'script>>),
    /// we're forced to make this pub because of lalrpop
    ModuleStmt(ModuleStmtRaw<'script>),
    /// we're forced to make this pub because of lalrpop
    Expr(Box<ExprRaw<'script>>),
}

impl<'script> BaseExpr for StmtRaw<'script> {
    fn mid(&self) -> usize {
        0
    }
    fn s(&self, meta: &NodeMetas) -> Location {
        match self {
            StmtRaw::ModuleStmt(s) => s.start,
            StmtRaw::Operator(s) => s.start,
            StmtRaw::OperatorDecl(s) => s.start,
            StmtRaw::Script(s) => s.start,
            StmtRaw::ScriptDecl(s) => s.start,
            StmtRaw::Select(s) => s.start,
            StmtRaw::Stream(s) => s.start,
            StmtRaw::WindowDecl(s) => s.start,
            StmtRaw::Expr(s) => s.s(meta),
        }
    }
    fn e(&self, meta: &NodeMetas) -> Location {
        match self {
            StmtRaw::ModuleStmt(e) => e.end,
            StmtRaw::Operator(e) => e.end,
            StmtRaw::OperatorDecl(e) => e.end,
            StmtRaw::Script(e) => e.end,
            StmtRaw::ScriptDecl(e) => e.end,
            StmtRaw::Select(e) => e.end,
            StmtRaw::Stream(e) => e.end,
            StmtRaw::WindowDecl(e) => e.end,
            StmtRaw::Expr(e) => e.e(meta),
        }
    }
}

impl<'script> Upable<'script> for StmtRaw<'script> {
    type Target = Stmt<'script>;
    fn up<'registry>(self, helper: &mut Helper<'script, 'registry>) -> Result<Self::Target> {
        match self {
            StmtRaw::Select(stmt) => {
                let mut aggregates = Vec::new();
                let mut consts = HashMap::new();
                let mut locals = HashMap::new();
                helper.swap(&mut aggregates, &mut consts, &mut locals);
                let stmt: Select<'script> = stmt.up(helper)?;
                helper.swap(&mut aggregates, &mut consts, &mut locals);
                // We know that select statements have exactly three consts
                let consts = vec![Value::null(), Value::null(), Value::null()];

                Ok(Stmt::Select(SelectStmt {
                    stmt: Box::new(stmt),
                    aggregates,
                    consts,
                    locals: locals.len(),
                    node_meta: helper.meta.clone(),
                }))
            }
            StmtRaw::Stream(stmt) => Ok(Stmt::Stream(stmt.up(helper)?)),
            StmtRaw::OperatorDecl(stmt) => {
                let stmt: OperatorDecl<'script> = stmt.up(helper)?;
                helper
                    .operators
                    .insert(stmt.fqon(&stmt.module), stmt.clone());
                Ok(Stmt::OperatorDecl(stmt))
            }
            StmtRaw::Operator(stmt) => Ok(Stmt::Operator(stmt.up(helper)?)),
            StmtRaw::ScriptDecl(stmt) => {
                let stmt: ScriptDecl<'script> = stmt.up(helper)?;
                helper.scripts.insert(stmt.fqsn(&stmt.module), stmt.clone());
                Ok(Stmt::ScriptDecl(Box::new(stmt)))
            }
            StmtRaw::Script(stmt) => Ok(Stmt::Script(stmt.up(helper)?)),
            StmtRaw::WindowDecl(stmt) => {
                let stmt: WindowDecl<'script> = stmt.up(helper)?;
                helper.windows.insert(stmt.fqwn(&stmt.module), stmt.clone());
                Ok(Stmt::WindowDecl(Box::new(stmt)))
            }
            StmtRaw::ModuleStmt(m) => {
                error_generic(&m, &m, &"Module in wrong place error", &helper.meta)
            }
            StmtRaw::Expr(m) => {
                error_generic(&*m, &*m, &"Expression in wrong place error", &helper.meta)
            }
        }
    }
}

/// we're forced to make this pub because of lalrpop
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct OperatorDeclRaw<'script> {
    pub(crate) start: Location,
    pub(crate) end: Location,
    pub(crate) kind: OperatorKindRaw,
    pub(crate) id: String,
    pub(crate) params: Option<WithExprsRaw<'script>>,
}

impl<'script> Upable<'script> for OperatorDeclRaw<'script> {
    type Target = OperatorDecl<'script>;
    fn up<'registry>(self, helper: &mut Helper<'script, 'registry>) -> Result<Self::Target> {
        let operator_decl = OperatorDecl {
            mid: helper.add_meta_w_name(self.start, self.end, &self.id),
            module: helper.module.clone(),
            id: self.id,
            kind: self.kind.up(helper)?,
            params: up_maybe_params(self.params, helper)?,
        };
        helper
            .operators
            .insert(operator_decl.fqon(&helper.module), operator_decl.clone());
        Ok(operator_decl)
    }
}

#[derive(Debug, PartialEq, Serialize, Clone)]
pub struct ModuleStmtRaw<'script> {
    pub start: Location,
    pub end: Location,
    pub name: IdentRaw<'script>,
    pub stmts: StmtsRaw<'script>,
    pub doc: Option<Vec<Cow<'script, str>>>,
}
impl_expr!(ModuleStmtRaw);

impl<'script> ModuleStmtRaw<'script> {
    pub(crate) fn define<'registry>(
        self,
        reg: &'registry Registry,
        aggr_reg: &'registry AggrRegistry,
        consts: &mut Vec<Value<'script>>,
        mut helper: &mut Helper<'script, 'registry>,
    ) -> Result<()> {
        helper.module.push(self.name.id.to_string());
        for e in self.stmts {
            match e {
                StmtRaw::ModuleStmt(m) => {
                    m.define(reg, aggr_reg, consts, helper)?;
                }
                StmtRaw::Expr(e) => {
                    // We create a 'fake' tremor script module to define
                    // expressions inside this module
                    let expr_m = ModuleRaw {
                        name: self.name.clone(),
                        start: self.start,
                        end: self.end,
                        doc: None,
                        exprs: vec![*e],
                    };
                    // since `ModuleRaw::define` also prepends the module
                    // name we got to remove it prior to calling `define` and
                    // add it back later
                    helper.module.pop();
                    expr_m.define(helper)?;
                    helper.module.push(self.name.id.to_string());
                }
                StmtRaw::WindowDecl(stmt) => {
                    let w = stmt.up(&mut helper)?;
                    helper.windows.insert(w.fqwn(&helper.module), w);
                }
                StmtRaw::ScriptDecl(stmt) => {
                    let s = stmt.up(&mut helper)?;
                    helper.scripts.insert(s.fqsn(&helper.module), s);
                }
                StmtRaw::OperatorDecl(stmt) => {
                    let o = stmt.up(&mut helper)?;
                    helper.operators.insert(o.fqon(&helper.module), o);
                }
                e => {
                    return error_generic(
                        &e,
                        &e,
                        &"Can't have statements inside of query modules",
                        &helper.meta,
                    )
                }
            }
        }
        helper.module.pop();
        Ok(())
    }
}

/// we're forced to make this pub because of lalrpop
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct OperatorStmtRaw<'script> {
    pub(crate) start: Location,
    pub(crate) end: Location,
    pub(crate) module: Vec<IdentRaw<'script>>,
    pub(crate) id: String,
    pub(crate) target: String,
    pub(crate) params: Option<WithExprsRaw<'script>>,
}
impl_expr!(OperatorStmtRaw);

impl<'script> Upable<'script> for OperatorStmtRaw<'script> {
    type Target = OperatorStmt<'script>;
    fn up<'registry>(self, helper: &mut Helper<'script, 'registry>) -> Result<Self::Target> {
        Ok(OperatorStmt {
            mid: helper.add_meta_w_name(self.start, self.end, &self.id),
            id: self.id,
            module: self
                .module
                .into_iter()
                .map(|x| x.id.to_string())
                .collect::<Vec<String>>(),

            target: self.target,
            params: up_maybe_params(self.params, helper)?,
        })
    }
}

/// we're forced to make this pub because of lalrpop
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct ScriptDeclRaw<'script> {
    pub(crate) start: Location,
    pub(crate) end: Location,
    pub(crate) id: String,
    pub(crate) params: Option<WithExprsRaw<'script>>,
    pub(crate) script: ScriptRaw<'script>,
}

impl<'script> Upable<'script> for ScriptDeclRaw<'script> {
    type Target = ScriptDecl<'script>;
    fn up<'registry>(self, helper: &mut Helper<'script, 'registry>) -> Result<Self::Target> {
        // NOTE As we can have module aliases and/or nested modules within script definitions
        // that are private to or inline with the script - multiple script definitions in the
        // same module scope can share the same relative function/const module paths.
        //
        // We add the script name to the scope as a means to distinguish these orthogonal
        // definitions. This is achieved with the push/pop pointcut around the up() call
        // below. The actual function registration occurs in the up() call in the usual way.
        //
        helper.module.push(self.id.to_string());
        let (script, mut warnings) = self.script.up_script(helper)?;
        helper.warnings.append(&mut warnings);

        helper.warnings.sort();
        helper.warnings.dedup();
        let script_decl = ScriptDecl {
            mid: helper.add_meta_w_name(self.start, self.end, &self.id),
            module: helper.module.clone(),
            id: self.id,
            params: up_maybe_params(self.params, helper)?,
            script,
        };
        helper.module.pop();
        helper
            .scripts
            .insert(script_decl.fqsn(&helper.module), script_decl.clone());
        Ok(script_decl)
    }
}

/// we're forced to make this pub because of lalrpop
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct ScriptStmtRaw<'script> {
    pub(crate) start: Location,
    pub(crate) end: Location,
    pub(crate) id: String,
    pub(crate) target: String,
    pub(crate) module: Vec<IdentRaw<'script>>,
    pub(crate) params: Option<WithExprsRaw<'script>>,
}

impl<'script> Upable<'script> for ScriptStmtRaw<'script> {
    type Target = ScriptStmt<'script>;
    fn up<'registry>(self, helper: &mut Helper<'script, 'registry>) -> Result<Self::Target> {
        // let (script, mut warnings) = self.script.up_script(helper.reg, helper.aggr_reg)?;
        // helper.warnings.append(&mut warnings);
        Ok(ScriptStmt {
            mid: helper.add_meta_w_name(self.start, self.end, &self.id),
            id: self.id,
            params: up_maybe_params(self.params, helper)?,
            target: self.target,
            module: self
                .module
                .into_iter()
                .map(|x| x.id.to_string())
                .collect::<Vec<String>>(),
        })
    }
}

/// we're forced to make this pub because of lalrpop
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct WindowDeclRaw<'script> {
    pub(crate) start: Location,
    pub(crate) end: Location,
    pub(crate) id: String,
    pub(crate) kind: WindowKind,
    pub(crate) params: WithExprsRaw<'script>,
    pub(crate) script: Option<ScriptRaw<'script>>,
}

impl<'script> Upable<'script> for WindowDeclRaw<'script> {
    type Target = WindowDecl<'script>;
    fn up<'registry>(self, helper: &mut Helper<'script, 'registry>) -> Result<Self::Target> {
        let mut maybe_script = self.script.map(|s| s.up_script(helper)).transpose()?;
        if let Some((_, ref mut warnings)) = maybe_script {
            helper.warnings.append(warnings);
            helper.warnings.sort();
            helper.warnings.dedup();
        };
        Ok(WindowDecl {
            mid: helper.add_meta_w_name(self.start, self.end, &self.id),
            module: helper.module.clone(),
            id: self.id,
            kind: self.kind,
            params: up_params(self.params, helper)?,
            script: maybe_script.map(|s| s.0),
        })
    }
}

/// we're forced to make this pub because of lalrpop
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct WindowDefnRaw<'script> {
    pub(crate) start: Location,
    pub(crate) end: Location,
    /// Module of the window definition
    pub module: Vec<IdentRaw<'script>>,
    /// Identity of the window definition
    pub id: String,
}

impl<'script> WindowDefnRaw<'script> {
    /// Calculate fully qualified module name
    pub fn fqwn(&self) -> String {
        if self.module.is_empty() {
            self.id.clone()
        } else {
            format!(
                "{}::{}",
                self.module
                    .iter()
                    .map(|x| x.id.to_string())
                    .collect::<Vec<String>>()
                    .join("::"),
                self.id
            )
        }
    }
}

/// we're forced to make this pub because of lalrpop
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct SelectRaw<'script> {
    pub(crate) start: Location,
    pub(crate) end: Location,
    pub(crate) from: (IdentRaw<'script>, Option<IdentRaw<'script>>),
    pub(crate) into: (IdentRaw<'script>, Option<IdentRaw<'script>>),
    pub(crate) target: ImutExprRaw<'script>,
    pub(crate) maybe_where: Option<ImutExprRaw<'script>>,
    pub(crate) maybe_having: Option<ImutExprRaw<'script>>,
    pub(crate) maybe_group_by: Option<GroupByRaw<'script>>,
    pub(crate) windows: Option<Vec<WindowDefnRaw<'script>>>,
}
impl_expr!(SelectRaw);

impl<'script> Upable<'script> for SelectRaw<'script> {
    type Target = Select<'script>;
    fn up<'registry>(self, helper: &mut Helper<'script, 'registry>) -> Result<Self::Target> {
        if !helper.consts.is_empty() {
            return error_no_consts(&(self.start, self.end), &self.target, &helper.meta);
        }
        // reserve const ids for builtin const
        helper
            .consts
            .insert(vec!["window".to_owned()], WINDOW_CONST_ID);
        helper
            .consts
            .insert(vec!["group".to_owned()], GROUP_CONST_ID);
        helper.consts.insert(vec!["args".to_owned()], ARGS_CONST_ID);
        let target = self.target.up(helper)?;

        if helper.has_locals() {
            return error_no_locals(&(self.start, self.end), &target, &helper.meta);
        };

        let maybe_having = self.maybe_having.up(helper)?;
        if helper.has_locals() {
            if let Some(definitely) = maybe_having {
                return error_no_locals(&(self.start, self.end), &definitely, &helper.meta);
            }
        };
        if helper.consts.remove(&vec!["window".to_owned()]) != Some(WINDOW_CONST_ID)
            || helper.consts.remove(&vec!["group".to_owned()]) != Some(GROUP_CONST_ID)
            || helper.consts.remove(&vec!["args".to_owned()]) != Some(ARGS_CONST_ID)
            || !helper.consts.is_empty()
        {
            return error_no_consts(&(self.start, self.end), &target, &helper.meta);
        }

        let maybe_where = self.maybe_where.up(helper)?;
        if helper.has_locals() {
            if let Some(definitely) = maybe_where {
                return error_no_locals(&(self.start, self.end), &definitely, &helper.meta);
            }
        };
        let maybe_group_by = self.maybe_group_by.up(helper)?;
        if helper.has_locals() {
            if let Some(definitely) = maybe_group_by {
                return error_no_locals(&(self.start, self.end), &definitely, &helper.meta);
            }
        };

        let windows = self.windows.unwrap_or_default();

        let from = match self.from {
            (stream, None) => {
                let mut port = stream.clone();
                port.id = Cow::Borrowed("out");
                (stream, port)
            }
            (stream, Some(port)) => (stream, port),
        };
        let into = match self.into {
            (stream, None) => {
                let mut port = stream.clone();
                port.id = Cow::Borrowed("in");
                (stream, port)
            }
            (stream, Some(port)) => (stream, port),
        };
        Ok(Select {
            mid: helper.add_meta(self.start, self.end),
            from: (from.0.up(helper)?, from.1.up(helper)?),
            into: (into.0.up(helper)?, into.1.up(helper)?),
            target: ImutExpr(target),
            maybe_where: maybe_where.map(ImutExpr),
            maybe_having: maybe_having.map(ImutExpr),
            maybe_group_by,
            windows,
        })
    }
}

/// we're forced to make this pub because of lalrpop
#[derive(Clone, Debug, PartialEq, Serialize)]
pub enum GroupByRaw<'script> {
    /// we're forced to make this pub because of lalrpop
    Expr {
        /// we're forced to make this pub because of lalrpop
        start: Location,
        /// we're forced to make this pub because of lalrpop
        end: Location,
        /// we're forced to make this pub because of lalrpop
        expr: ImutExprRaw<'script>,
    },
    /// we're forced to make this pub because of lalrpop
    Set {
        /// we're forced to make this pub because of lalrpop
        start: Location,
        /// we're forced to make this pub because of lalrpop
        end: Location,
        /// we're forced to make this pub because of lalrpop
        items: Vec<GroupByRaw<'script>>,
    },
    /// we're forced to make this pub because of lalrpop
    Each {
        /// we're forced to make this pub because of lalrpop
        start: Location,
        /// we're forced to make this pub because of lalrpop
        end: Location,
        /// we're forced to make this pub because of lalrpop
        expr: ImutExprRaw<'script>,
    },
}

impl<'script> Upable<'script> for GroupByRaw<'script> {
    type Target = GroupBy<'script>;
    fn up<'registry>(self, helper: &mut Helper<'script, 'registry>) -> Result<Self::Target> {
        Ok(match self {
            GroupByRaw::Expr { start, end, expr } => GroupBy(GroupByInt::Expr {
                mid: helper.add_meta(start, end),
                expr: expr.up(helper)?,
            }),
            GroupByRaw::Each { start, end, expr } => GroupBy(GroupByInt::Each {
                mid: helper.add_meta(start, end),
                expr: expr.up(helper)?,
            }),
            GroupByRaw::Set { start, end, items } => GroupBy(GroupByInt::Set {
                mid: helper.add_meta(start, end),
                items: items.up(helper)?,
            }),
        })
    }
}

/// we're forced to make this pub because of lalrpop
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct OperatorKindRaw {
    pub(crate) start: Location,
    pub(crate) end: Location,
    pub(crate) module: String,
    pub(crate) operation: String,
}
impl BaseExpr for OperatorKindRaw {
    fn s(&self, _meta: &NodeMetas) -> Location {
        self.start
    }
    fn e(&self, _meta: &NodeMetas) -> Location {
        self.end
    }
    fn mid(&self) -> usize {
        0
    }
}

impl<'script> Upable<'script> for OperatorKindRaw {
    type Target = OperatorKind;
    fn up<'registry>(self, helper: &mut Helper<'script, 'registry>) -> Result<Self::Target> {
        Ok(OperatorKind {
            mid: helper.add_meta_w_name(
                self.start,
                self.end,
                &format!("{}::{}", self.module, self.operation),
            ),
            module: self.module,
            operation: self.operation,
        })
    }
}

/// we're forced to make this pub because of lalrpop
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct StreamStmtRaw {
    pub(crate) start: Location,
    pub(crate) end: Location,
    pub(crate) id: String,
}
impl<'script> Upable<'script> for StreamStmtRaw {
    type Target = StreamStmt;
    fn up<'registry>(self, helper: &mut Helper<'script, 'registry>) -> Result<Self::Target> {
        Ok(StreamStmt {
            mid: helper.add_meta_w_name(self.start, self.end, &self.id),
            id: self.id,
        })
    }
}

pub type StmtsRaw<'script> = Vec<StmtRaw<'script>>;