Struct rustfmt_nightly::config::license::TemplateParser[][src]

pub(crate) struct TemplateParser {
    parsed: String,
    buffer: String,
    state: ParsingState,
    linum: u32,
    open_brace_line: u32,
}

Fields

parsed: Stringbuffer: Stringstate: ParsingStatelinum: u32open_brace_line: u32

Implementations

Converts a license template into a string which can be turned into a regex.

The license template could use regex syntax directly, but that would require a lot of manual escaping, which is inconvenient. It is therefore literal by default, with optional regex subparts delimited by { and }. Additionally:

  • to insert literal {, } or \, escape it with \
  • an empty regex placeholder ({}) is shorthand for {.*?}

This function parses this input format and builds a properly escaped string representation of the equivalent regular expression. It does not however guarantee that the returned string is a syntactically valid regular expression.

Examples
assert_eq!(
    TemplateParser::parse(
        r"
// Copyright {\d+} The \} Rust \\ Project \{ Developers. See the {([A-Z]+)}
// file at the top-level directory of this distribution and at
// {}.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
"
    ).unwrap(),
    r"^
// Copyright \d+ The \} Rust \\ Project \{ Developers\. See the ([A-Z]+)
// file at the top\-level directory of this distribution and at
// .*?\.
//
// Licensed under the Apache License, Version 2\.0 <LICENSE\-APACHE or
// http://www\.apache\.org/licenses/LICENSE\-2\.0> or the MIT license
// <LICENSE\-MIT or http://opensource\.org/licenses/MIT>, at your
// option\. This file may not be copied, modified, or distributed
// except according to those terms\.
"
);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Layout

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 88 bytes