+8
CHANGELOG.md
+8
CHANGELOG.md
···
5
5
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
8
+
## v0.9.2 -- 2023-04-14
9
+
10
+
### Library
11
+
12
+
#### Added
13
+
14
+
- The `parse_error::Excerpt` type, which is used to show source excerpts, is now public.
15
+
8
16
## v0.9.1 -- 2023-04-03
9
17
10
18
### CLI
+1
-1
Cargo.toml
+1
-1
Cargo.toml
+6
-4
src/parse_error.rs
+6
-4
src/parse_error.rs
···
357
357
//-----------------------------------------------------------------------------
358
358
359
359
/// Excerpts of source from either the target language file or the tsg rules file.
360
-
pub(crate) struct Excerpt<'a> {
360
+
pub struct Excerpt<'a> {
361
361
path: &'a Path,
362
362
source: Option<&'a str>,
363
363
row: usize,
···
370
370
path: &'a Path,
371
371
source: &'a str,
372
372
row: usize,
373
-
columns: Range<usize>,
373
+
mut columns: Range<usize>,
374
374
indent: usize,
375
375
) -> Excerpt<'a> {
376
+
let source = source.lines().nth(row);
377
+
columns.end = std::cmp::min(columns.end, source.map(|s| s.len()).unwrap_or_default());
376
378
Excerpt {
377
379
path,
378
-
source: source.lines().nth(row),
380
+
source,
379
381
row,
380
382
columns,
381
383
indent,
···
394
396
f,
395
397
"{}{}:{}:{}:",
396
398
" ".repeat(self.indent),
397
-
white_bold(&self.path.to_str().unwrap_or("<unknown file>")),
399
+
white_bold(&self.path.to_string_lossy()),
398
400
white_bold(&format!("{}", self.row + 1)),
399
401
white_bold(&format!("{}", self.columns.start + 1)),
400
402
)?;