test: simple termParser attribute test

This commit is contained in:
Leonardo de Moura 2019-12-31 17:03:11 -08:00
parent 2c77ea47de
commit dd4bed3c6f

View file

@ -0,0 +1,26 @@
import Init.Lean
open Lean
open Lean.Elab
def run (input : String) (failIff : Bool := true) : MetaIO Unit :=
do env ← MetaIO.getEnv;
opts ← MetaIO.getOptions;
let (env, messages) := process input env opts;
messages.toList.forM $ fun msg => IO.println msg;
when (failIff && messages.hasErrors) $ throw (IO.userError "errors have been found");
when (!failIff && !messages.hasErrors) $ throw (IO.userError "there are no errors");
pure ()
open Lean.Parser
@[termParser] def tst := parser! "(|" >> termParser >> "|)"
@[termParser] def boo : ParserDescr :=
ParserDescr.node `boo
(ParserDescr.andthen
(ParserDescr.symbol "[|" 0)
(ParserDescr.andthen
(ParserDescr.parser `term 0)
(ParserDescr.symbol "|]" 0)))
#eval run "#check [| @id.{1} Nat |]"
#eval run "#check (| id 1 |)"