Skip to content

Commit 04fe167

Browse files
authored
Merge pull request #35 from lefessan/z-2023-10-14-fix-texi2rst
Fix texi2rst to handle two-line macros
2 parents fd3b888 + a51b7ec commit 04fe167

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/lsp/superbol_free_lib/command_texi2rst.ml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ type closer =
159159
| BRACE
160160
| QUOTE
161161

162+
exception Unexpected_eol
163+
162164
let read ~path filename =
163165

164166
let file = Filename.basename filename in
@@ -174,13 +176,13 @@ let read ~path filename =
174176
Buffer.clear b;
175177
if s = "" then [] else [ STRING s ]
176178
in
177-
let parse_line ic line =
179+
let parse_line_exn ic line =
178180
let len = String.length line in
179181
let b = Buffer.create len in
180182
let rec iter i braced =
181183
if i = len then
182184
if braced <> EOL then
183-
INPUT.error ~ic "unexpected end of line"
185+
raise Unexpected_eol
184186
else
185187
len,
186188
maybe b
@@ -272,6 +274,13 @@ let read ~path filename =
272274
INPUT.error ~ic "unbalanced ending brace";
273275
line
274276
in
277+
let parse_line ic arg =
278+
try
279+
parse_line_exn ic arg
280+
with
281+
| Unexpected_eol ->
282+
INPUT.error ~ic "unexpected end of line"
283+
in
275284
let parse_level ic arg =
276285
let len = String.length arg in
277286
if len < 3 ||
@@ -498,8 +507,21 @@ let read ~path filename =
498507
if line = "" then
499508
iter_lines ic ( EMPTY_LINE :: rev ) stack
500509
else
501-
let line = parse_line ic line in
502-
iter_lines ic ( LINE line :: rev ) stack
510+
parse_line_rec true ic line rev stack
511+
512+
and parse_line_rec again ic line rev stack =
513+
match parse_line_exn ic line with
514+
| line -> iter_lines ic ( LINE line :: rev ) stack
515+
| exception Unexpected_eol ->
516+
if again then
517+
match INPUT.input_line ic with
518+
| exception _ ->
519+
INPUT.close_in ic;
520+
rev, stack
521+
| line2 ->
522+
parse_line_rec false ic (line ^ "\n" ^ line2) rev stack
523+
else
524+
INPUT.error ~ic "unexpected end of line after continuation"
503525

504526
and end_item ic rev stack item_arg =
505527
match stack with

0 commit comments

Comments
 (0)