Skip to content

Report all syntax errors in Markdown files#389

Merged
NathanReb merged 10 commits intorealworldocaml:mainfrom
NathanReb:report-all-syntax-errors
Aug 3, 2022
Merged

Report all syntax errors in Markdown files#389
NathanReb merged 10 commits intorealworldocaml:mainfrom
NathanReb:report-all-syntax-errors

Conversation

@NathanReb
Copy link
Copy Markdown
Contributor

This PR improves the MDX workflow by making sure that all parsing errors are reported at once rather than exiting on the first errors.

Obviously that only impacts errors that we can recover from e.g. mis-used or missing labels, syntax error inside a block but not for errors such as invalid markdown.

We used to do all the work in markdown/cram parser. I changed that to extract raw bits of data from the parser and leave their interpretation to a later pass.

While working on this I discovered that the locations we attach to blocks are incorrect due to inconsistencies in eol handling in the lexer code which I took the liberty to fix as part of this PR. I can eventually extract it as a separate PR depending on this one if you'd like but basing it on this work made it significantly simpler.

@NathanReb
Copy link
Copy Markdown
Contributor Author

There is a small side effect which is that errors with labels are reported with the entire block location. I think it's not too bad, especially given how precise the error messages usually are, there should be no ambiguity as to where the error comes from.

We can eventually try to refine error locations even further but since we have no editor integration at the moment I see little incentive for it.

@NathanReb
Copy link
Copy Markdown
Contributor Author

Finally, this does not impact mli files at the moment. The implementation of the parsing being quite different I decided to open a PR with I already had.

I'll work on the mli side of things next but doing it separately should ease the review!

NathanReb and others added 6 commits August 2, 2022 10:28
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
@NathanReb NathanReb force-pushed the report-all-syntax-errors branch from afa20e1 to 00dc7d9 Compare August 2, 2022 08:42
Copy link
Copy Markdown
Collaborator

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I think it is fair to leave the fix for the error locations here, untangling it would probably create more work than it is worth, although it would be somewhat simpler to review.

In general I think it is fair to move the parsing out of the lexer, which also makes programming a bit easier in a file that is actual OCaml syntax instead of ocamllex. And well, it is more parsing than lexing anyway.

The code is fine, I don't have anything big to note. Just a few comments on the points that took me longer to understand with suggestions how to improve them.

Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Copy link
Copy Markdown
Collaborator

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I think it is ready to be merged.

@NathanReb NathanReb merged commit d23b06b into realworldocaml:main Aug 3, 2022
Leonidas-from-XIV added a commit to Leonidas-from-XIV/opam-repository that referenced this pull request Jan 6, 2023
CHANGES:

#### Added

- Report all parsing errors in Markdown files (realworldocaml/mdx#389, @NathanReb)

#### Changed

- Preserve indentation in multiline OCaml blocks in .mli files (realworldocaml/mdx#395, @panglesd)

#### Fixed

- Fixed compatibility with Cmdliner 1.1.0 (realworldocaml/mdx#371, @Leonidas-from-XIV)
- Report errors and exit codes of toplevel directives (realworldocaml/mdx#382, @talex5,
  @Leonidas-from-XIV)
- Fix block locations in error reporting (realworldocaml/mdx#389, @NathanReb)
- Include the content of the line that features the `part-end` MDX directive in
  the output, before that line would've been dropped (realworldocaml/mdx#374, realworldocaml/mdx#387,
  @Leonidas-from-XIV)
- Handle EINTR signal on waitpid call by restarting the syscall. (realworldocaml/mdx#409, @tmcgilchrist)
- Fix parsing of multiline toplevel phrases in .mli files (realworldocaml/mdx#394, realworldocaml/mdx#397,
  @Leonidas-from-XIV)

#### Removed

- Removed warning about missing semicolons added in MDX 1.11.0 and the
  automatic insertion of semicolons in the corrected files introduced in MDX
  2.0.0. (realworldocaml/mdx#398, @Leonidas-from-XIV)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants