summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax')
-rw-r--r--src/syntax/ast.rs6
-rw-r--r--src/syntax/highlight.rs46
-rw-r--r--src/syntax/incremental.rs49
-rw-r--r--src/syntax/mod.rs13
-rw-r--r--src/syntax/node.rs16
-rw-r--r--src/syntax/parser.rs16
-rw-r--r--src/syntax/parsing.rs85
-rw-r--r--src/syntax/resolve.rs12
-rw-r--r--src/syntax/source.rs51
-rw-r--r--src/syntax/span.rs2
-rw-r--r--src/syntax/tokens.rs21
11 files changed, 159 insertions, 158 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs
index 06e41fa0..61b8f0e6 100644
--- a/src/syntax/ast.rs
+++ b/src/syntax/ast.rs
@@ -1471,7 +1471,11 @@ impl ForPattern {
pub fn key(&self) -> Option<Ident> {
let mut children = self.0.children().filter_map(SyntaxNode::cast);
let key = children.next();
- if children.next().is_some() { key } else { None }
+ if children.next().is_some() {
+ key
+ } else {
+ None
+ }
}
/// The value part of the pattern.
diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs
index 0db45785..d5345fab 100644
--- a/src/syntax/highlight.rs
+++ b/src/syntax/highlight.rs
@@ -81,7 +81,7 @@ where
F: FnMut(Range<usize>, Style),
{
if node.children().len() == 0 {
- let range = offset .. offset + node.len();
+ let range = offset..offset + node.len();
let style = highlighter.style_for_stack(&scopes);
f(range, style);
return;
@@ -112,7 +112,7 @@ where
F: FnMut(Range<usize>, Category),
{
for (i, child) in node.children().enumerate() {
- let span = offset .. offset + child.len();
+ let span = offset..offset + child.len();
if range.start <= span.end && range.end >= span.start {
if let Some(category) = Category::determine(child, node, i) {
f(span, category);
@@ -412,29 +412,35 @@ mod tests {
fn test(text: &str, goal: &[(Range<usize>, Category)]) {
let mut vec = vec![];
let source = Source::detached(text);
- let full = 0 .. text.len();
+ let full = 0..text.len();
highlight_categories(source.root(), full, &mut |range, category| {
vec.push((range, category));
});
assert_eq!(vec, goal);
}
- test("= *AB*", &[(0 .. 6, Heading), (2 .. 6, Strong)]);
-
- test("#f(x + 1)", &[
- (0 .. 2, Function),
- (2 .. 3, Bracket),
- (5 .. 6, Operator),
- (7 .. 8, Number),
- (8 .. 9, Bracket),
- ]);
-
- test("#let f(x) = x", &[
- (0 .. 4, Keyword),
- (5 .. 6, Function),
- (6 .. 7, Bracket),
- (8 .. 9, Bracket),
- (10 .. 11, Operator),
- ]);
+ test("= *AB*", &[(0..6, Heading), (2..6, Strong)]);
+
+ test(
+ "#f(x + 1)",
+ &[
+ (0..2, Function),
+ (2..3, Bracket),
+ (5..6, Operator),
+ (7..8, Number),
+ (8..9, Bracket),
+ ],
+ );
+
+ test(
+ "#let f(x) = x",
+ &[
+ (0..4, Keyword),
+ (5..6, Function),
+ (6..7, Bracket),
+ (8..9, Bracket),
+ (10..11, Operator),
+ ],
+ );
}
}
diff --git a/src/syntax/incremental.rs b/src/syntax/incremental.rs
index 15c0df0c..1087bb79 100644
--- a/src/syntax/incremental.rs
+++ b/src/syntax/incremental.rs
@@ -28,7 +28,7 @@ pub fn reparse(
let id = root.span().source();
*root = parse(text);
root.numberize(id, Span::FULL).unwrap();
- 0 .. text.len()
+ 0..text.len()
}
/// Try to reparse inside the given node.
@@ -55,7 +55,7 @@ fn try_reparse(
// Find the the first child in the range of children to reparse.
for (i, child) in node.children().enumerate() {
let pos = NodePos { idx: i, offset };
- let child_span = offset .. offset + child.len();
+ let child_span = offset..offset + child.len();
child_outermost = outermost && i + 1 == original_count;
match search {
@@ -81,7 +81,7 @@ fn try_reparse(
} else {
// Update compulsary state of `ahead_nontrivia`.
if let Some(ahead_nontrivia) = ahead.as_mut() {
- if let NodeKind::Space { newlines: (1 ..) } = child.kind() {
+ if let NodeKind::Space { newlines: (1..) } = child.kind() {
ahead_nontrivia.newline();
}
}
@@ -126,10 +126,13 @@ fn try_reparse(
// If we were looking for a non-whitespace element and hit the end of
// the file here, we instead use EOF as the end of the span.
if let SearchState::RequireNonTrivia(start) = search {
- search = SearchState::SpanFound(start, NodePos {
- idx: node.children().len() - 1,
- offset: offset - node.children().last().unwrap().len(),
- })
+ search = SearchState::SpanFound(
+ start,
+ NodePos {
+ idx: node.children().len() - 1,
+ offset: offset - node.children().last().unwrap().len(),
+ },
+ )
}
if let SearchState::Contained(pos) = search {
@@ -156,7 +159,7 @@ fn try_reparse(
return Some(range);
}
- let superseded_span = pos.offset .. pos.offset + prev_len;
+ let superseded_span = pos.offset..pos.offset + prev_len;
let func: Option<ReparseMode> = match child.kind() {
NodeKind::CodeBlock => Some(ReparseMode::Code),
NodeKind::ContentBlock => Some(ReparseMode::Content),
@@ -170,7 +173,7 @@ fn try_reparse(
change,
node,
func,
- pos.idx .. pos.idx + 1,
+ pos.idx..pos.idx + 1,
superseded_span,
outermost,
) {
@@ -197,13 +200,13 @@ fn try_reparse(
}
let superseded_span =
- start.offset .. end.offset + node.children().as_slice()[end.idx].len();
+ start.offset..end.offset + node.children().as_slice()[end.idx].len();
replace(
change,
node,
ReparseMode::MarkupElements { at_start, min_indent },
- start.idx .. end.idx + 1,
+ start.idx..end.idx + 1,
superseded_span,
outermost,
)
@@ -223,33 +226,33 @@ fn replace(
let differential: isize =
change.replacement_len as isize - change.replaced.len() as isize;
let newborn_end = (superseded_span.end as isize + differential) as usize;
- let newborn_span = superseded_span.start .. newborn_end;
+ let newborn_span = superseded_span.start..newborn_end;
let mut prefix = "";
- for (i, c) in change.text[.. newborn_span.start].char_indices().rev() {
+ for (i, c) in change.text[..newborn_span.start].char_indices().rev() {
if is_newline(c) {
break;
}
- prefix = &change.text[i .. newborn_span.start];
+ prefix = &change.text[i..newborn_span.start];
}
let (newborns, terminated, amount) = match mode {
ReparseMode::Code => reparse_code_block(
prefix,
- &change.text[newborn_span.start ..],
+ &change.text[newborn_span.start..],
newborn_span.len(),
),
ReparseMode::Content => reparse_content_block(
prefix,
- &change.text[newborn_span.start ..],
+ &change.text[newborn_span.start..],
newborn_span.len(),
),
ReparseMode::MarkupElements { at_start, min_indent } => reparse_markup_elements(
prefix,
- &change.text[newborn_span.start ..],
+ &change.text[newborn_span.start..],
newborn_span.len(),
differential,
- &node.children().as_slice()[superseded_start ..],
+ &node.children().as_slice()[superseded_start..],
at_start,
min_indent,
),
@@ -261,7 +264,7 @@ fn replace(
return None;
}
- node.replace_children(superseded_start .. superseded_start + amount, newborns)
+ node.replace_children(superseded_start..superseded_start + amount, newborns)
.ok()?;
Some(newborn_span)
@@ -351,11 +354,7 @@ impl Ahead {
Self {
pos,
at_start,
- kind: if bounded {
- AheadKind::Normal
- } else {
- AheadKind::Unbounded(true)
- },
+ kind: if bounded { AheadKind::Normal } else { AheadKind::Unbounded(true) },
}
}
@@ -402,7 +401,7 @@ fn is_bounded(kind: &NodeKind) -> bool {
/// previous value of the property.
fn next_at_start(kind: &NodeKind, prev: bool) -> bool {
match kind {
- NodeKind::Space { newlines: (1 ..) } => true,
+ NodeKind::Space { newlines: (1..) } => true,
NodeKind::Space { .. } | NodeKind::LineComment | NodeKind::BlockComment => prev,
_ => false,
}
diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs
index 1a23db5f..2ef49322 100644
--- a/src/syntax/mod.rs
+++ b/src/syntax/mod.rs
@@ -2,6 +2,7 @@
pub mod ast;
pub mod highlight;
+
mod incremental;
mod kind;
mod node;
@@ -12,12 +13,12 @@ mod source;
mod span;
mod tokens;
-pub use kind::*;
-pub use node::*;
-pub use parsing::*;
-pub use source::*;
-pub use span::*;
-pub use tokens::*;
+pub use self::kind::*;
+pub use self::node::*;
+pub use self::parsing::*;
+pub use self::source::*;
+pub use self::span::*;
+pub use self::tokens::*;
use incremental::reparse;
use parser::*;
diff --git a/src/syntax/node.rs b/src/syntax/node.rs
index 4ec4abdf..5758a4bf 100644
--- a/src/syntax/node.rs
+++ b/src/syntax/node.rs
@@ -291,16 +291,16 @@ impl InnerNode {
let mut start = within.start;
if range.is_none() {
let end = start + stride;
- self.data.numberize(id, start .. end)?;
+ self.data.numberize(id, start..end)?;
self.upper = within.end;
start = end;
}
// Number the children.
let len = self.children.len();
- for child in &mut self.children[range.unwrap_or(0 .. len)] {
+ for child in &mut self.children[range.unwrap_or(0..len)] {
let end = start + child.descendants() as u64 * stride;
- child.numberize(id, start .. end)?;
+ child.numberize(id, start..end)?;
start = end;
}
@@ -377,8 +377,8 @@ impl InnerNode {
// - or if we were erroneous before due to a non-superseded node.
self.erroneous = replacement.iter().any(SyntaxNode::erroneous)
|| (self.erroneous
- && (self.children[.. range.start].iter().any(SyntaxNode::erroneous))
- || self.children[range.end ..].iter().any(SyntaxNode::erroneous));
+ && (self.children[..range.start].iter().any(SyntaxNode::erroneous))
+ || self.children[range.end..].iter().any(SyntaxNode::erroneous));
// Perform the replacement.
let replacement_count = replacement.len();
@@ -392,7 +392,7 @@ impl InnerNode {
let max_left = range.start;
let max_right = self.children.len() - range.end;
loop {
- let renumber = range.start - left .. range.end + right;
+ let renumber = range.start - left..range.end + right;
// The minimum assignable number is either
// - the upper bound of the node right before the to-be-renumbered
@@ -416,7 +416,7 @@ impl InnerNode {
.map_or(self.upper(), |next| next.span().number());
// Try to renumber.
- let within = start_number .. end_number;
+ let within = start_number..end_number;
let id = self.span().source();
if self.numberize(id, Some(renumber), within).is_ok() {
return Ok(());
@@ -529,7 +529,7 @@ impl NodeData {
/// If the span points into this node, convert it to a byte range.
fn range(&self, span: Span, offset: usize) -> Option<Range<usize>> {
- (self.span == span).then(|| offset .. offset + self.len())
+ (self.span == span).then(|| offset..offset + self.len())
}
}
diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs
index 4c8e1013..8d51f7eb 100644
--- a/src/syntax/parser.rs
+++ b/src/syntax/parser.rs
@@ -97,7 +97,7 @@ impl<'s> Parser<'s> {
// Trailing trivia should not be wrapped into the new node.
let idx = self.children.len();
self.children.push(SyntaxNode::default());
- self.children.extend(children.drain(until.0 ..));
+ self.children.extend(children.drain(until.0..));
self.children[idx] = InnerNode::with_children(kind, children).into();
}
@@ -177,7 +177,11 @@ impl<'s> Parser<'s> {
/// Peek at the current token without consuming it.
pub fn peek(&self) -> Option<&NodeKind> {
- if self.eof { None } else { self.current.as_ref() }
+ if self.eof {
+ None
+ } else {
+ self.current.as_ref()
+ }
}
/// Peek at the current token, but only if it follows immediately after the
@@ -192,7 +196,7 @@ impl<'s> Parser<'s> {
/// Peek at the source of the current token.
pub fn peek_src(&self) -> &'s str {
- self.get(self.current_start() .. self.current_end())
+ self.get(self.current_start()..self.current_end())
}
/// Obtain a range of the source code.
@@ -303,7 +307,7 @@ impl<'s> Parser<'s> {
if group_mode != TokenMode::Markup {
let start = self.trivia_start().0;
target = self.current_start
- - self.children[start ..].iter().map(SyntaxNode::len).sum::<usize>();
+ - self.children[start..].iter().map(SyntaxNode::len).sum::<usize>();
self.children.truncate(start);
}
@@ -466,7 +470,7 @@ impl Marker {
/// with the given `kind`.
pub fn end(self, p: &mut Parser, kind: NodeKind) {
let until = p.trivia_start().0.max(self.0);
- let children = p.children.drain(self.0 .. until).collect();
+ let children = p.children.drain(self.0..until).collect();
p.children
.insert(self.0, InnerNode::with_children(kind, children).into());
}
@@ -476,7 +480,7 @@ impl Marker {
where
F: FnMut(&SyntaxNode) -> Result<(), &'static str>,
{
- for child in &mut p.children[self.0 ..] {
+ for child in &mut p.children[self.0..] {
// Don't expose errors.
if child.kind().is_error() {
continue;
diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs
index 10b4c4c2..fecc527c 100644
--- a/src/syntax/parsing.rs
+++ b/src/syntax/parsing.rs
@@ -90,7 +90,7 @@ pub(crate) fn reparse_markup_elements(
let mut stopped = false;
'outer: while !p.eof() {
- if let Some(NodeKind::Space { newlines: (1 ..) }) = p.peek() {
+ if let Some(NodeKind::Space { newlines: (1..) }) = p.peek() {
if p.column(p.current_end()) < min_indent {
return None;
}
@@ -167,7 +167,7 @@ fn markup_indented(p: &mut Parser, min_indent: usize) {
while !p.eof() {
match p.peek() {
- Some(NodeKind::Space { newlines: (1 ..) })
+ Some(NodeKind::Space { newlines: (1..) })
if p.column(p.current_end()) < min_indent =>
{
break;
@@ -195,7 +195,7 @@ where
p.perform(NodeKind::Markup { min_indent: usize::MAX }, |p| {
let mut at_start = false;
while let Some(kind) = p.peek() {
- if let NodeKind::Space { newlines: (1 ..) } = kind {
+ if let NodeKind::Space { newlines: (1..) } = kind {
break;
}
@@ -210,11 +210,7 @@ where
/// Parse a markup node.
fn markup_node(p: &mut Parser, at_start: &mut bool) {
- let token = match p.peek() {
- Some(t) => t,
- None => return,
- };
-
+ let Some(token) = p.peek() else { return };
match token {
// Whitespace.
NodeKind::Space { newlines } => {
@@ -316,7 +312,7 @@ fn heading(p: &mut Parser, at_start: bool) {
markup_line(p, |kind| matches!(kind, NodeKind::Label(_)));
marker.end(p, NodeKind::Heading);
} else {
- let text = p.get(current_start .. p.prev_end()).into();
+ let text = p.get(current_start..p.prev_end()).into();
marker.convert(p, NodeKind::Text(text));
}
}
@@ -420,12 +416,9 @@ fn math_node_prec(p: &mut Parser, min_prec: usize, stop: Option<NodeKind>) {
Some(NodeKind::Underscore) => {
(NodeKind::Script, 2, Assoc::Right, Some(NodeKind::Hat))
}
- Some(NodeKind::Hat) => (
- NodeKind::Script,
- 2,
- Assoc::Right,
- Some(NodeKind::Underscore),
- ),
+ Some(NodeKind::Hat) => {
+ (NodeKind::Script, 2, Assoc::Right, Some(NodeKind::Underscore))
+ }
Some(NodeKind::Slash) => (NodeKind::Frac, 1, Assoc::Left, None),
_ => break,
};
@@ -454,11 +447,7 @@ fn math_node_prec(p: &mut Parser, min_prec: usize, stop: Option<NodeKind>) {
/// Parse a primary math node.
fn math_primary(p: &mut Parser) {
- let token = match p.peek() {
- Some(t) => t,
- None => return,
- };
-
+ let Some(token) = p.peek() else { return };
match token {
// Spaces, atoms and expressions.
NodeKind::Space { .. }
@@ -652,7 +641,6 @@ fn literal(p: &mut Parser) -> bool {
p.eat();
true
}
-
_ => false,
}
}
@@ -724,50 +712,51 @@ enum CollectionKind {
/// Returns the length of the collection and whether the literal contained any
/// commas.
fn collection(p: &mut Parser, keyed: bool) -> (CollectionKind, usize) {
- let mut kind = None;
+ let mut collection_kind = None;
let mut items = 0;
let mut can_group = true;
let mut missing_coma: Option<Marker> = None;
while !p.eof() {
- if let Ok(item_kind) = item(p, keyed) {
- match item_kind {
- NodeKind::Spread => can_group = false,
- NodeKind::Named if kind.is_none() => {
- kind = Some(CollectionKind::Named);
- can_group = false;
- }
- _ if kind.is_none() => {
- kind = Some(CollectionKind::Positional);
- }
- _ => {}
+ let Ok(item_kind) = item(p, keyed) else {
+ p.eat_if(NodeKind::Comma);
+ collection_kind = Some(CollectionKind::Group);
+ continue;
+ };
+
+ match item_kind {
+ NodeKind::Spread => can_group = false,
+ NodeKind::Named if collection_kind.is_none() => {
+ collection_kind = Some(CollectionKind::Named);
+ can_group = false;
+ }
+ _ if collection_kind.is_none() => {
+ collection_kind = Some(CollectionKind::Positional);
}
+ _ => {}
+ }
- items += 1;
+ items += 1;
- if let Some(marker) = missing_coma.take() {
- p.expected_at(marker, "comma");
- }
+ if let Some(marker) = missing_coma.take() {
+ p.expected_at(marker, "comma");
+ }
- if p.eof() {
- break;
- }
+ if p.eof() {
+ break;
+ }
- if p.eat_if(NodeKind::Comma) {
- can_group = false;
- } else {
- missing_coma = Some(p.trivia_start());
- }
+ if p.eat_if(NodeKind::Comma) {
+ can_group = false;
} else {
- p.eat_if(NodeKind::Comma);
- kind = Some(CollectionKind::Group);
+ missing_coma = Some(p.trivia_start());
}
}
let kind = if can_group && items == 1 {
CollectionKind::Group
} else {
- kind.unwrap_or(CollectionKind::Positional)
+ collection_kind.unwrap_or(CollectionKind::Positional)
};
(kind, items)
diff --git a/src/syntax/resolve.rs b/src/syntax/resolve.rs
index 2ad35cec..bbed3c5c 100644
--- a/src/syntax/resolve.rs
+++ b/src/syntax/resolve.rs
@@ -30,7 +30,6 @@ pub fn resolve_string(string: &str) -> EcoString {
None => out.push_str(s.from(start)),
}
}
-
_ => out.push_str(s.from(start)),
}
}
@@ -66,10 +65,7 @@ pub fn resolve_raw(column: usize, backticks: usize, text: &str) -> RawKind {
/// Parse the lang tag and return it alongside the remaining inner raw text.
fn split_at_lang_tag(raw: &str) -> (&str, &str) {
let mut s = Scanner::new(raw);
- (
- s.eat_until(|c: char| c == '`' || c.is_whitespace() || is_newline(c)),
- s.after(),
- )
+ (s.eat_until(|c: char| c == '`' || c.is_whitespace() || is_newline(c)), s.after())
}
/// Trim raw text and splits it into lines.
@@ -94,7 +90,7 @@ fn trim_and_split_raw(column: usize, mut raw: &str) -> (String, bool) {
.take_while(|c| c.is_whitespace())
.map(char::len_utf8)
.sum();
- *line = &line[offset ..];
+ *line = &line[offset..];
}
let had_newline = lines.len() > 1;
@@ -127,13 +123,13 @@ fn split_lines(text: &str) -> Vec<&str> {
s.eat_if('\n');
}
- lines.push(&text[start .. end]);
+ lines.push(&text[start..end]);
start = s.cursor();
}
end = s.cursor();
}
- lines.push(&text[start ..]);
+ lines.push(&text[start..]);
lines
}
diff --git a/src/syntax/source.rs b/src/syntax/source.rs
index 1b87b1c9..48b0ff0e 100644
--- a/src/syntax/source.rs
+++ b/src/syntax/source.rs
@@ -123,13 +123,13 @@ impl Source {
self.lines.truncate(line + 1);
// Handle adjoining of \r and \n.
- if self.text[.. start_byte].ends_with('\r') && with.starts_with('\n') {
+ if self.text[..start_byte].ends_with('\r') && with.starts_with('\n') {
self.lines.pop();
}
// Recalculate the line starts after the edit.
self.lines
- .extend(lines(start_byte, start_utf16, &self.text[start_byte ..]));
+ .extend(lines(start_byte, start_utf16, &self.text[start_byte..]));
// Incrementally reparse the replaced range.
let mut root = std::mem::take(&mut self.root).into_inner();
@@ -146,7 +146,7 @@ impl Source {
/// Get the length of the file in UTF-16 code units.
pub fn len_utf16(&self) -> usize {
let last = self.lines.last().unwrap();
- last.utf16_idx + self.text[last.byte_idx ..].len_utf16()
+ last.utf16_idx + self.text[last.byte_idx..].len_utf16()
}
/// Get the length of the file in lines.
@@ -167,7 +167,7 @@ impl Source {
pub fn byte_to_utf16(&self, byte_idx: usize) -> Option<usize> {
let line_idx = self.byte_to_line(byte_idx)?;
let line = self.lines.get(line_idx)?;
- let head = self.text.get(line.byte_idx .. byte_idx)?;
+ let head = self.text.get(line.byte_idx..byte_idx)?;
Some(line.utf16_idx + head.len_utf16())
}
@@ -188,7 +188,7 @@ impl Source {
pub fn byte_to_column(&self, byte_idx: usize) -> Option<usize> {
let line = self.byte_to_line(byte_idx)?;
let start = self.line_to_byte(line)?;
- let head = self.get(start .. byte_idx)?;
+ let head = self.get(start..byte_idx)?;
Some(head.chars().count())
}
@@ -202,7 +202,7 @@ impl Source {
)?;
let mut k = line.utf16_idx;
- for (i, c) in self.text[line.byte_idx ..].char_indices() {
+ for (i, c) in self.text[line.byte_idx..].char_indices() {
if k >= utf16_idx {
return Some(line.byte_idx + i);
}
@@ -212,7 +212,6 @@ impl Source {
(k == utf16_idx).then(|| self.text.len())
}
-
/// Return the byte position at which the given line starts.
pub fn line_to_byte(&self, line_idx: usize) -> Option<usize> {
self.lines.get(line_idx).map(|line| line.byte_idx)
@@ -222,7 +221,7 @@ impl Source {
pub fn line_to_range(&self, line_idx: usize) -> Option<Range<usize>> {
let start = self.line_to_byte(line_idx)?;
let end = self.line_to_byte(line_idx + 1).unwrap_or(self.text.len());
- Some(start .. end)
+ Some(start..end)
}
/// Return the byte index of the given (line, column) pair.
@@ -237,7 +236,7 @@ impl Source {
let range = self.line_to_range(line_idx)?;
let line = self.get(range.clone())?;
let mut chars = line.chars();
- for _ in 0 .. column_idx {
+ for _ in 0..column_idx {
chars.next();
}
Some(range.start + (line.len() - chars.as_str().len()))
@@ -312,10 +311,7 @@ fn lines(
utf16_idx += 1;
}
- Some(Line {
- byte_idx: byte_offset + s.cursor(),
- utf16_idx,
- })
+ Some(Line { byte_idx: byte_offset + s.cursor(), utf16_idx })
})
}
@@ -328,12 +324,15 @@ mod tests {
#[test]
fn test_source_file_new() {
let source = Source::detached(TEST);
- assert_eq!(source.lines, [
- Line { byte_idx: 0, utf16_idx: 0 },
- Line { byte_idx: 7, utf16_idx: 6 },
- Line { byte_idx: 15, utf16_idx: 12 },
- Line { byte_idx: 18, utf16_idx: 15 },
- ]);
+ assert_eq!(
+ source.lines,
+ [
+ Line { byte_idx: 0, utf16_idx: 0 },
+ Line { byte_idx: 7, utf16_idx: 6 },
+ Line { byte_idx: 15, utf16_idx: 12 },
+ Line { byte_idx: 18, utf16_idx: 15 },
+ ]
+ );
}
#[test]
@@ -411,20 +410,20 @@ mod tests {
}
// Test inserting at the begining.
- test("abc\n", 0 .. 0, "hi\n", "hi\nabc\n");
- test("\nabc", 0 .. 0, "hi\r", "hi\r\nabc");
+ test("abc\n", 0..0, "hi\n", "hi\nabc\n");
+ test("\nabc", 0..0, "hi\r", "hi\r\nabc");
// Test editing in the middle.
- test(TEST, 4 .. 16, "❌", "ä\tc❌i\rjkl");
+ test(TEST, 4..16, "❌", "ä\tc❌i\rjkl");
// Test appending.
- test("abc\ndef", 7 .. 7, "hi", "abc\ndefhi");
- test("abc\ndef\n", 8 .. 8, "hi", "abc\ndef\nhi");
+ test("abc\ndef", 7..7, "hi", "abc\ndefhi");
+ test("abc\ndef\n", 8..8, "hi", "abc\ndef\nhi");
// Test appending with adjoining \r and \n.
- test("abc\ndef\r", 8 .. 8, "\nghi", "abc\ndef\r\nghi");
+ test("abc\ndef\r", 8..8, "\nghi", "abc\ndef\r\nghi");
// Test removing everything.
- test(TEST, 0 .. 21, "", "");
+ test(TEST, 0..21, "", "");
}
}
diff --git a/src/syntax/span.rs b/src/syntax/span.rs
index e3ff67b8..08bce4d5 100644
--- a/src/syntax/span.rs
+++ b/src/syntax/span.rs
@@ -70,7 +70,7 @@ impl Span {
const DETACHED: u64 = 1;
/// The full range of numbers available to spans.
- pub const FULL: Range<u64> = 2 .. (1 << Self::BITS);
+ pub const FULL: Range<u64> = 2..(1 << Self::BITS);
/// Create a new span from a source id and a unique number.
///
diff --git a/src/syntax/tokens.rs b/src/syntax/tokens.rs
index c787fa69..f18bb780 100644
--- a/src/syntax/tokens.rs
+++ b/src/syntax/tokens.rs
@@ -373,7 +373,7 @@ impl<'s> Tokens<'s> {
NodeKind::Raw(Arc::new(resolve_raw(
column,
backticks,
- self.s.get(start .. end),
+ self.s.get(start..end),
)))
} else {
self.terminated = false;
@@ -548,7 +548,7 @@ impl<'s> Tokens<'s> {
self.s.eat_while(char::is_ascii_alphanumeric);
}
- let number = self.s.get(start .. suffix_start);
+ let number = self.s.get(start..suffix_start);
let suffix = self.s.from(suffix_start);
// Find out whether it is a simple number.
@@ -558,9 +558,8 @@ impl<'s> Tokens<'s> {
}
}
- let v = match number.parse::<f64>() {
- Ok(v) => v,
- Err(_) => return NodeKind::Error(ErrorPos::Full, "invalid number".into()),
+ let Ok(v) = number.parse::<f64>() else {
+ return NodeKind::Error(ErrorPos::Full, "invalid number".into());
};
match suffix {
@@ -636,7 +635,7 @@ fn keyword(ident: &str) -> Option<NodeKind> {
#[inline]
fn column(string: &str, index: usize, offset: usize) -> usize {
let mut apply_offset = false;
- let res = string[.. index]
+ let res = string[..index]
.char_indices()
.rev()
.take_while(|&(_, c)| !is_newline(c))
@@ -653,7 +652,11 @@ fn column(string: &str, index: usize, offset: usize) -> usize {
apply_offset = true;
}
- if apply_offset { res + offset } else { res }
+ if apply_offset {
+ res + offset
+ } else {
+ res
+ }
}
/// Whether this character denotes a newline.
@@ -767,8 +770,8 @@ mod tests {
// - mode in which the suffix is applicable
// - the suffix string
// - the resulting suffix NodeKind
- fn suffixes()
- -> impl Iterator<Item = (char, Option<TokenMode>, &'static str, NodeKind)> {
+ fn suffixes(
+ ) -> impl Iterator<Item = (char, Option<TokenMode>, &'static str, NodeKind)> {
[
// Whitespace suffixes.
(' ', None, " ", Space(0)),