@@ -108,10 +108,14 @@ module Offside = struct
108108 if column < indent - 2 then error " offside" else
109109 emit token >>
110110 get >> = inside_braces break false indent
111+ | AND ->
112+ if column < indent then error " offside" else
113+ emit token >>
114+ get >> = inside_braces break false indent
111115 | _ ->
112116 if column < indent then error " offside" else
113117 emit_if (column = indent && insert) COMMA >>
114- nest token >>
118+ nest false token >>
115119 get >> = inside_braces break (token <> LOCAL ) indent
116120
117121 and inside_local insert indent (token , column ) =
@@ -128,7 +132,7 @@ module Offside = struct
128132 emit IN
129133 else
130134 emit_if (column = indent && insert) COMMA >>
131- nest token >>
135+ nest false token >>
132136 get >> = inside_local (token <> LOCAL ) indent
133137
134138 and inside_let insert indent (token , column ) =
@@ -147,12 +151,12 @@ module Offside = struct
147151 inside_in false column (token, column)
148152 else
149153 emit_if (column = indent && insert) COMMA >>
150- nest token >>
154+ nest false token >>
151155 get >> = inside_let (token <> LOCAL ) indent
152156
153157 and inside_in insert indent (token , column ) =
154158 match token with
155- | RBRACE | COMMA | IN | EOF | RPAR -> unget (token, column)
159+ | RBRACE | COMMA | IN | EOF | RPAR | EQUAL -> unget (token, column)
156160 | SEMI ->
157161 if column < indent - 2 then error " offside" else
158162 emit token >>
@@ -170,18 +174,18 @@ module Offside = struct
170174 let slack = slack_of token in
171175 if column < indent - slack then unget (token, column) else
172176 emit_if (slack = 0 && column = indent && insert) SEMI >>
173- nest token >>
177+ nest true token >>
174178 get >> = inside_in (slack = 0 && indent < column) indent
175179
176180 and inside_parens (token , column ) =
177181 match token with
178182 | RPAR -> emit token
179- | _ -> nest token >> get >> = inside_parens
183+ | _ -> nest true token >> get >> = inside_parens
180184
181- and nest token =
185+ and nest is_expr token =
182186 match token with
183187 | FUN | REC ->
184- emit LPAR >> emit token
188+ if is_expr then emit LPAR >> emit token else emit token
185189 | _ ->
186190 emit token >>
187191 match token with
@@ -197,7 +201,7 @@ module Offside = struct
197201 | DARROW ->
198202 get >> = fun (token , column ) ->
199203 inside_in false column (token, column) >>
200- emit RPAR
204+ if is_expr then emit RPAR else unit
201205 | EQUAL | DO ->
202206 get >> = fun (token , column ) -> inside_in false column (token, column)
203207 | _ ->
@@ -251,6 +255,7 @@ rule token = parse
251255 | " import" { IMPORT }
252256 | " primitive" { PRIMITIVE }
253257 | " rec" { REC }
258+ | " and" { AND }
254259 | " then" { THEN }
255260 | " type" { TYPE }
256261 | " unwrap" { UNWRAP }
0 commit comments