-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
pp.parens
option to pretty print with all parentheses (#2934)
This PR adds the option `pp.parens` (default: false) that causes the pretty printer to eagerly insert parentheses, which can be useful for teaching and for understanding the structure of expressions. For example, it causes `p → q → r` to pretty print as `p → (q → r)`. Any notations with precedence greater than or equal to `maxPrec` do not receive such discretionary parentheses, since this precedence level is considered to be infinity. This option was a feature in the Lean 3 community edition.
- Loading branch information
Showing
3 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/-! | ||
# Tests for the `pp.parens` pretty printing option | ||
-/ | ||
|
||
set_option pp.parens true | ||
|
||
/-! | ||
No parentheses around numeral. | ||
-/ | ||
/-- info: 1 : Nat -/ | ||
#guard_msgs in #check 1 | ||
|
||
/-! | ||
No parentheses around variable. | ||
-/ | ||
/-- info: x : Nat -/ | ||
#guard_msgs in variable (x : Nat) in #check x | ||
|
||
/-! | ||
No parentheses around each individual function application. | ||
-/ | ||
def f (x y z : Nat) : Nat := x + y + z | ||
/-- info: f 1 2 3 : Nat -/ | ||
#guard_msgs in #check f 1 2 3 | ||
|
||
/-! | ||
Example arithmetic expressions | ||
-/ | ||
/-- info: (1 + (2 * 3)) + 4 : Nat -/ | ||
#guard_msgs in #check 1 + 2 * 3 + 4 | ||
/-- info: Nat.add_assoc : ∀ (n m k : Nat), (((n + m) + k) = (n + (m + k))) -/ | ||
#guard_msgs in #check (Nat.add_assoc) | ||
|
||
/-! | ||
Implication chains | ||
-/ | ||
/-- info: p → (q → r) : Prop -/ | ||
#guard_msgs in variable (p q r : Prop) in #check p → q → r | ||
|
||
/-! | ||
No parentheses around list literals | ||
-/ | ||
/-- info: [1, 2, 3] ++ [3, 4, 5] : List Nat -/ | ||
#guard_msgs in #check [1,2,3] ++ [3,4,5] | ||
|
||
/-! | ||
Parentheses around body of forall. | ||
-/ | ||
/-- info: ∀ (p : (Nat → (Nat → Prop))), (p (1 + 2) 3) : Prop -/ | ||
#guard_msgs in #check ∀ (p : Nat → Nat → Prop), p (1 + 2) 3 | ||
|
||
/-! | ||
Parentheses around branches of `if`. | ||
-/ | ||
/-- info: if True then (1 + 2) else (2 + 3) : Nat -/ | ||
#guard_msgs in #check if True then 1 + 2 else 2 + 3 |