mirror of
https://github.com/Dummi26/mers.git
synced 2026-03-13 03:52:27 +01:00
improve and move theming traits
move pretty_print.rs from mers to mers_lib
This commit is contained in:
@@ -308,6 +308,9 @@ impl Source {
|
||||
line
|
||||
}
|
||||
|
||||
pub fn get_pos_last_char(&self) -> SourcePos {
|
||||
SourcePos(self.i.saturating_sub(1))
|
||||
}
|
||||
pub fn get_pos(&self) -> SourcePos {
|
||||
SourcePos(self.i)
|
||||
}
|
||||
|
||||
@@ -555,7 +555,7 @@ pub fn parse_string(
|
||||
srca: &Arc<Source>,
|
||||
double_quote: SourcePos,
|
||||
) -> Result<String, CheckError> {
|
||||
parse_string_custom_end(src, srca, double_quote, '"', '"')
|
||||
parse_string_custom_end(src, srca, double_quote, '"', '"', "", EColor::StringEOF)
|
||||
}
|
||||
pub fn parse_string_custom_end(
|
||||
src: &mut Source,
|
||||
@@ -563,6 +563,8 @@ pub fn parse_string_custom_end(
|
||||
opening: SourcePos,
|
||||
opening_char: char,
|
||||
closing_char: char,
|
||||
string_prefix: &str,
|
||||
eof_color: EColor,
|
||||
) -> Result<String, CheckError> {
|
||||
let mut s = String::new();
|
||||
loop {
|
||||
@@ -602,13 +604,13 @@ pub fn parse_string_custom_end(
|
||||
return Err(CheckError::new()
|
||||
.src(vec![(
|
||||
(opening, src.get_pos(), srca).into(),
|
||||
Some(EColor::StringEOF),
|
||||
Some(eof_color),
|
||||
)])
|
||||
.msg_str(format!(
|
||||
"EOF in string literal{}",
|
||||
"EOF in {string_prefix}string literal{}",
|
||||
if closing_char != '"' {
|
||||
format!(
|
||||
"{opening_char}...{closing_char} (end string with '{closing_char}')"
|
||||
" {opening_char}...{closing_char} (end string with '{closing_char}')"
|
||||
)
|
||||
} else {
|
||||
String::new()
|
||||
|
||||
@@ -24,6 +24,7 @@ pub fn parse_single_type(src: &mut Source, srca: &Arc<Source>) -> Result<ParsedT
|
||||
Ok(match src.peek_char() {
|
||||
// Reference
|
||||
Some('&') => {
|
||||
let pos_in_src = src.get_pos();
|
||||
src.next_char();
|
||||
if let Some('[') = src.peek_char() {
|
||||
src.next_char();
|
||||
@@ -35,9 +36,14 @@ pub fn parse_single_type(src: &mut Source, srca: &Arc<Source>) -> Result<ParsedT
|
||||
} else {
|
||||
format!("EOF")
|
||||
};
|
||||
return Err(CheckError::new().msg_str(format!(
|
||||
"No closing ] in reference type with opening [! Found {nc} instead"
|
||||
)));
|
||||
return Err(CheckError::new()
|
||||
.src(vec![(
|
||||
(pos_in_src, src.get_pos(), srca).into(),
|
||||
Some(EColor::BracketedRefTypeNoClosingBracket),
|
||||
)])
|
||||
.msg_str(format!(
|
||||
"No closing ] in reference type with opening [! Found {nc} instead"
|
||||
)));
|
||||
}
|
||||
ParsedType::Reference(types)
|
||||
} else {
|
||||
@@ -177,13 +183,28 @@ pub fn parse_single_type(src: &mut Source, srca: &Arc<Source>) -> Result<ParsedT
|
||||
src.next_char();
|
||||
ParsedType::TypeWithInfo(
|
||||
t,
|
||||
super::statements::parse_string_custom_end(src, srca, pos, '<', '>')?,
|
||||
super::statements::parse_string_custom_end(
|
||||
src,
|
||||
srca,
|
||||
pos,
|
||||
'<',
|
||||
'>',
|
||||
"type-info ",
|
||||
EColor::TypeEOF,
|
||||
)?,
|
||||
)
|
||||
} else {
|
||||
ParsedType::Type(t)
|
||||
}
|
||||
}
|
||||
None => todo!(),
|
||||
None => {
|
||||
return Err(CheckError::new()
|
||||
.src(vec![(
|
||||
(src.get_pos_last_char(), src.get_pos(), srca).into(),
|
||||
Some(EColor::TypeEOF),
|
||||
)])
|
||||
.msg_str(format!("Expected type, got EOF")))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user