1use crate::parse::ast::AST;
2use crate::parse::ast::Node;
3use crate::parse::expression::parse_inner_expression;
4use crate::parse::iterator::LexIterator;
5use crate::parse::lex::token::Token;
6use crate::parse::result::ParseResult;
7
8macro_rules! inner_bin_op {
9    ($it:expr, $start:expr, $fun:path, $ast:ident, $left:expr, $msg:expr) => {{
10        $it.eat(&Token::$ast, "operation")?;
11        let right = $it.parse(&$fun, $msg, $start)?;
12        let node = Node::$ast { left: $left, right: right.clone() };
13        Ok(Box::from(AST::new($start.union(right.pos), node)))
14    }};
15}
16
17pub fn parse_expression(it: &mut LexIterator) -> ParseResult { parse_level_7(it) }
30
31fn parse_level_7(it: &mut LexIterator) -> ParseResult {
32    let start = it.start_pos("operation (7)")?;
33    let arithmetic = it.parse(&parse_level_6, "operation", start)?;
34    macro_rules! bin_op {
35        ($it:expr, $fun:path, $ast:ident, $arithmetic:expr, $msg:expr) => {{
36            inner_bin_op!($it, start, $fun, $ast, $arithmetic, $msg)
37        }};
38    }
39
40    it.peek(
41        &|it, lex| match lex.token {
42            Token::And => bin_op!(it, parse_level_7, And, arithmetic.clone(), "and"),
43            Token::Or => bin_op!(it, parse_level_7, Or, arithmetic.clone(), "or"),
44            Token::Question => bin_op!(it, parse_level_7, Question, arithmetic.clone(), "question"),
45            _ => Ok(arithmetic.clone())
46        },
47        Ok(arithmetic.clone()),
48    )
49}
50
51fn parse_level_6(it: &mut LexIterator) -> ParseResult {
52    let start = it.start_pos("operation (6)")?;
53    let arithmetic = it.parse(&parse_level_5, "operation", start)?;
54    macro_rules! bin_op {
55        ($it:expr, $fun:path, $ast:ident, $arithmetic:expr, $msg:expr) => {{
56            inner_bin_op!($it, start, $fun, $ast, $arithmetic, $msg)
57        }};
58    }
59
60    it.peek(
61        &|it, lex| match lex.token {
62            Token::Ge => bin_op!(it, parse_level_6, Ge, arithmetic.clone(), "greater"),
63            Token::Geq => bin_op!(it, parse_level_6, Geq, arithmetic.clone(), "greater, equal"),
64            Token::Le => bin_op!(it, parse_level_6, Le, arithmetic.clone(), "less"),
65            Token::Leq => bin_op!(it, parse_level_6, Leq, arithmetic.clone(), "less, equal"),
66            Token::Eq => bin_op!(it, parse_level_6, Eq, arithmetic.clone(), "equal"),
67            Token::Neq => bin_op!(it, parse_level_6, Neq, arithmetic.clone(), "not equal"),
68            Token::Is => bin_op!(it, parse_level_6, Is, arithmetic.clone(), "is"),
69            Token::IsN => bin_op!(it, parse_level_6, IsN, arithmetic.clone(), "is not"),
70            Token::IsA => bin_op!(it, parse_level_6, IsA, arithmetic.clone(), "is a"),
71            Token::IsNA => bin_op!(it, parse_level_6, IsNA, arithmetic.clone(), "is not a"),
72            Token::In => bin_op!(it, parse_level_6, In, arithmetic.clone(), "in"),
73            _ => Ok(arithmetic.clone())
74        },
75        Ok(arithmetic.clone()),
76    )
77}
78
79fn parse_level_5(it: &mut LexIterator) -> ParseResult {
80    let start = it.start_pos("operation (5)")?;
81    let arithmetic = it.parse(&parse_level_4, "operation", start)?;
82    macro_rules! bin_op {
83        ($it:expr, $fun:path, $ast:ident, $arithmetic:expr, $msg:expr) => {{
84            inner_bin_op!($it, start, $fun, $ast, $arithmetic, $msg)
85        }};
86    }
87
88    it.peek(
89        &|it, lex| match lex.token {
90            Token::BLShift =>
91                bin_op!(it, parse_level_5, BLShift, arithmetic.clone(), "bitwise left shift"),
92            Token::BRShift =>
93                bin_op!(it, parse_level_5, BRShift, arithmetic.clone(), "bitwise right shift"),
94            Token::BAnd => bin_op!(it, parse_level_5, BAnd, arithmetic.clone(), "bitwise and"),
95            Token::BOr => bin_op!(it, parse_level_5, BOr, arithmetic.clone(), "bitwise or"),
96            Token::BXOr => bin_op!(it, parse_level_5, BXOr, arithmetic.clone(), "bitwise xor"),
97            _ => Ok(arithmetic.clone())
98        },
99        Ok(arithmetic.clone()),
100    )
101}
102
103fn parse_level_4(it: &mut LexIterator) -> ParseResult {
104    let start = it.start_pos("operation (4)")?;
105    let arithmetic = it.parse(&parse_level_3, "operation", start)?;
106    macro_rules! bin_op {
107        ($it:expr, $fun:path, $ast:ident, $arithmetic:expr, $msg:expr) => {{
108            inner_bin_op!($it, start, $fun, $ast, $arithmetic, $msg)
109        }};
110    }
111
112    it.peek(
113        &|it, lex| match lex.token {
114            Token::Add => bin_op!(it, parse_level_4, Add, arithmetic.clone(), "add"),
115            Token::Sub => bin_op!(it, parse_level_4, Sub, arithmetic.clone(), "sub"),
116            _ => Ok(arithmetic.clone())
117        },
118        Ok(arithmetic.clone()),
119    )
120}
121
122fn parse_level_3(it: &mut LexIterator) -> ParseResult {
123    let start = it.start_pos("operation (3)")?;
124    let arithmetic = it.parse(&parse_level_2, "operation", start)?;
125    macro_rules! bin_op {
126        ($it:expr, $fun:path, $ast:ident, $arithmetic:expr, $msg:expr) => {{
127            inner_bin_op!($it, start, $fun, $ast, $arithmetic, $msg)
128        }};
129    }
130
131    macro_rules! match_range_slice {
132        ($it:expr, $token:ident, $incl:expr, $node:ident, $msg:expr) => {{
133            $it.eat(&Token::$token, $msg)?;
134            let to = $it.parse(&parse_expression, $msg, start)?;
135            let (to, step, end) = match to.node {
136                Node::$node { from, to, .. } => (from.clone(), Some(to.clone()), to.pos),
137                _ => {
138                    let step = $it.parse_if(&Token::$node, &parse_expression, $msg, start)?;
139                    (to.clone(), step.clone(), step.map_or(to.pos, |ast| ast.pos))
140                    }
141            };
142
143            let node = Node::$node { from: arithmetic.clone(), to, inclusive: $incl, step };
144            Ok(Box::from(AST::new(start.union(end), node)))
145        }}
146    }
147
148    it.peek(
149        &|it, lex| match lex.token {
150            Token::Mul => bin_op!(it, parse_level_3, Mul, arithmetic.clone(), "mul"),
151            Token::Div => bin_op!(it, parse_level_3, Div, arithmetic.clone(), "div"),
152            Token::FDiv => bin_op!(it, parse_level_3, FDiv, arithmetic.clone(), "floor div"),
153            Token::Mod => bin_op!(it, parse_level_3, Mod, arithmetic.clone(), "mod"),
154            Token::Range => match_range_slice!(it, Range, false, Range, "range"),
155            Token::RangeIncl => match_range_slice!(it, RangeIncl, true, Range, "range"),
156            Token::Slice => match_range_slice!(it, Slice, false, Slice, "range"),
157            Token::SliceIncl => match_range_slice!(it, SliceIncl, true, Slice, "range"),
158            _ => Ok(arithmetic.clone())
159        },
160        Ok(arithmetic.clone()),
161    )
162}
163
164fn parse_level_2(it: &mut LexIterator) -> ParseResult {
165    let start = it.start_pos("operation (2)")?;
166    macro_rules! un_op {
167        ($it:expr, $fun:path, $tok:ident, $ast:ident, $msg:expr) => {{
168            let factor = $it.parse(&$fun, $msg, start)?;
169            let node = Node::$ast { expr: factor.clone() };
170            Ok(Box::from(AST::new(start.union(factor.pos), node)))
171        }};
172    }
173
174    if it.eat_if(&Token::Add).is_some() {
175        un_op!(it, parse_level_2, Add, AddU, "plus")
176    } else if it.eat_if(&Token::Sub).is_some() {
177        un_op!(it, parse_level_2, Sub, SubU, "subtract")
178    } else if it.eat_if(&Token::Sqrt).is_some() {
179        un_op!(it, parse_expression, Sqrt, Sqrt, "square root")
180    } else if it.eat_if(&Token::Not).is_some() {
181        un_op!(it, parse_expression, Not, Not, "not")
182    } else if it.eat_if(&Token::BOneCmpl).is_some() {
183        un_op!(it, parse_expression, BOneCmpl, BOneCmpl, "bitwise ones compliment")
184    } else {
185        parse_level_1(it)
186    }
187}
188
189fn parse_level_1(it: &mut LexIterator) -> ParseResult {
190    let start = it.start_pos("operation (1)")?;
191    let arithmetic = it.parse(&parse_inner_expression, "operation", start)?;
192    macro_rules! bin_op {
193        ($it:expr, $fun:path, $ast:ident, $arithmetic:expr, $msg:expr) => {{
194            inner_bin_op!($it, start, $fun, $ast, $arithmetic, $msg)
195        }};
196    }
197
198    it.peek(
199        &|it, lex| match lex.token {
200            Token::Pow => bin_op!(it, parse_level_1, Pow, arithmetic.clone(), "exponent"),
201            Token::Question => {
202                it.eat(&Token::Question, "optional expression")?;
203                let right = it.parse(&parse_expression, "optional expression", lex.pos)?;
204                let node = Node::Question { left: arithmetic.clone(), right: right.clone() };
205                Ok(Box::from(AST::new(lex.pos.union(right.pos), node)))
206            }
207            _ => Ok(arithmetic.clone())
208        },
209        Ok(arithmetic.clone()),
210    )
211}
212
213#[cfg(test)]
214mod test {
215    use std::convert::From;
216
217    use crate::parse::{parse, parse_direct};
218    use crate::parse::ast::Node;
219    use crate::parse::lex::token::Token::*;
220
221    macro_rules! verify_is_operation {
222        ($op:ident, $ast:expr) => {{
223            match &$ast.first().expect("script empty.").node {
224                Node::$op { left, right } => (left.clone(), right.clone()),
225                other => panic!("first element script was not op: {}, but was: {:?}", $op, other)
226            }
227        }};
228    }
229
230    macro_rules! verify_is_un_operation {
231        ($op:ident, $ast:expr) => {{
232            match &$ast.first().expect("script empty.").node {
233                Node::$op { expr } => expr.clone(),
234                _ => panic!("first element script was not tuple.")
235            }
236        }};
237    }
238
239    #[test]
240    fn addition_verify() {
241        let source = String::from("a + b");
242        let ast = parse_direct(&source).unwrap();
243
244        let (left, right) = verify_is_operation!(Add, ast);
245        assert_eq!(left.node, Node::Id { lit: String::from("a") });
246        assert_eq!(right.node, Node::Id { lit: String::from("b") });
247    }
248
249    #[test]
250    fn addition_unary_verify() {
251        let source = String::from("+ b");
252        let ast = parse_direct(&source).unwrap();
253
254        let expr = verify_is_un_operation!(AddU, ast);
255        assert_eq!(expr.node, Node::Id { lit: String::from("b") });
256    }
257
258    #[test]
259    fn subtraction_verify() {
260        let source = String::from("a - False");
261        let ast = parse_direct(&source).unwrap();
262
263        let (left, right) = verify_is_operation!(Sub, ast);
264        assert_eq!(left.node, Node::Id { lit: String::from("a") });
265        assert_eq!(right.node, Node::Bool { lit: false });
266    }
267
268    #[test]
269    fn subtraction_unary_verify() {
270        let source = String::from("- c");
271        let ast = parse_direct(&source).unwrap();
272
273        let expr = verify_is_un_operation!(SubU, ast);
274        assert_eq!(expr.node, Node::Id { lit: String::from("c") });
275    }
276
277    #[test]
278    fn multiplication_verify() {
279        let source = String::from("True * b");
280        let ast = parse_direct(&source).unwrap();
281
282        let (left, right) = verify_is_operation!(Mul, ast);
283        assert_eq!(left.node, Node::Bool { lit: true });
284        assert_eq!(right.node, Node::Id { lit: String::from("b") });
285    }
286
287    #[test]
288    fn division_verify() {
289        let source = String::from("10.0 / fgh");
290        let ast = parse_direct(&source).unwrap();
291
292        let (left, right) = verify_is_operation!(Div, ast);
293        assert_eq!(left.node, Node::Real { lit: String::from("10.0") });
294        assert_eq!(right.node, Node::Id { lit: String::from("fgh") });
295    }
296
297    #[test]
298    fn floor_division_verify() {
299        let source = String::from("10.0 // fgh");
300        let ast = parse_direct(&source).unwrap();
301
302        let (left, right) = verify_is_operation!(FDiv, ast);
303        assert_eq!(left.node, Node::Real { lit: String::from("10.0") });
304        assert_eq!(right.node, Node::Id { lit: String::from("fgh") });
305    }
306
307    #[test]
308    fn power_verify() {
309        let source = String::from("chopin ^ liszt");
310        let ast = parse_direct(&source).unwrap();
311
312        let (left, right) = verify_is_operation!(Pow, ast);
313        assert_eq!(left.node, Node::Id { lit: String::from("chopin") });
314        assert_eq!(right.node, Node::Id { lit: String::from("liszt") });
315    }
316
317    #[test]
318    fn mod_verify() {
319        let source = String::from("chopin mod 3E10");
320        let ast = parse_direct(&source).unwrap();
321
322        let (left, right) = verify_is_operation!(Mod, ast);
323        assert_eq!(left.node, Node::Id { lit: String::from("chopin") });
324        assert_eq!(right.node, Node::ENum { num: String::from("3"), exp: String::from("10") });
325    }
326
327    #[test]
328    fn is_verify() {
329        let source = String::from("p is q");
330        let ast = parse_direct(&source).unwrap();
331
332        let (left, right) = verify_is_operation!(Is, ast);
333        assert_eq!(left.node, Node::Id { lit: String::from("p") });
334        assert_eq!(right.node, Node::Id { lit: String::from("q") });
335    }
336
337    #[test]
338    fn isnt_verify() {
339        let source = String::from("p isnt q");
340        let ast = parse_direct(&source).unwrap();
341
342        let (left, right) = verify_is_operation!(IsN, ast);
343        assert_eq!(left.node, Node::Id { lit: String::from("p") });
344        assert_eq!(right.node, Node::Id { lit: String::from("q") });
345    }
346
347    #[test]
348    fn isa_verify() {
349        let source = String::from("lizard isa animal");
350        let ast = parse_direct(&source).unwrap();
351
352        let (left, right) = verify_is_operation!(IsA, ast);
353        assert_eq!(left.node, Node::Id { lit: String::from("lizard") });
354        assert_eq!(right.node, Node::Id { lit: String::from("animal") });
355    }
356
357    #[test]
358    fn isnta_verify() {
359        let source = String::from("i isnta natural");
360        let ast = parse_direct(&source).unwrap();
361
362        let (left, right) = verify_is_operation!(IsNA, ast);
363        assert_eq!(left.node, Node::Id { lit: String::from("i") });
364        assert_eq!(right.node, Node::Id { lit: String::from("natural") });
365    }
366
367    #[test]
368    fn equality_verify() {
369        let source = String::from("i = s");
370        let ast = parse_direct(&source).unwrap();
371
372        let (left, right) = verify_is_operation!(Eq, ast);
373        assert_eq!(left.node, Node::Id { lit: String::from("i") });
374        assert_eq!(right.node, Node::Id { lit: String::from("s") });
375    }
376
377    #[test]
378    fn le_verify() {
379        let source = String::from("one < two");
380        let ast = parse_direct(&source).unwrap();
381
382        let (left, right) = verify_is_operation!(Le, ast);
383        assert_eq!(left.node, Node::Id { lit: String::from("one") });
384        assert_eq!(right.node, Node::Id { lit: String::from("two") });
385    }
386
387    #[test]
388    fn leq_verify() {
389        let source = String::from("two_hundred <= three");
390        let ast = parse_direct(&source).unwrap();
391
392        let (left, right) = verify_is_operation!(Leq, ast);
393        assert_eq!(left.node, Node::Id { lit: String::from("two_hundred") });
394        assert_eq!(right.node, Node::Id { lit: String::from("three") });
395    }
396
397    #[test]
398    fn ge_verify() {
399        let source = String::from("r > 10");
400        let ast = parse_direct(&source).unwrap();
401
402        let (left, right) = verify_is_operation!(Ge, ast);
403        assert_eq!(left.node, Node::Id { lit: String::from("r") });
404        assert_eq!(right.node, Node::Int { lit: String::from("10") });
405    }
406
407    #[test]
408    fn geq_verify() {
409        let source = String::from("4 >= 10");
410        let ast = parse_direct(&source).unwrap();
411
412        let (left, right) = verify_is_operation!(Geq, ast);
413        assert_eq!(left.node, Node::Int { lit: String::from("4") });
414        assert_eq!(right.node, Node::Int { lit: String::from("10") });
415    }
416
417    #[test]
418    fn in_verify() {
419        let source = String::from("one in my_set");
420        let ast = parse_direct(&source).unwrap();
421
422        let (left, right) = verify_is_operation!(In, ast);
423        assert_eq!(left.node, Node::Id { lit: String::from("one") });
424        assert_eq!(right.node, Node::Id { lit: String::from("my_set") });
425    }
426
427    #[test]
428    fn and_verify() {
429        let source = String::from("one and three");
430        let ast = parse_direct(&source).unwrap();
431
432        let (left, right) = verify_is_operation!(And, ast);
433        assert_eq!(left.node, Node::Id { lit: String::from("one") });
434        assert_eq!(right.node, Node::Id { lit: String::from("three") });
435    }
436
437    #[test]
438    fn or_verify() {
439        let source = String::from("one or \"asdf\"");
440        let ast = parse_direct(&source).unwrap();
441
442        let (left, right) = verify_is_operation!(Or, ast);
443        assert_eq!(left.node, Node::Id { lit: String::from("one") });
444        assert_eq!(right.node, Node::Str { lit: String::from("asdf"), expressions: vec![] });
445    }
446
447    #[test]
448    fn not_verify() {
449        let source = String::from("not some_cond");
450        let ast = parse_direct(&source).unwrap();
451
452        let expr = verify_is_un_operation!(Not, ast);
453        assert_eq!(expr.node, Node::Id { lit: String::from("some_cond") });
454    }
455
456    #[test]
457    fn sqrt_verify() {
458        let source = String::from("sqrt some_num");
459        let ast = parse_direct(&source).unwrap();
460
461        let expr = verify_is_un_operation!(Sqrt, ast);
462        assert_eq!(expr.node, Node::Id { lit: String::from("some_num") });
463    }
464
465    #[test]
466    fn b_and_verify() {
467        let source = String::from("one _and_ three");
468        let ast = parse_direct(&source).unwrap();
469
470        let (left, right) = verify_is_operation!(BAnd, ast);
471        assert_eq!(left.node, Node::Id { lit: String::from("one") });
472        assert_eq!(right.node, Node::Id { lit: String::from("three") });
473    }
474
475    #[test]
476    fn b_or_verify() {
477        let source = String::from("one _or_ \"asdf\"");
478        let ast = parse_direct(&source).unwrap();
479
480        let (left, right) = verify_is_operation!(BOr, ast);
481        assert_eq!(left.node, Node::Id { lit: String::from("one") });
482        assert_eq!(right.node, Node::Str { lit: String::from("asdf"), expressions: vec![] });
483    }
484
485    #[test]
486    fn b_xor_verify() {
487        let source = String::from("one _xor_ \"asdf\"");
488        let ast = parse_direct(&source).unwrap();
489
490        let (left, right) = verify_is_operation!(BXOr, ast);
491        assert_eq!(left.node, Node::Id { lit: String::from("one") });
492        assert_eq!(right.node, Node::Str { lit: String::from("asdf"), expressions: vec![] });
493    }
494
495    #[test]
496    fn b_ones_complement_verify() {
497        let source = String::from("_not_ \"asdf\"");
498        let ast = parse_direct(&source).unwrap();
499
500        let expr = verify_is_un_operation!(BOneCmpl, ast);
501        assert_eq!(expr.node, Node::Str { lit: String::from("asdf"), expressions: vec![] });
502    }
503
504    #[test]
505    fn b_lshift_verify() {
506        let source = String::from("one << \"asdf\"");
507        let ast = parse_direct(&source).unwrap();
508
509        let (left, right) = verify_is_operation!(BLShift, ast);
510        assert_eq!(left.node, Node::Id { lit: String::from("one") });
511        assert_eq!(right.node, Node::Str { lit: String::from("asdf"), expressions: vec![] });
512    }
513
514    #[test]
515    fn brshift_verify() {
516        let source = String::from("one >> \"asdf\"");
517        let ast = parse_direct(&source).unwrap();
518
519        let (left, right) = verify_is_operation!(BRShift, ast);
520        assert_eq!(left.node, Node::Id { lit: String::from("one") });
521        assert_eq!(right.node, Node::Str { lit: String::from("asdf"), expressions: vec![] });
522    }
523
524    #[test]
525    fn addition_missing_factor() {
526        let source = String::from("a +");
527        parse(&source).unwrap_err();
528    }
529
530    #[test]
531    fn subtraction_missing_factor() {
532        let source = String::from("b -");
533        parse(&source).unwrap_err();
534    }
535
536    #[test]
537    fn multiplication_missing_factor() {
538        let source = String::from("b *");
539        parse(&source).unwrap_err();
540    }
541
542    #[test]
543    fn division_missing_factor() {
544        let source = String::from("b /");
545        parse(&source).unwrap_err();
546    }
547
548    #[test]
549    fn power_missing_factor() {
550        let source = String::from("a ^");
551        parse(&source).unwrap_err();
552    }
553
554    #[test]
555    fn mod_missing_factor() {
556        let source = String::from("y mod");
557        parse(&source).unwrap_err();
558    }
559
560    #[test]
561    fn is_missing_value_left() {
562        let source = String::from("is a");
563        parse(&source).unwrap_err();
564    }
565
566    #[test]
567    fn is_missing_value_right() {
568        let source = String::from("kotlin is");
569        parse(&source).unwrap_err();
570    }
571
572    #[test]
573    fn isnt_missing_value_left() {
574        let source = String::from("isnt a");
575        parse(&source).unwrap_err();
576    }
577
578    #[test]
579    fn isnt_missing_value_right() {
580        let source = String::from("kotlin isnt");
581        parse(&source).unwrap_err();
582    }
583
584    #[test]
585    fn isa_missing_value_left() {
586        let source = String::from("isa a");
587        parse(&source).unwrap_err();
588    }
589
590    #[test]
591    fn isa_missing_value_right() {
592        let source = String::from("kotlin isa");
593        parse(&source).unwrap_err();
594    }
595
596    #[test]
597    fn isnta_missing_value_left() {
598        let source = String::from("isnta a");
599        parse(&source).unwrap_err();
600    }
601
602    #[test]
603    fn isnta_missing_value_right() {
604        let source = String::from("kotlin isnta");
605        parse(&source).unwrap_err();
606    }
607
608    #[test]
609    fn equality_missing_value_left() {
610        let source = String::from("= a");
611        parse(&source).unwrap_err();
612    }
613
614    #[test]
615    fn equality_missing_value_right() {
616        let source = String::from("kotlin =");
617        parse(&source).unwrap_err();
618    }
619
620    #[test]
621    fn le_missing_value_left() {
622        let source = String::from("< a");
623        parse(&source).unwrap_err();
624    }
625
626    #[test]
627    fn le_missing_value_right() {
628        let source = String::from("kotlin <");
629        parse(&source).unwrap_err();
630    }
631
632    #[test]
633    fn leq_missing_value_left() {
634        let source = String::from("<= a");
635        parse(&source).unwrap_err();
636    }
637
638    #[test]
639    fn leq_missing_value_right() {
640        let source = String::from("kotlin <=");
641        parse(&source).unwrap_err();
642    }
643
644    #[test]
645    fn ge_missing_value_left() {
646        let source = String::from("> a");
647        parse(&source).unwrap_err();
648    }
649
650    #[test]
651    fn ge_missing_value_right() {
652        let source = String::from("kotlin >");
653        parse(&source).unwrap_err();
654    }
655
656    #[test]
657    fn geq_missing_value_left() {
658        let source = String::from(">= a");
659        parse(&source).unwrap_err();
660    }
661
662    #[test]
663    fn geq_missing_value_right() {
664        let source = String::from("kotlin >=");
665        parse(&source).unwrap_err();
666    }
667
668    #[test]
669    fn and_missing_value_left() {
670        let source = String::from("and a");
671        parse(&source).unwrap_err();
672    }
673
674    #[test]
675    fn and_missing_value_right() {
676        let source = String::from("kotlin and");
677        parse(&source).unwrap_err();
678    }
679
680    #[test]
681    fn or_missing_value_left() {
682        let source = String::from("or a");
683        parse(&source).unwrap_err();
684    }
685
686    #[test]
687    fn or_missing_value_right() {
688        let source = String::from("kotlin or");
689        parse(&source).unwrap_err();
690    }
691
692    #[test]
693    fn not_missing_value() {
694        let source = String::from("not");
695        parse(&source).unwrap_err();
696    }
697
698    #[test]
699    fn sqrt_missing_value() {
700        let source = String::from("sqrt");
701        parse(&source).unwrap_err();
702    }
703}