summary refs log tree commit diff
path: root/18/src/expression.lalrpop
blob: 49356f6dc48b0e96b6f50bc56a8a73e9529edbee (plain)
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
use crate::types::{Pair, Value};

grammar;

pub Pair: Pair = {
  LEFT_BRACKET <left:Value> COMMA <right:Value> RIGHT_BRACKET => {
    Pair {
      left: left,
      right: right,
    }
  },
};

Value: Value = {
  NUMBER => {
    Value::Literal(<>.parse::<i64>().unwrap())
  },
  Pair => {
    Value::Pair(Box::new(<>))
  },
};

match {
  r"\p{Zs}+" => { },

  r"[0-9]+" => NUMBER,

  "," => COMMA,

  "[" => LEFT_BRACKET,

  "]" => RIGHT_BRACKET,
}