lib_ruby_parser/source/source_line.rs
1#[repr(C)]
2#[derive(Debug, Clone, Default, PartialEq, Eq)]
3/// Representation of a source line in a source file
4pub struct SourceLine {
5 /// Start of the line (in bytes)
6 pub start: usize,
7
8 /// End of the line (in bytes)
9 pub end: usize,
10
11 /// `true` if line ends with EOF char (which is true for the last line in the file)
12 pub ends_with_eof: bool,
13}
14
15impl SourceLine {
16 /// Returns length of the line
17 pub fn len(&self) -> usize {
18 self.end - self.start
19 }
20
21 /// Returns true if SourceLine is empty (i.e. has `len = 0`)
22 pub fn is_empty(&self) -> bool {
23 self.len() == 0
24 }
25
26 /// Returns location of the last non-EOF, non-EOL character
27 pub fn line_end(&self) -> usize {
28 let mut result = self.end;
29 if !self.ends_with_eof {
30 result -= 1 // exclude trailing \n
31 }
32 result
33 }
34}