Skip to content

Commit 476bd99

Browse files
panglesdjonludlam
authored andcommitted
allow | char as a word outside of light table
Signed-off-by: Paul-Elliot <[email protected]>
1 parent 0641cb9 commit 476bd99

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

src/syntax.ml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ let rec inline_element :
204204
| `Plus ->
205205
junk input;
206206
Loc.at location (`Word "+")
207+
| `Bar ->
208+
junk input;
209+
Loc.at location (`Word "|")
207210
| (`Code_span _ | `Math_span _ | `Raw_markup _) as token ->
208211
junk input;
209212
Loc.at location token
@@ -364,6 +367,11 @@ and delimited_inline_element_list :
364367
junk input;
365368
let element = Loc.same next_token (`Space ws) in
366369
consume_elements ~at_start_of_line:true (element :: acc)
370+
| `Bar as token ->
371+
let acc =
372+
inline_element input next_token.location ~context token :: acc
373+
in
374+
consume_elements ~at_start_of_line:false acc
367375
| (`Minus | `Plus) as bullet ->
368376
(if at_start_of_line then
369377
let suggestion =
@@ -457,8 +465,8 @@ let paragraph : input -> Ast.nestable_block_element with_location =
457465
fun acc ->
458466
let next_token = peek input in
459467
match next_token.value with
460-
| (`Space _ | `Minus | `Plus | #token_that_always_begins_an_inline_element)
461-
as token ->
468+
| ( `Space _ | `Minus | `Plus | `Bar
469+
| #token_that_always_begins_an_inline_element ) as token ->
462470
let element =
463471
inline_element input next_token.location ~context:Outside_light_table
464472
token
@@ -748,19 +756,6 @@ let rec block_element_list :
748756
|> add_warning input;
749757
junk input;
750758
consume_block_elements ~parsed_a_tag where_in_line acc
751-
(* Bars can never appear directly in block content.
752-
They can only appear inside [{t ...}]. *)
753-
| { value = `Bar as token; location } ->
754-
let suggestion =
755-
Printf.sprintf "move %s into %s." (Token.print token)
756-
(Token.describe `Begin_table_light)
757-
in
758-
Parse_error.not_allowed ~what:(Token.describe token)
759-
~in_what:(Token.describe parent_markup)
760-
~suggestion location
761-
|> add_warning input;
762-
junk input;
763-
consume_block_elements ~parsed_a_tag where_in_line acc
764759
(* Tags. These can appear at the top level only. Also, once one tag is seen,
765760
the only top-level elements allowed are more tags. *)
766761
| { value = `Tag tag as token; location } as next_token -> (
@@ -872,8 +867,8 @@ let rec block_element_list :
872867
let tag = Loc.at location (`Tag tag) in
873868
consume_block_elements ~parsed_a_tag:true `After_text
874869
(tag :: acc)))
875-
| { value = #token_that_always_begins_an_inline_element; _ } as next_token
876-
->
870+
| ( { value = #token_that_always_begins_an_inline_element; _ }
871+
| { value = `Bar; _ } ) as next_token ->
877872
warn_if_after_tags next_token;
878873
warn_if_after_text next_token;
879874

test/test.ml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ let%expect_test _ =
405405
()
406406

407407
let%expect_test _ =
408-
let module Plus_minus_words = struct
408+
let module Plus_minus_bar_words = struct
409409
let minus_in_word =
410410
test "foo-bar";
411411
[%expect
@@ -444,6 +444,36 @@ let%expect_test _ =
444444
((f.ml (1 4) (1 5)) (word +)))))))
445445
(warnings ())) |}]
446446

447+
let bar_in_word =
448+
test "foo|bar";
449+
[%expect
450+
{|
451+
((output
452+
(((f.ml (1 0) (1 7))
453+
(paragraph
454+
(((f.ml (1 0) (1 3)) (word foo)) ((f.ml (1 3) (1 4)) (word |))
455+
((f.ml (1 4) (1 7)) (word bar)))))))
456+
(warnings ())) |}]
457+
458+
let escaped_bar_in_word =
459+
test "foo\\|bar";
460+
[%expect
461+
{|
462+
((output
463+
(((f.ml (1 0) (1 8)) (paragraph (((f.ml (1 0) (1 8)) (word "foo\\|bar")))))))
464+
(warnings ())) |}]
465+
466+
let bar_as_word =
467+
test "foo |";
468+
[%expect
469+
{|
470+
((output
471+
(((f.ml (1 0) (1 5))
472+
(paragraph
473+
(((f.ml (1 0) (1 3)) (word foo)) ((f.ml (1 3) (1 4)) space)
474+
((f.ml (1 4) (1 5)) (word |)))))))
475+
(warnings ())) |}]
476+
447477
let negative_number =
448478
test "-3.14 -1337";
449479
[%expect

test/test_tables.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ let%expect_test _ =
506506
newlines} | {b d} [foo] |
507507
}
508508
|};
509-
[%expect {|
509+
[%expect
510+
{|
510511
((output
511512
(((f.ml (2 6) (6 7))
512513
(table (syntax light)

0 commit comments

Comments
 (0)