lean4-htt/tests/playground/parser/test1.lean
Leonardo de Moura 2eed00039a chore(tests/playground/parser/parser): remove Thunk hack
The artificial `Thunk` was being used just to make sure a `Parser`
object was small enough to be inlined. We don't need this hack anymore.
Commit 0ea944a adds a new transformation that makes sure the size of
field `info` does not impact the decision on whether field `fn` will be
inlined or not.
2019-04-18 13:18:31 -07:00

39 lines
1.1 KiB
Text

import parser
open Parser
local infix ` ; `:10 := Parser.andthen
local infix ` || `:5 := Parser.orelse
def mkNumPairKind : IO SyntaxNodeKind := nextKind `numPair
@[init mkNumPairKind] constant numPairKind : SyntaxNodeKind := default _
def mkNumSetKind : IO SyntaxNodeKind := nextKind `numSet
@[init mkNumSetKind] constant numSetKind : SyntaxNodeKind := default _
-- set_option trace.compiler.boxed true
def numPair : BasicParser :=
node numPairKind $
"("; number; ","; number; ")"
def numSet : BasicParser :=
node numSetKind $
"{"; sepBy number ","; "}"
def testParser : BasicParser :=
many (numPair || numSet)
@[noinline] def test (p : BasicParser) (s : String) : IO Unit :=
match p.run s with
| Except.error msg := IO.println msg
| Except.ok stx := IO.println stx
def mkNumPairString : Nat → String → String
| 0 s := s
| (n+1) s := mkNumPairString n $
s ++ "{} /- /- comment2 -/ -/ "
++ "{" ++ toString n ++ "," ++ toString (n+1) ++ ", " ++ toString (n+2) ++ "}"
++ "(" ++ toString n ++ ", " ++ toString n ++ ") -- comment\n"
def main (xs : List String) : IO Unit :=
let s := mkNumPairString xs.head.toNat "" in
test testParser s