lean4-htt/tests/lean/user_notation.lean
2017-06-07 10:09:38 -07:00

25 lines
722 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

open lean (parser)
open lean.parser
open interactive
open tactic
reserve prefix `unquote! `:100
@[user_notation]
meta def unquote_macro (_ : parse $ tk "unquote!") (e : parse lean.parser.pexpr) : parser pexpr :=
↑(to_expr e >>= eval_expr pexpr)
#eval unquote! ``(1 + 1)
reserve infix ` +⋯+ `:65
@[user_notation]
meta def upto_notation (e₁ : parse lean.parser.pexpr) (_ : parse $ tk "+⋯+") (n₂ : ) : parser pexpr :=
do n₁ ← ↑(to_expr e₁ >>= eval_expr nat),
pure $ (n₂+1-n₁).repeat (λ i e, ``(%%e + %%(reflect $ n₁ + i))) ``(0)
#check 1 +⋯+ 10
@[user_notation]
meta def no_tk (e₁ : parse lean.parser.pexpr) := e₁
@[user_notation]
meta def no_parser (e₁ : parse $ tk "(") := e₁