pub struct NamingHelper;
Expand description

Struct used as namespace only

Implementations

Checks whether the given name is a reserved Rust keyword

use parol::generators::NamingHelper as NmHlp;
assert!(!NmHlp::is_rust_keyword("Type"));
assert!(NmHlp::is_rust_keyword("type"));

Checks whether the symbol starts with “r#”

use parol::generators::naming_helper::NamingHelper;

assert!(NamingHelper::is_raw_identifier("r#let"));
assert!(!NamingHelper::is_raw_identifier("_let"));

If the given name is a reserved Rust keyword it is converted into a raw identifier

use parol::generators::NamingHelper as NmHlp;
assert_eq!("Type".to_string(), NmHlp::escape_rust_keyword("Type".to_string()));
assert_eq!("r#type".to_string(), NmHlp::escape_rust_keyword("type".to_string()));

Returns an underscore string if the item is not used.

Returns an underscore string if the item is not used.

use parol::generators::naming_helper::NamingHelper;

assert_eq!(NamingHelper::add_unused_indicator(false, "r#let"), "_let");
assert_eq!(NamingHelper::add_unused_indicator(false, "x"), "_x");
assert_eq!(NamingHelper::add_unused_indicator(true, "x"), "x");

Produces a lower snake camel case version of the given name. Since these names are supposed to be used as identifiers a clash with rust keywords is detected and prevented.

use parol::generators::NamingHelper as NmHlp;
assert_eq!("prolog0", NmHlp::to_lower_snake_case("Prolog0"));
assert_eq!("_prolog_0_", NmHlp::to_lower_snake_case("_prolog_0_"));
assert_eq!("_prolog_0_1_3", NmHlp::to_lower_snake_case("_prolog_0_1__3"));
assert_eq!("_", NmHlp::to_lower_snake_case("_____"));
assert_eq!("calc_lst1_1", NmHlp::to_lower_snake_case("calc_lst1_1"));
assert_eq!("nor_op_23", NmHlp::to_lower_snake_case("nor_op_23"));
assert_eq!("r#type", NmHlp::to_lower_snake_case("type"));

Produces an upper camel case version of the given name. Separated numbers are kept separated. Camel case compliant input should be preserved.

use parol::generators::NamingHelper as NmHlp;
assert_eq!("Prolog0", NmHlp::to_upper_camel_case("_prolog_0"));
assert_eq!("Prolog0", NmHlp::to_upper_camel_case("_prolog_0_"));
assert_eq!("Prolog0", NmHlp::to_upper_camel_case("_prolog_0__"));
assert_eq!("Prolog0_1", NmHlp::to_upper_camel_case("_prolog_0__1"));
assert_eq!("Prolog0_1_10_20", NmHlp::to_upper_camel_case("_prolog_0__1_10___20__"));
assert_eq!("Prolog0A", NmHlp::to_upper_camel_case("_prolog_0__a"));
assert_eq!("PrologAA", NmHlp::to_upper_camel_case("_prolog_a_a"));
assert_eq!("PrologItem", NmHlp::to_upper_camel_case("prolog_item"));
assert_eq!("PrologItem", NmHlp::to_upper_camel_case("PrologItem"));
assert_eq!("AA", NmHlp::to_upper_camel_case("_a_a_"));

This is a very restrictive definition of allowed characters in identifiers parol allows. Invalid characters in terminal names, non-terminal names and module names are typically replaced by the underscore character and can later be removed during name generations using special casing rules like UpperCamelCase.

use parol::generators::naming_helper::NamingHelper;

assert!(NamingHelper::is_valid_name_character('a'));
assert!(NamingHelper::is_valid_name_character('A'));
assert!(NamingHelper::is_valid_name_character('1'));
assert!(NamingHelper::is_valid_name_character('_'));

assert!(!NamingHelper::is_valid_name_character('-'));
assert!(!NamingHelper::is_valid_name_character(':'));
assert!(!NamingHelper::is_valid_name_character('/'));

Replaces all invalid characters from the given name with underscores. It is used to process user given names which are for instance given as command arguments.

Examples
use parol::generators::naming_helper::NamingHelper;

assert_eq!(NamingHelper::purge_name("test-module"), "test_module");

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Set the foreground color generically Read more

Set the background color generically. Read more

Change the foreground color to black

Change the background color to black

Change the foreground color to red

Change the background color to red

Change the foreground color to green

Change the background color to green

Change the foreground color to yellow

Change the background color to yellow

Change the foreground color to blue

Change the background color to blue

Change the foreground color to magenta

Change the background color to magenta

Change the foreground color to purple

Change the background color to purple

Change the foreground color to cyan

Change the background color to cyan

Change the foreground color to white

Change the background color to white

Change the foreground color to the terminal default

Change the background color to the terminal default

Change the foreground color to bright black

Change the background color to bright black

Change the foreground color to bright red

Change the background color to bright red

Change the foreground color to bright green

Change the background color to bright green

Change the foreground color to bright yellow

Change the background color to bright yellow

Change the foreground color to bright blue

Change the background color to bright blue

Change the foreground color to bright magenta

Change the background color to bright magenta

Change the foreground color to bright purple

Change the background color to bright purple

Change the foreground color to bright cyan

Change the background color to bright cyan

Change the foreground color to bright white

Change the background color to bright white

Make the text bold

Make the text dim

Make the text italicized

Make the text italicized

Make the text blink

Make the text blink (but fast!)

Swap the foreground and background colors

Hide the text

Cross out the text

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more

Set the foreground color to a specific RGB value.

Set the background color to a specific RGB value.

Sets the foreground color to an RGB value.

Sets the background color to an RGB value.

Apply a runtime-determined style

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.