Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 28441d8

Browse files
author
Iwan
committed
Tweak poly var printing in outcome printer
1 parent a409ae4 commit 28441d8

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

src/res_outcome_printer.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let classifyIdentContent ~allowUident txt =
2929
let c = String.unsafe_get txt i in
3030
if i == 0 && not (
3131
(allowUident && (c >= 'A' && c <= 'Z')) ||
32-
(c >= 'a' && c <= 'z') || c = '_' || (c >= '0' && c <= '9')) then
32+
(c >= 'a' && c <= 'z') || c = '_') then
3333
ExoticIdent
3434
else if not (
3535
(c >= 'a' && c <= 'z')
@@ -56,6 +56,15 @@ let printIdentLike ~allowUident txt =
5656
]
5757
| NormalIdent -> Doc.text txt
5858

59+
let printPolyVarIdent txt =
60+
match classifyIdentContent ~allowUident:true txt with
61+
| ExoticIdent -> Doc.concat [
62+
Doc.text "\"";
63+
Doc.text txt;
64+
Doc.text"\""
65+
]
66+
| NormalIdent -> Doc.text txt
67+
5968
(* ReScript doesn't have parenthesized identifiers.
6069
* We don't support custom operators. *)
6170
let parenthesized_ident _name = true
@@ -376,7 +385,7 @@ let printIdentLike ~allowUident txt =
376385
Doc.group (
377386
Doc.concat [
378387
Doc.text "#";
379-
printIdentLike ~allowUident:true name;
388+
printPolyVarIdent name;
380389
match types with
381390
| [] -> Doc.nil
382391
| types ->

tests/oprint/oprint.res

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ let computeAreaPlus = (sp: shapePlus) =>
135135
| #...shape as s => computeArea(s)
136136
}
137137

138+
let computeAreaExotic = (sp) =>
139+
switch sp {
140+
| #"R-Triangle+"(_p1, _p2, _p3) => ()
141+
| #...shape as s => ignore(s); ()
142+
}
143+
138144
let top = #Point(3.0, 5.0)
139145
let left = #Point(0.0, 0.0)
140146
let right = #Point(3.0, 0.0)
@@ -183,6 +189,11 @@ type t21 = [#"va r ia nt"]
183189
type t22 = [#"Variant ⛰"]
184190
type \"let" = int
185191
type \"type" = [ #"Point🗿"(\"let", float) ]
192+
type t23 = [
193+
| #"1"
194+
| #"10space"
195+
| #"123"
196+
]
186197

187198
type exoticUser = {
188199
\"let": string,

tests/oprint/oprint.res.snapshot

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ type shapePlus = [
100100
| #Triangle(point, point, point)
101101
]
102102
let computeAreaPlus: shapePlus => float
103+
let computeAreaExotic: [<
104+
| #Circle(point, float)
105+
| #"R-Triangle+"('a, 'b, 'c)
106+
| #Rectangle(point, point)
107+
] => unit
103108
let top: [> #Point(float, float)]
104109
let left: [> #Point(float, float)]
105110
let right: [> #Point(float, float)]
@@ -137,11 +142,12 @@ module type Conjunctive = {
137142
let f: [< #T([< u2]) & ([< u2]) & ([< u1])] => unit
138143
let g: [< #S & ([< u2]) & ([< u2]) & ([< u1])] => unit
139144
}
140-
type t20 = [#\"type"]
141-
type t21 = [#\"va r ia nt"]
142-
type t22 = [#\"Variant ⛰"]
145+
type t20 = [#"type"]
146+
type t21 = [#"va r ia nt"]
147+
type t22 = [#"Variant ⛰"]
143148
type \"let" = int
144-
type \"type" = [#\"Point🗿"(\"let", float)]
149+
type \"type" = [#"Point🗿"(\"let", float)]
150+
type t23 = [#"1" | #"10space" | #"123"]
145151
type exoticUser = {\"let": string, \"type": float}
146152
module Js = {
147153
module Fn = {

0 commit comments

Comments
 (0)