Skip to content

Commit

Permalink
Allow prefixed page reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Julow committed Jun 7, 2024
1 parent f6b9daa commit dd61bc5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/model/reference.ml
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,20 @@ let parse whole_reference_location s :
location
|> Error.raise_exception
| `TPage ->
let suggestion =
Printf.sprintf "'page-%s' should be first." identifier
let () =
match next_token.kind with
| `End_in_slash -> ()
| `None | `Prefixed _ ->
let suggestion =
Printf.sprintf "Reference pages as '<parent_path>/%s'."
identifier
in
not_allowed ~what:"Page label"
~in_what:"on the right side of a dot" ~suggestion location
|> Error.raise_exception
in
not_allowed ~what:"Page label"
~in_what:"the last component of a reference path" ~suggestion
location
|> Error.raise_exception
(* Prefixed pages are not differentiated. *)
`Page_path (page_path identifier next_token tokens)
| `TRelativePath -> `Page_path (page_path identifier next_token tokens))
in

Expand Down
9 changes: 7 additions & 2 deletions test/model/semantics/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2353,7 +2353,7 @@ let%expect_test _ =
test "{!foo.page-bar}";
[%expect
{|
{"value":[{"`Paragraph":[{"`Code_span":"foo.page-bar"}]}],"warnings":["File \"f.ml\", line 1, characters 6-14:\nPage label is not allowed in the last component of a reference path.\nSuggestion: 'page-bar' should be first."]} |}]
{"value":[{"`Paragraph":[{"`Code_span":"foo.page-bar"}]}],"warnings":["File \"f.ml\", line 1, characters 6-14:\nPage label is not allowed in on the right side of a dot.\nSuggestion: Reference pages as '<parent_path>/bar'."]} |}]

let inner_parent_something_in_something =
test "{!foo.bar.field-baz}";
Expand Down Expand Up @@ -2806,7 +2806,7 @@ let%expect_test _ =
let relative_tag_after_slash =
test "{!foo/page-bar}";
[%expect
{| {"value":[{"`Paragraph":[{"`Code_span":"foo/page-bar"}]}],"warnings":["File \"f.ml\", line 1, characters 6-14:\nPage label is not allowed in the last component of a reference path.\nSuggestion: 'page-bar' should be first."]} |}]
{| {"value":[{"`Paragraph":[{"`Reference":[{"`Page_path":{"`Slash":[{"`Root":["foo","`TRelativePath"]},"bar"]}},[]]}]}],"warnings":[]} |}]

let relative_tag_after_slash =
test "{!foo/module-Bar}";
Expand Down Expand Up @@ -2840,6 +2840,11 @@ let%expect_test _ =
[%expect
{| {"value":[{"`Paragraph":[{"`Code_span":"./"}]}],"warnings":["File \"f.ml\", line 1, characters 4-4:\nIdentifier in reference should not be empty."]} |}]

let err_page_prefix_after_dot =
test "{!foo.page-bar}";
[%expect
{| {"value":[{"`Paragraph":[{"`Code_span":"foo.page-bar"}]}],"warnings":["File \"f.ml\", line 1, characters 6-14:\nPage label is not allowed in on the right side of a dot.\nSuggestion: Reference pages as '<parent_path>/bar'."]} |}]

(* Old kind compatibility *)

let oldkind_abs_page =
Expand Down

0 comments on commit dd61bc5

Please sign in to comment.