mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Remove line/column fields
This commit is contained in:
parent
eb35e9914f
commit
8e1241adea
4 changed files with 37 additions and 67 deletions
|
@ -944,12 +944,12 @@ mod test_can {
|
||||||
let problem = Problem::RuntimeError(RuntimeError::CircularDef(vec![CycleEntry {
|
let problem = Problem::RuntimeError(RuntimeError::CircularDef(vec![CycleEntry {
|
||||||
symbol: interns.symbol(home, "x".into()),
|
symbol: interns.symbol(home, "x".into()),
|
||||||
symbol_region: Region::new(
|
symbol_region: Region::new(
|
||||||
Position::new(0, 0, 0),
|
Position::new(0),
|
||||||
Position::new(1, 0, 0),
|
Position::new(1),
|
||||||
),
|
),
|
||||||
expr_region: Region::new(
|
expr_region: Region::new(
|
||||||
Position::new(4, 0, 0),
|
Position::new(4),
|
||||||
Position::new(5, 0, 0),
|
Position::new(5),
|
||||||
),
|
),
|
||||||
}]));
|
}]));
|
||||||
|
|
||||||
|
@ -981,34 +981,34 @@ mod test_can {
|
||||||
CycleEntry {
|
CycleEntry {
|
||||||
symbol: interns.symbol(home, "x".into()),
|
symbol: interns.symbol(home, "x".into()),
|
||||||
symbol_region: Region::new(
|
symbol_region: Region::new(
|
||||||
Position::new(0, 0, 0),
|
Position::new(0),
|
||||||
Position::new(1, 0, 0),
|
Position::new(1),
|
||||||
),
|
),
|
||||||
expr_region: Region::new(
|
expr_region: Region::new(
|
||||||
Position::new(4, 0, 0),
|
Position::new(4),
|
||||||
Position::new(5, 0, 0),
|
Position::new(5),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
CycleEntry {
|
CycleEntry {
|
||||||
symbol: interns.symbol(home, "y".into()),
|
symbol: interns.symbol(home, "y".into()),
|
||||||
symbol_region: Region::new(
|
symbol_region: Region::new(
|
||||||
Position::new(6, 0, 0),
|
Position::new(6),
|
||||||
Position::new(7, 0, 0),
|
Position::new(7),
|
||||||
),
|
),
|
||||||
expr_region: Region::new(
|
expr_region: Region::new(
|
||||||
Position::new(10, 0, 0),
|
Position::new(10),
|
||||||
Position::new(11, 0, 0),
|
Position::new(11),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
CycleEntry {
|
CycleEntry {
|
||||||
symbol: interns.symbol(home, "z".into()),
|
symbol: interns.symbol(home, "z".into()),
|
||||||
symbol_region: Region::new(
|
symbol_region: Region::new(
|
||||||
Position::new(12, 0, 0),
|
Position::new(12),
|
||||||
Position::new(13, 0, 0),
|
Position::new(13),
|
||||||
),
|
),
|
||||||
expr_region: Region::new(
|
expr_region: Region::new(
|
||||||
Position::new(16, 0, 0),
|
Position::new(16),
|
||||||
Position::new(17, 0, 0),
|
Position::new(17),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
]));
|
]));
|
||||||
|
|
|
@ -45,10 +45,7 @@ impl<'a> State<'a> {
|
||||||
|
|
||||||
/// Returns the current position
|
/// Returns the current position
|
||||||
pub const fn pos(&self) -> Position {
|
pub const fn pos(&self) -> Position {
|
||||||
Position::new(
|
Position::new((self.input_len - self.bytes.len()) as u32)
|
||||||
(self.input_len - self.bytes.len()) as u32,
|
|
||||||
self.xyzlcol.line,
|
|
||||||
self.xyzlcol.column)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the parser has reached the end of the input
|
/// Returns whether the parser has reached the end of the input
|
||||||
|
@ -102,15 +99,7 @@ impl<'a> State<'a> {
|
||||||
pub fn len_region(&self, length: u16) -> Region {
|
pub fn len_region(&self, length: u16) -> Region {
|
||||||
Region::new(
|
Region::new(
|
||||||
self.pos(),
|
self.pos(),
|
||||||
Position::new(
|
self.pos().bump_column(length),
|
||||||
self.pos().bump_column(length).offset,
|
|
||||||
self.xyzlcol.line,
|
|
||||||
self
|
|
||||||
.xyzlcol
|
|
||||||
.column
|
|
||||||
.checked_add(length)
|
|
||||||
.unwrap_or_else(|| panic!("len_region overflowed")),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -366,7 +366,7 @@ mod test_parse {
|
||||||
assert_segments(r#""Hi, \u(123)!""#, |arena| {
|
assert_segments(r#""Hi, \u(123)!""#, |arena| {
|
||||||
bumpalo::vec![in arena;
|
bumpalo::vec![in arena;
|
||||||
Plaintext("Hi, "),
|
Plaintext("Hi, "),
|
||||||
Unicode(Loc::new(Position::new(8, 0, 0), Position::new(11, 0, 0), "123")),
|
Unicode(Loc::new(8, 11, "123")),
|
||||||
Plaintext("!")
|
Plaintext("!")
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@ -376,7 +376,7 @@ mod test_parse {
|
||||||
fn unicode_escape_in_front() {
|
fn unicode_escape_in_front() {
|
||||||
assert_segments(r#""\u(1234) is a unicode char""#, |arena| {
|
assert_segments(r#""\u(1234) is a unicode char""#, |arena| {
|
||||||
bumpalo::vec![in arena;
|
bumpalo::vec![in arena;
|
||||||
Unicode(Loc::new(Position::new(4, 0, 0), Position::new(8, 0, 0), "1234")),
|
Unicode(Loc::new(4, 8, "1234")),
|
||||||
Plaintext(" is a unicode char")
|
Plaintext(" is a unicode char")
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@ -387,7 +387,7 @@ mod test_parse {
|
||||||
assert_segments(r#""this is unicode: \u(1)""#, |arena| {
|
assert_segments(r#""this is unicode: \u(1)""#, |arena| {
|
||||||
bumpalo::vec![in arena;
|
bumpalo::vec![in arena;
|
||||||
Plaintext("this is unicode: "),
|
Plaintext("this is unicode: "),
|
||||||
Unicode(Loc::new(Position::new(21, 0, 0), Position::new(22, 0, 0), "1"))
|
Unicode(Loc::new(21, 22, "1"))
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -396,11 +396,11 @@ mod test_parse {
|
||||||
fn unicode_escape_multiple() {
|
fn unicode_escape_multiple() {
|
||||||
assert_segments(r#""\u(a1) this is \u(2Bcd) unicode \u(ef97)""#, |arena| {
|
assert_segments(r#""\u(a1) this is \u(2Bcd) unicode \u(ef97)""#, |arena| {
|
||||||
bumpalo::vec![in arena;
|
bumpalo::vec![in arena;
|
||||||
Unicode(Loc::new(Position::new(4, 0, 0), Position::new(6, 0, 0), "a1")),
|
Unicode(Loc::new(4, 6, "a1")),
|
||||||
Plaintext(" this is "),
|
Plaintext(" this is "),
|
||||||
Unicode(Loc::new(Position::new(19, 0, 0), Position::new(23, 0, 0), "2Bcd")),
|
Unicode(Loc::new(19, 23, "2Bcd")),
|
||||||
Plaintext(" unicode "),
|
Plaintext(" unicode "),
|
||||||
Unicode(Loc::new(Position::new(36, 0, 0), Position::new(40, 0, 0), "ef97"))
|
Unicode(Loc::new(36, 40, "ef97"))
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -417,7 +417,7 @@ mod test_parse {
|
||||||
|
|
||||||
bumpalo::vec![in arena;
|
bumpalo::vec![in arena;
|
||||||
Plaintext("Hi, "),
|
Plaintext("Hi, "),
|
||||||
Interpolated(Loc::new(Position::new(7, 0, 0), Position::new(11, 0, 0), expr)),
|
Interpolated(Loc::new(7, 11, expr)),
|
||||||
Plaintext("!")
|
Plaintext("!")
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@ -432,7 +432,7 @@ mod test_parse {
|
||||||
});
|
});
|
||||||
|
|
||||||
bumpalo::vec![in arena;
|
bumpalo::vec![in arena;
|
||||||
Interpolated(Loc::new(Position::new(3, 0, 0), Position::new(7, 0, 0), expr)),
|
Interpolated(Loc::new(3, 7, expr)),
|
||||||
Plaintext(", hi!")
|
Plaintext(", hi!")
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@ -448,7 +448,7 @@ mod test_parse {
|
||||||
|
|
||||||
bumpalo::vec![in arena;
|
bumpalo::vec![in arena;
|
||||||
Plaintext("Hello "),
|
Plaintext("Hello "),
|
||||||
Interpolated(Loc::new(Position::new(9, 0, 0), Position::new(13, 0, 0), expr))
|
Interpolated(Loc::new(9, 13, expr))
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -468,9 +468,9 @@ mod test_parse {
|
||||||
|
|
||||||
bumpalo::vec![in arena;
|
bumpalo::vec![in arena;
|
||||||
Plaintext("Hi, "),
|
Plaintext("Hi, "),
|
||||||
Interpolated(Loc::new(Position::new(7, 0, 0), Position::new(11, 0, 0), expr1)),
|
Interpolated(Loc::new(7, 11, expr1)),
|
||||||
Plaintext("! How is "),
|
Plaintext("! How is "),
|
||||||
Interpolated(Loc::new(Position::new(23, 0, 0), Position::new(30, 0, 0), expr2)),
|
Interpolated(Loc::new(23, 30, expr2)),
|
||||||
Plaintext(" going?")
|
Plaintext(" going?")
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
|
@ -101,8 +101,6 @@ impl fmt::Debug for Region {
|
||||||
#[derive(Copy, Clone, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Copy, Clone, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
pub struct Position {
|
pub struct Position {
|
||||||
pub offset: u32,
|
pub offset: u32,
|
||||||
line: u32,
|
|
||||||
column: u16,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for Position {
|
impl PartialEq for Position {
|
||||||
|
@ -113,18 +111,16 @@ impl PartialEq for Position {
|
||||||
|
|
||||||
impl Position {
|
impl Position {
|
||||||
pub const fn zero() -> Position {
|
pub const fn zero() -> Position {
|
||||||
Position { offset: 0, line: 0, column: 0 }
|
Position { offset: 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn new(offset: u32, line: u32, column: u16) -> Position {
|
pub const fn new(offset: u32) -> Position {
|
||||||
Position { offset, line, column }
|
Position { offset }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn bump_column(self, count: u16) -> Self {
|
pub const fn bump_column(self, count: u16) -> Self {
|
||||||
Self {
|
Self {
|
||||||
line: self.line,
|
|
||||||
column: self.column + count,
|
|
||||||
offset: self.offset + count as u32,
|
offset: self.offset + count as u32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,8 +128,6 @@ impl Position {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn bump_invisible(self, count: u16) -> Self {
|
pub fn bump_invisible(self, count: u16) -> Self {
|
||||||
Self {
|
Self {
|
||||||
line: self.line,
|
|
||||||
column: self.column,
|
|
||||||
offset: self.offset + count as u32,
|
offset: self.offset + count as u32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,8 +135,6 @@ impl Position {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn bump_newline(self) -> Self {
|
pub fn bump_newline(self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
line: self.line + 1,
|
|
||||||
column: 0,
|
|
||||||
offset: self.offset + 1,
|
offset: self.offset + 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,8 +143,6 @@ impl Position {
|
||||||
pub const fn sub(self, count: u16) -> Self {
|
pub const fn sub(self, count: u16) -> Self {
|
||||||
Self {
|
Self {
|
||||||
offset: self.offset - count as u32,
|
offset: self.offset - count as u32,
|
||||||
line: self.line,
|
|
||||||
column: self.column - count,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,8 +295,8 @@ pub struct Loc<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Loc<T> {
|
impl<T> Loc<T> {
|
||||||
pub fn new(start: Position, end: Position, value: T) -> Loc<T> {
|
pub fn new(start: u32, end: u32, value: T) -> Loc<T> {
|
||||||
let region = Region::new(start, end);
|
let region = Region::new(Position::new(start), Position::new(end));
|
||||||
Loc { region, value }
|
Loc { region, value }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,23 +376,14 @@ impl LineInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_pos(&self, pos: Position) -> LineColumn {
|
pub fn convert_pos(&self, pos: Position) -> LineColumn {
|
||||||
let res = self.convert_offset(pos.offset);
|
self.convert_offset(pos.offset)
|
||||||
// let expected = LineColumn { line: pos.line, column: pos.column };
|
|
||||||
// assert_eq!(expected, res);
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_region(&self, region: Region) -> LineColumnRegion {
|
pub fn convert_region(&self, region: Region) -> LineColumnRegion {
|
||||||
let res = LineColumnRegion {
|
LineColumnRegion {
|
||||||
start: self.convert_pos(region.start()),
|
start: self.convert_pos(region.start()),
|
||||||
end: self.convert_pos(region.end()),
|
end: self.convert_pos(region.end()),
|
||||||
};
|
}
|
||||||
let expected = LineColumnRegion::new(
|
|
||||||
LineColumn { line: region.start.line, column: region.start.column },
|
|
||||||
LineColumn { line: region.end.line, column: region.end.column },
|
|
||||||
);
|
|
||||||
assert_eq!(expected, res);
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue