Skip to content

rustdoc: make langstring parsing more robust #14569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2014

Conversation

skade
Copy link
Contributor

@skade skade commented May 31, 2014

This changes the parsing of the language string
in code examples so that unrecognized examples
are not considered Rust code. This was, for example,
the case when a code example was marked sh for shell
code.

This relieves authors of having to mark those samples
as notrust.

Also adds recognition of the positive marker rust.

By default, unmarked examples are still considered rust.

@skade skade changed the title rustdoc: make langstring parsing robuster rustdoc: make langstring parsing more robust May 31, 2014
let mut tokens = string.as_slice().split(|c: char| !c.is_alphanumeric());

for token in tokens {
if token.len() == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

This chain could be written as

match token {
    "" => {}
    "should_fail" => should_fail = true,
    "no_run" => ignore = true,
    ...
    _ => notrust = true,
}

@skade
Copy link
Contributor Author

skade commented Jun 1, 2014

I fixed and re-indented the code. Also changed the logic a bit: If any of the rustdoc tags are seen, the code is considered rust, even if other unrecognized ones are seen (allowing for .rust .example).

@alexcrichton
Copy link
Member

While rustdoc is usually not tested, this logic seems tricky enough that it would lend itself quite well to a unit test. Could you add a test in this module inside of a mod tests section?

This changes the parsing of the language string
in code examples so that unrecognized examples
are not considered Rust code. This was, for example,
the case when a code example was marked `sh` for shell
code.

This relieves authors of having to mark those samples
as `notrust`.

Also adds recognition of the positive marker `rust`.

By default, unmarked examples are still considered rust.

If any rust-specific tags are seen, code is considered
rust unless marked as "notrust".

Adds test cases for the detection logic.
@skade
Copy link
Contributor Author

skade commented Jun 1, 2014

Sure, I added one with all important examples.

bors added a commit that referenced this pull request Jun 2, 2014
…r=alexcrichton

This changes the parsing of the language string
in code examples so that unrecognized examples
are not considered Rust code. This was, for example,
the case when a code example was marked `sh` for shell
code.

This relieves authors of having to mark those samples
as `notrust`.

Also adds recognition of the positive marker `rust`.

By default, unmarked examples are still considered rust.
@bors bors closed this Jun 2, 2014
@bors bors merged commit 3fef7a7 into rust-lang:master Jun 2, 2014
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.

4 participants