#!/usr/bin/env python3 from milkshake import slurp, Symbol from lark import Tree, Token import pytest @pytest.mark.parametrize( "input, val", [ ("()", Tree("list", [])), ("nil", nil := Symbol("nil")), ("(nil nil nil)", Tree("list", [nil, nil, nil])), ( "(/ + - * % ^ \\ & # @ ! = |)", Tree( "list", [ Symbol("/"), Symbol("+"), Symbol("-"), Symbol("*"), Symbol("%"), Symbol("^"), Symbol("\\"), Symbol("&"), Symbol("#"), Symbol("@"), Symbol("!"), Symbol("="), Symbol("|"), ], ), ), ("1.0", Tree("number", ["1.0"])), ("+1.0", Tree("number", ["+1.0"])), ("-1.0", Tree("number", ["-1.0"])), ("-10,000,000.0", Tree("number", ["-10,000,000.0"])), ("-10.000.000,0", Tree("number", ["-10.000.000,0"])), ("-10_000_000,0", Tree("number", ["-10_000_000,0"])), ("-10_000_000.0", Tree("number", ["-10_000_000.0"])), ("1e50", Tree("number", ["1e50"])), ("-1e-50", Tree("number", ["-1e-50"])), ("-1e+50", Tree("number", ["-1e+50"])), ( "(+inf -inf inf nan +nan -nan)", Tree( "list", [ Symbol("+inf"), Symbol("-inf"), Symbol("inf"), Symbol("nan"), Symbol("+nan"), Symbol("-nan"), ], ), ), ("'()", Tree("quote", [Tree("list", [])])), ( "`(nil ~'() ~@'())", Tree( "quasiquote", [ Tree( "list", [ Symbol("nil"), Tree( "unquote", [ Tree( "quote", [ Tree("list", []), ], ), ], ), Tree( "unquote_splicing", [ Tree( "quote", [ Tree("list", []), ], ), ], ), ], ), ], ), ), (r"/foo\S+/", Tree("pattern", [r"/foo\S+/"])), ], ) def test_examples(input, val): assert slurp(input, start="expr") == val