nff: LexError should include position for InvalidNumber; update diagnostics
This commit is contained in:
parent
728483d84f
commit
c0002f5806
2 changed files with 49 additions and 24 deletions
|
@ -453,7 +453,7 @@ impl AnalyzerModule for LexicalAnalyzer {
|
|||
}
|
||||
|
||||
impl LexicalAnalyzer {
|
||||
fn lex_error_to_diagnostic(error: &LexError, source: &str) -> Diagnostic {
|
||||
pub fn lex_error_to_diagnostic(error: &LexError, source: &str) -> Diagnostic {
|
||||
match error {
|
||||
LexError::InvalidToken { position, text } => {
|
||||
let pos = Position::from_text_size(TextSize::from(*position as u32), source);
|
||||
|
@ -478,27 +478,17 @@ impl LexicalAnalyzer {
|
|||
"Unterminated string literal".to_string(),
|
||||
)
|
||||
}
|
||||
LexError::InvalidNumber { text } => {
|
||||
if let Some(pos) = source.find(text) {
|
||||
let start_pos = Position::from_text_size(TextSize::from(pos as u32), source);
|
||||
let end_pos =
|
||||
Position::new(start_pos.line, start_pos.character + text.len() as u32);
|
||||
let range = Range::new(start_pos, end_pos);
|
||||
Diagnostic::new(
|
||||
range,
|
||||
DiagnosticSeverity::Error,
|
||||
DiagnosticCode::InvalidNumber,
|
||||
format!("Invalid number: '{}'", text),
|
||||
)
|
||||
} else {
|
||||
let range = Range::single_position(Position::new(0, 0));
|
||||
Diagnostic::new(
|
||||
range,
|
||||
DiagnosticSeverity::Error,
|
||||
DiagnosticCode::InvalidNumber,
|
||||
format!("Invalid number: '{}'", text),
|
||||
)
|
||||
}
|
||||
LexError::InvalidNumber { position, text } => {
|
||||
let start_pos = Position::from_text_size(TextSize::from(*position as u32), source);
|
||||
let end_pos =
|
||||
Position::new(start_pos.line, start_pos.character + text.len() as u32);
|
||||
let range = Range::new(start_pos, end_pos);
|
||||
Diagnostic::new(
|
||||
range,
|
||||
DiagnosticSeverity::Error,
|
||||
DiagnosticCode::InvalidNumber,
|
||||
format!("Invalid number: '{}'", text),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue