mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-02 05:31:11 +00:00
Update: doc comment
This commit is contained in:
parent
f79eb25975
commit
d080e21b78
2 changed files with 66 additions and 1 deletions
|
@ -397,10 +397,56 @@ pub struct SubMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SubMessage {
|
impl SubMessage {
|
||||||
|
///
|
||||||
|
/// Used when the msg or hint si empty.
|
||||||
|
/// `msg` is Vec\<String\> instead of Option\<String\> because it can be used when there are multiple `msg`s as well as multiple lines.
|
||||||
|
/// # Example
|
||||||
|
/// ```
|
||||||
|
/// let msg = SubMessage::ambiguous_new(loc, vec![], None); // this code same as only_loc()
|
||||||
|
///
|
||||||
|
/// let hint = Some("hint message here".to_string())
|
||||||
|
/// let msg = SubMessage::ambiguous_new(loc, vec![], hint);
|
||||||
|
/// /* example
|
||||||
|
/// -------
|
||||||
|
/// `- hint message here
|
||||||
|
/// */
|
||||||
|
///
|
||||||
|
/// let hint = Some("hint here".to_string())
|
||||||
|
/// let first = StyledString::new("1th message", Color::Red, None);
|
||||||
|
/// let second = StyledString::new("2th message", Color::White, None);
|
||||||
|
/// :
|
||||||
|
/// let nth = StyledString::new("nth message", Color::Green, None);
|
||||||
|
/// let msg = SubMessage::ambiguous_new(
|
||||||
|
/// loc,
|
||||||
|
/// vec![
|
||||||
|
/// first.to_string(),
|
||||||
|
/// second.to_string(),
|
||||||
|
/// ...,
|
||||||
|
/// nth.to_string(),
|
||||||
|
/// ],
|
||||||
|
/// hint);
|
||||||
|
/// /* example
|
||||||
|
/// -------
|
||||||
|
/// :- 1th message
|
||||||
|
/// :- 2th message
|
||||||
|
/// :
|
||||||
|
/// :- nth message
|
||||||
|
/// `- hint here
|
||||||
|
/// */
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
pub fn ambiguous_new(loc: Location, msg: Vec<String>, hint: Option<String>) -> Self {
|
pub fn ambiguous_new(loc: Location, msg: Vec<String>, hint: Option<String>) -> Self {
|
||||||
Self { loc, msg, hint }
|
Self { loc, msg, hint }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Used when only Location is fixed.
|
||||||
|
/// In this case, error position is just modified
|
||||||
|
/// # Example
|
||||||
|
/// ```
|
||||||
|
/// let sub_msg = SubMessage::only_loc(loc);
|
||||||
|
/// ```
|
||||||
pub fn only_loc(loc: Location) -> Self {
|
pub fn only_loc(loc: Location) -> Self {
|
||||||
Self {
|
Self {
|
||||||
loc,
|
loc,
|
||||||
|
|
|
@ -313,6 +313,14 @@ pub struct StyledString {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StyledString {
|
impl StyledString {
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```
|
||||||
|
/// let s = String::from("Hello, world");
|
||||||
|
/// StyledString::new(s, None, None);
|
||||||
|
/// let s = "Hello, world";
|
||||||
|
/// StyledString::new(s, None, None);
|
||||||
|
/// ```
|
||||||
pub fn new<'a, S: Into<Cow<'a, str>>>(
|
pub fn new<'a, S: Into<Cow<'a, str>>>(
|
||||||
s: S,
|
s: S,
|
||||||
color: Option<Color>,
|
color: Option<Color>,
|
||||||
|
@ -464,7 +472,18 @@ impl StyledStrings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_same_color(&self, color: Color) -> bool {
|
///
|
||||||
|
/// Determine if all strings in Vec are empty
|
||||||
|
/// Returns False if any string is present.
|
||||||
|
///
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.texts
|
||||||
|
.iter()
|
||||||
|
.inspect(|x| println!("{:#?}", x))
|
||||||
|
.all(|s| s.is_empty())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_same_color(&self, color: Color) -> bool {
|
||||||
if let Some(text) = self.texts.last() {
|
if let Some(text) = self.texts.last() {
|
||||||
return text.color == Some(color);
|
return text.color == Some(color);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue