]> git.lizzy.rs Git - metalua.git/blob - junk/dynamatch.mlua
Merge remote branch 'origin/master'
[metalua.git] / junk / dynamatch.mlua
1 --x = dynamatch()
2 --x <| foo | bar -> do toto end
3 --table.insert(x.cases, |$| match $ with foo|bar -> toto end    )
4
5
6 local match_builder = mlp.stat:get "match"
7
8 function dynacase_builder (d, s)
9    local  v = mlp.gensym()
10    local  m = match_builder{ v, false, { s[1], s[2], s[3] } }
11    local  c = `Function{ {v}, {m} }
12    return `Call{ `Index{ d, "extend" }, c }
13 end
14
15 --fixme: limiter la precedence du expr de droite
16 mlp.expr.suffix:add{ 
17    name = "dynamatch extension", prec=30, 
18    "<|",  
19    gg.list{ name = "patterns",
20       primary = mlp.expr,
21       separators = "|",
22       terminators = { "->", "if" } },
23    gg.onkeyword{ "if", mlp.expr },
24    "->",
25    gg.multisequence{
26       { "do", mlp.block, "end", builder = |x| x[1] },
27       default = { mlp.expr, builder = |x| { `Return{ x[1] } } } },
28    builder = |x| dyna_builder (x[1], x[3]) }
29