erg/compiler/erg_parser/tests/test2_advanced_syntax.er
Shunsuke Shibayama f9d91aa38e Organize crates
2022-08-13 06:38:12 +09:00

28 lines
503 B
Python

# Check that a parser can pass the advanced syntax
# 高度な文法をチェックする
# overloading (多重定義)
f x = 1 + x + 2
f x, y =
1 + x + y
f x, y, z =
1 + x + y + z
assert 4 == f 1
assert 4 == f 1, 1
assert 3 == f 1, 1, 1
# pattern overloading
fib 0 = 0
fib 1 = 1
fib(n: Nat) -> Nat = fib(n-1) + fib(n-2)
# keyword arguments (キーワード引数)
t = if True:
then: 1
else: 2
assert t == 1
# import
math = import "math"
# {*} = "math" # use all
{pi} = import "math"