inc 0.1.3

Incremental approach to compiler construction
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
//! A scheme parser in nom.
//!
//! Describes the [formal BNF grammar][grammar] in Rust as closely as possible
//! using the nom parser combinator library.
//!
//! ✏ This module is heavily documented and the order of declaration follow the
//! grammar; so the source best read sequentially in the declared order rather
//! than alphabetically here.
//!
//! See [lisper][lisper] for a similar Haskell implementation.
//!
//! [grammar]: http://www.scheme.com/tspl2d/grammar.html
//! [lisper]: https://github.com/jaseemabid/lisper/blob/master/src/Lisper/Parser.hs
use super::core::*;
use nom::{
    branch::alt,
    bytes::complete::{is_not, tag},
    character::complete::{multispace0 as space0, multispace1 as space1, *},
    combinator::{map, opt, value},
    multi::*,
    sequence::*,
    IResult,
};
use std::str;

/// A program consists of a sequence of definitions and expressions.
///
/// ```BNF
/// <program>  → <form>*
/// <form>     → <definition> | <expression>
/// ```
fn program(i: &str) -> IResult<&str, Vec<Expr>> {
    many1(delimited(space0, expression, space0))(i)
}

// pub fn form(i: &str) -> IResult<&str, Expr> {
//     alt((definition, expression))(i)
// }

/// Definitions include various forms of declarations
///
/// Definitions include variable and syntax definitions, begin forms containing
/// zero or more definitions, let-syntax and letrec-syntax forms expanding into
/// zero or more definitions, and derived definitions. Derived definitions are
/// syntactic extensions that expand into some form of definition. A transformer
/// expression is a syntax-rules form or some other expression that produces a
/// transformer.
///
/// ```BNF
///
/// <definition> → <variable definition>
///              | <syntax definition>
///              | (begin <definition>*)
///              | (let-syntax (<syntax binding>*) <definition>*)
///              | (letrec-syntax (<syntax binding>*) <definition>*)
///              | <derived definition>
///
/// <variable definition> → (define <variable> <expression>)
///                       | (define (<variable> <variable>*) <body>)
///                       | (define (<variable> <variable>* . <variable>) <body>)
///
/// <variable>          → <identifier>
/// <body>              → <definition>* <expression>+
/// <syntax definition> → (define-syntax <keyword> <transformer expression>)
/// <keyword>           → <identifier>
/// <syntax binding>    → (<keyword> <transformer expression>)
/// ```
// fn definition(i: &str) -> IResult<&str, Expr> {
//     alt((let_syntax, if_syntax))(i)
// }

/// `(let-syntax (<syntax binding>*) <expression>+)`
fn let_syntax(i: &str) -> IResult<&str, Expr> {
    let (i, _) = tuple((open, tag("let"), space1))(i)?;
    let (i, bindings) = delimited(open, many0(binding), close)(i)?;
    let (i, body) = delimited(space0, many1(terminated(expression, space0)), space0)(i)?;
    let (i, _) = close(i)?;

    Ok((i, Expr::Let { bindings, body }))
}

/// `named → (name value)`
fn binding(i: &str) -> IResult<&str, (String, Expr)> {
    let (i, (_, name, _, value, _, _)) =
        tuple((open, identifier, space1, expression, close, space0))(i)?;

    Ok((i, (name, value)))
}

/// Core expressions
///
/// Expressions include core expressions, let-syntax or letrec-syntax forms
/// expanding into a sequence of one or more expressions, and derived
/// expressions. The core expressions are self-evaluating constants, variable
/// references, applications, and quote, lambda, if, and set! expressions.
/// Derived expressions include and, begin, case, cond, delay, do, let, let*,
/// letrec, or, and quasiquote expressions plus syntactic extensions that expand
/// into some form of expression.
///
/// ```BNF
/// <expression>  → <constant>
///               | <variable>
///               | (quote <datum>) | ' <datum>
///               | (lambda <formals> <body>)
///               | (if <expression> <expression> <expression>)
///               | (if <expression> <expression>)
///               | (set! <variable> <expression>)
///               | <application>
///               | (let-syntax (<syntax binding>*) <expression>+)
///               | (letrec-syntax (<syntax binding>*) <expression>+)
///               | <derived expression>
///
/// <constant>    → <boolean> | <number> | <character> | <string>
/// <formals>     → <variable> | (<variable>*) | (<variable>+ . <variable>)
/// <application> → (<expression> <expression>*)
/// ```
fn expression(i: &str) -> IResult<&str, Expr> {
    alt((constant, variable, quote, lambda_syntax, if_syntax, let_syntax, application))(i)
}

/// `(lambda <formals> <body>)`
fn lambda_syntax(i: &str) -> IResult<&str, Expr> {
    let (i, (_, _, _, formals, _, body, _, _)) =
        tuple((open, tag("lambda"), space1, formals, space0, body, space0, close))(i)?;

    Ok((i, Expr::Lambda(Code { name: None, formals, body, free: vec![] })))
}

/// `(if <expression> <expression> <expression>) | (if <expression> <expression>)`
fn if_syntax(i: &str) -> IResult<&str, Expr> {
    let (i, (_, _, _, pred, _, then, alt, _, _)) = tuple((
        open,
        tag("if"),
        space1,
        expression,
        space1,
        expression,
        opt(tuple((space1, expression))),
        space0,
        close,
    ))(i)?;

    Ok((i, Expr::Cond { pred: box pred, then: box then, alt: alt.map({ |(_, a)| box a }) }))
}

/// variable is an identifier
fn variable(i: &str) -> IResult<&str, Expr> {
    map(identifier, Expr::Identifier)(i)
}

/// `<formals>     → <variable> | (<variable>*) | (<variable>+ . <variable>)`
fn formals(i: &str) -> IResult<&str, Vec<String>> {
    alt((
        map(identifier, |s| vec![s]),
        delimited(open, many0(terminated(identifier, space0)), close),
    ))(i)
}

/// `<body> → <definition>* <expression>+`
fn body(i: &str) -> IResult<&str, Vec<Expr>> {
    let (i, mut es) = many1(expression)(i)?;

    let mut v = Vec::new();
    v.append(&mut es);
    Ok((i, v))
}

/// (quote <datum>) | '<datum>
// Note: This parser only handles simple quoted symbols for now
fn quote(i: &str) -> IResult<&str, Expr> {
    map(tuple((tag("\'"), identifier)), { |(_, i)| Expr::Symbol(i) })(i)
}

/// `<constant> → <boolean> | <number> | <character> | <string>`
fn constant(i: &str) -> IResult<&str, Expr> {
    alt((
        (map(tag("()"), { |_| Expr::Nil })),
        (map(ascii, Expr::Char)),
        (map(boolean, Expr::Boolean)),
        (map(number, Expr::Number)),
        (map(string, Expr::Str)),
    ))(i)
}

/// `<application> → (<expression> <expression>*)`
fn application(i: &str) -> IResult<&str, Expr> {
    let (i, (_, a, _, mut b, _)) =
        tuple((open, expression, space0, many0(terminated(expression, space0)), close))(i)?;

    let mut v = vec![a];
    v.append(&mut b);

    Ok((i, Expr::List(v)))
}

/// Identifiers may denote variables, keywords, or symbols depending upon
/// context.
///
/// They are formed from sequences of letters, digits, and special
/// characters. With three exceptions, identifiers cannot begin with a
/// character that can also begin a number, i.e., they cannot begin with .,
/// +, -, or a digit. The three exceptions are the identifiers ..., +, and -.
/// Case is insignificant in symbols so that, for example, newspaper,
/// NewsPaper, and NEWSPAPER all represent the same identifier.
///
/// ```BNF
/// <identifier> → <initial> <subsequent>* | + | - | ...
/// <initial>    → <letter> | ! | $ | % | & | * | / | : | < | = | > | ? | ~ | _ | ^
/// <subsequent> → <initial> | <digit> | . | + | -
/// <letter>     → a | b | ... | z
/// <digit>      → 0 | 1 | ... | 9
/// ```
fn identifier(i: &str) -> IResult<&str, String> {
    alt((
        value(String::from("+"), tag("+")),
        value(String::from("-"), tag("-")),
        value(String::from("..."), tag("...")),
        map(tuple((initial, many0(subsequent))), |(i, s)| {
            // Convert a vector of chars to string
            // https://doc.rust-lang.org/stable/core/iter/trait.Iterator.html#method.collect
            format!("{}{}", i, s.iter().collect::<String>())
        }),
    ))(i)
}

fn initial(i: &str) -> IResult<&str, char> {
    alt((letter, symbol))(i)
}

fn subsequent(i: &str) -> IResult<&str, char> {
    alt((initial, digit, one_of(".+-")))(i)
}

fn symbol(i: &str) -> IResult<&str, char> {
    one_of("!$%&*/:<=>?~_^")(i)
}

fn letter(i: &str) -> IResult<&str, char> {
    one_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")(i)
}

fn digit(i: &str) -> IResult<&str, char> {
    one_of("0123456789")(i)
}

/// Data include booleans, numbers, characters, strings, symbols, lists, and
/// vectors.
///
/// Case is insignificant in the syntax for booleans, numbers, and
/// character names, but it is significant in other character constants and
/// in strings. For example, #T is equivalent to #t, #E1E3 is equivalent to
/// #e1e3, #X2aBc is equivalent to #x2abc, and #\NewLine is equivalent to
/// #\newline; but #\A is distinct from #\a and "String" is distinct from
/// string".
///
/// ```BNF
/// <datum>            → <boolean> | <number> | <character> | <string> | <symbol> | <list> | <vector>
/// <boolean>          → #t | #f
/// <number>           → <num 2> | <num 8> | <num 10> | <num 16>
/// <character>        → #\ <any character> | #\newline | #\space
/// <string>           → " <string character>* "
/// <string character> → \" | \\ | <any character other than" or \>
/// <symbol>           →  <identifier>
/// <list>             →  (<datum>*) | (<datum>+ . <datum>) | <abbreviation>
/// <abbreviation>     →  ' <datum> | ` <datum> | , <datum> | ,@ <datum>
/// <vector>           → #(<datum>*)
/// ```
#[cfg(test)]
fn datum(i: &str) -> IResult<&str, Expr> {
    alt((
        (map(tag("()"), { |_| Expr::Nil })),
        (map(boolean, Expr::Boolean)),
        (map(ascii, Expr::Char)),
        (map(number, Expr::Number)),
        (map(identifier, Expr::Identifier)),
        (map(string, Expr::Str)),
        list,
    ))(i)
}

fn boolean(i: &str) -> IResult<&str, bool> {
    alt((value(true, tag("#t")), value(false, tag("#f"))))(i)
}

fn sign(i: &str) -> IResult<&str, i64> {
    alt((value(-1, tag("-")), value(1, tag("+"))))(i)
}

fn number(i: &str) -> IResult<&str, i64> {
    let (i, s) = opt(sign)(i)?;
    let (i, n) = digit1(i)?;

    // TODO: Propagate this error up rather than panic
    let n = n.parse::<i64>().expect(&format!("Failed to parse digits into i64: `{:?}`\n", n)[..]);

    Ok((i, s.unwrap_or(1) * n))
}

/// ASCII Characters for now
fn ascii(i: &str) -> IResult<&str, u8> {
    // $ man ascii
    alt((
        value(9 as u8, tag(r"#\tab")),
        value(10 as u8, tag(r"#\newline")),
        value(13 as u8, tag(r"#\return")),
        value(32 as u8, tag(r"#\space")),
        // Picking the first byte is quite unsafe, fix for UTF8
        preceded(tag(r"#\"), map(anychar, { |c: char| c as u8 })),
    ))(i)
}

fn string(i: &str) -> IResult<&str, String> {
    let q = "\"";
    let (i, s) = delimited(tag(q), opt(is_not(q)), tag(q))(i)?;

    Ok((i, s.map_or(String::from(""), |s| s.to_string())))
}

/// `<list> → (<datum>*) | (<datum>+ . <datum>) | <abbreviation>`
#[cfg(test)]
fn list(i: &str) -> IResult<&str, Expr> {
    let (i, _) = tuple((char('('), space0))(i)?;
    let (i, elems) = separated_list(space1, datum)(i)?;
    let (i, _) = tuple((space0, char(')')))(i)?;

    if elems.is_empty() {
        Ok((i, Expr::Nil))
    } else {
        Ok((i, Expr::List(elems)))
    }
}

fn open(i: &str) -> IResult<&str, ()> {
    let (i, _) = tuple((char('('), space0))(i)?;
    Ok((i, ()))
}

fn close(i: &str) -> IResult<&str, ()> {
    let (i, _) = tuple((space0, char(')')))(i)?;
    Ok((i, ()))
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::core::Expr::*;
    use pretty_assertions::assert_eq;

    // OK consumes all of the input and succeeds
    fn ok<T, E>(t: T) -> IResult<&'static str, T, E> {
        Ok(("", t))
    }

    // Partial consumes some of the input and succeeds
    fn partial<T, E>(rest: &str, t: T) -> IResult<&str, T, E> {
        Ok((rest, t))
    }

    // Fail denotes a parser failing without consuming any of its input
    fn fail<T>(i: &str) -> IResult<&str, T, (&str, nom::error::ErrorKind)> {
        Err(nom::Err::Error((i, nom::error::ErrorKind::Tag)))
    }

    #[test]
    fn assorted() {
        assert_eq!(ok(true), boolean("#t"));
        assert_eq!(ok(false), boolean("#f"));
        assert_eq!(fail("A"), boolean("A"));

        assert_eq!(ok('?'), symbol("?"));

        assert_eq!(ok(42), number("42"));
        assert_eq!(ok(-42), number("-42"));

        assert_eq!(ok(b'j'), ascii("#\\j"));
        assert_eq!(ok(b'^'), ascii("#\\^"));

        // Character parser must not consume anything unless it starts with
        // an explicit tag.
        assert_eq!(fail("test"), ascii("test"));
    }

    #[test]
    fn identifiers() {
        assert_eq!(ok(String::from("x")), identifier("x"));
        assert_eq!(ok(String::from("one")), identifier("one"));
        assert_eq!(ok(String::from("!bang")), identifier("!bang"));
        assert_eq!(ok(String::from("a->b")), identifier("a->b"));
        assert_eq!(ok(String::from("+")), identifier("+"));
        assert_eq!(ok(String::from("-")), identifier("-"));
        assert_eq!(ok(String::from("i64")), identifier("i64"));

        // -> is not an identifier, consume the - as an id and return the >
        assert_eq!(partial(">", String::from("-")), identifier("->"));

        // Identifiers must split at space and not consume anything
        // afterwards
        assert_eq!(partial(" b", String::from("a")), identifier("a b"));

        // Quoted symbols are not identifiers
        assert_eq!(partial("'woo", String::from("a")), identifier("a'woo"));
    }

    // #[test]
    // fn unicode() {
    //     assert_eq!(fail(("അ")), identifier(("അ")))
    // }

    #[test]
    fn data() {
        assert_eq!(ok(Nil), datum("()"));
        assert_eq!(ok("one".into()), datum("one"));
        assert_eq!(ok(42.into()), datum("42"));
    }

    #[test]
    fn strings() {
        assert_eq!(ok(Str("hello world".into())), datum("\"hello world\""));
        assert_eq!(ok(Str("മലയാളം".into())), datum("\"മലയാളം\""));

        assert_eq!(ok(Str("Unicode 😱 ⌘".into())), datum("\"Unicode 😱 ⌘\""));

        assert_eq!(ok(Str("".into())), datum("\"\""));
    }

    #[test]
    fn lists() {
        assert_eq!(ok(List(vec!["+".into(), 1.into()])), list("(+ 1)"));

        assert_eq!(
            ok(List(vec![1.into(), 2.into(), 3.into(), "a".into(), "b".into(), "c".into()])),
            list("(1 2 3 a b c)")
        );

        assert_eq!(
            ok(List(vec!["inc".into(), List(vec!["inc".into(), 42.into()]),],)),
            list("(inc (inc 42))")
        );

        // Lists should throw away all spaces in between
        assert_eq!(program("(   +   1 )"), program("(+ 1)"));
    }

    #[test]
    fn binary() {
        assert_eq!(ok(List(vec!["+".into(), "x".into(), 1776.into()])), list("(+ x 1776)"));

        assert_eq!(
            ok(List(
                vec!["+".into(), "x".into(), List(vec!["*".into(), "a".into(), "b".into()],),],
            )),
            list("(+ x (* a b))")
        );
    }

    #[test]
    fn top() {
        assert_eq!(ok(vec![true.into()]), program("#t"));
        assert_eq!(ok(vec![false.into()]), program("#f"));

        assert_eq!(ok(vec!['?'.into()]), program("#\\?"));

        assert_eq!(ok(vec![42.into()]), program("42"));
        assert_eq!(ok(vec![(-42).into()]), program("-42"));

        assert_eq!(ok(vec!['j'.into()]), program("#\\j"));
        assert_eq!(ok(vec!['^'.into()]), program("#\\^"));
    }

    #[test]
    fn let_syntax() {
        let p1 = "(let ((x 1) (y 2)) (+ x y))";
        let p2 = "(let ((x 1)) (let ((x 2)) #t) x)";

        let e1 = Let {
            bindings: vec![("x".to_string(), Number(1)), ("y".to_string(), Number(2))],
            body: vec![List(vec![("+".into()), ("x".into()), ("y".into())])],
        };

        let e2 = Let {
            bindings: vec![("x".to_string(), Number(1))],
            body: vec![
                Let { bindings: vec![("x".to_string(), Number(2))], body: vec![true.into()] },
                "x".into(),
            ],
        };

        assert_eq!(ok(e1), super::let_syntax(p1));
        assert_eq!(ok(e2), super::let_syntax(p2));

        assert!(program("(let ((x (let ((y (+ 1 2))) (* y y)))) (cons x (+ x x)))").is_ok());

        assert!(program("(let ((x (let ((y 3)) (* y y)))) (cons x (+ x x)))").is_ok());
    }

    #[test]
    fn if_syntax() {
        let prog = "(if #t 12 13)";
        let exp = Cond { pred: box true.into(), then: box 12.into(), alt: Some(box 13.into()) };

        assert_eq!(ok(vec![exp]), program(prog));

        let prog = "(if #t 14)";
        let exp = Cond { pred: box true.into(), then: box 14.into(), alt: None };

        assert_eq!(ok(vec![exp]), program(prog));

        let prog = "(if (zero? x) 1 (* x (f (dec x))))";
        let exp = Cond {
            pred: box List(vec!["zero?".into(), "x".into()]),
            then: box 1.into(),
            alt: Some(box List(vec![
                "*".into(),
                "x".into(),
                List(vec!["f".into(), List(vec!["dec".into(), "x".into()])]),
            ])),
        };

        assert_eq!(ok(vec![exp]), program(prog));
    }

    #[test]
    fn application() {
        assert_eq!(ok(List(vec!["f".into(), "x".into()])), super::application("(f x)"));
        assert_eq!(ok(List(vec!["f".into()])), super::application("(f)"));
    }

    #[test]
    fn quotes() {
        let p = super::program("(symbol=? 'one 'two)");
        let e = vec![List(vec![
            Identifier("symbol=?".into()),
            Symbol("one".into()),
            Symbol("two".into()),
        ])];

        assert_eq!(ok(e), p);
    }

    #[test]
    fn lambda_syntax() {
        let prog = "(lambda () 1)";
        let exp = Lambda(Code { name: None, formals: vec![], body: vec![Number(1)], free: vec![] });

        assert_eq!(ok(vec![exp]), program(prog));

        let prog = "(lambda (a b ) a)";
        let exp = Lambda(Code {
            name: None,
            formals: vec!["a".into(), "b".into()],
            free: vec![],
            body: vec![("a".into())],
        });

        assert_eq!(ok(vec![exp]), program(prog));
        // assert_eq!(ok(exp), super::lambda_syntax(prog));

        let prog = "(lambda (a b) (+ b a))";
        let exp = Lambda(Code {
            name: None,
            free: vec![],
            formals: vec!["a".into(), "b".into()],
            body: vec![Expr::List(vec!["+".into(), "b".into(), "a".into()])],
        });

        assert_eq!(ok(vec![exp]), program(prog));

        let prog = "(lambda a a)";
        let exp = Lambda(Code {
            name: None,
            formals: vec!["a".into()],
            free: vec![],
            body: vec![("a".into())],
        });

        assert_eq!(ok(vec![exp]), program(prog));

        let prog = "(lambda (x) (if #t 1 2))";
        let exp = Lambda(Code {
            name: None,
            formals: vec!["x".into()],
            free: vec![],
            body: vec![Cond { pred: box true.into(), then: box 1.into(), alt: Some(box 2.into()) }],
        });

        assert_eq!(ok(vec![exp]), program(prog));

        let prog = "(lambda (x) (if (zero? x) 1 (* x (f (dec x)))))";
        let exp = Lambda(Code {
            name: None,
            formals: vec!["x".into()],
            free: vec![],
            body: vec![Cond {
                pred: box List(vec![("zero?".into()), ("x".into())]),
                then: box 1.into(),
                alt: Some(box List(vec![
                    "*".into(),
                    "x".into(),
                    List(vec!["f".into(), List(vec!["dec".into(), "x".into()])]),
                ])),
            }],
        });

        assert_eq!(ok(vec![exp]), program(prog));
    }
}

/// Parse a single expression for testing, return or panic
#[cfg(test)]
pub fn parse1<'a>(i: &'a str) -> Expr {
    match expression(i) {
        Ok((_rest, e)) => e,
        Err(e) => panic!("Failed to parse `{}`: {:?}", i, e),
    }
}

/// Parse the whole program
pub fn parse<'a>(i: &'a str) -> Result<Vec<Expr>, Error<'a>> {
    match program(i) {
        Ok((_rest, expressions)) => Ok(expressions),
        Err(e) => Err(Error::Parser(e)),
    }
}