summaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/mod.rs5
-rw-r--r--src/parse/parser.rs11
-rw-r--r--src/parse/tokens.rs27
3 files changed, 23 insertions, 20 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
index 832c297e..4f42442f 100644
--- a/src/parse/mod.rs
+++ b/src/parse/mod.rs
@@ -11,8 +11,9 @@ pub use tokens::*;
use std::collections::HashSet;
+use crate::diag::ErrorPos;
use crate::syntax::ast::{Assoc, BinOp, UnOp};
-use crate::syntax::{NodeKind, SpanPos, SyntaxNode};
+use crate::syntax::{NodeKind, SyntaxNode};
use crate::util::EcoString;
/// Parse a source file.
@@ -811,7 +812,7 @@ fn item(p: &mut Parser, keyed: bool) -> ParseResult<NodeKind> {
msg.push_str(", found ");
msg.push_str(kind.name());
}
- let error = NodeKind::Error(SpanPos::Full, msg);
+ let error = NodeKind::Error(ErrorPos::Full, msg);
marker.end(p, error);
p.eat();
marker.perform(p, NodeKind::Named, expr).ok();
diff --git a/src/parse/parser.rs b/src/parse/parser.rs
index 4b73c2b9..fe04f29e 100644
--- a/src/parse/parser.rs
+++ b/src/parse/parser.rs
@@ -3,7 +3,8 @@ use std::mem;
use std::ops::Range;
use super::{TokenMode, Tokens};
-use crate::syntax::{InnerNode, NodeData, NodeKind, SpanPos, SyntaxNode};
+use crate::diag::ErrorPos;
+use crate::syntax::{InnerNode, NodeData, NodeKind, SyntaxNode};
use crate::util::EcoString;
/// A convenient token-based parser.
@@ -398,7 +399,7 @@ impl Parser<'_> {
pub fn unexpected(&mut self) {
if let Some(found) = self.peek() {
let msg = format_eco!("unexpected {}", found.name());
- let error = NodeKind::Error(SpanPos::Full, msg);
+ let error = NodeKind::Error(ErrorPos::Full, msg);
self.perform(error, Self::eat);
}
}
@@ -412,7 +413,7 @@ impl Parser<'_> {
/// Insert an error message that `what` was expected at the marker position.
pub fn expected_at(&mut self, marker: Marker, what: &str) {
let msg = format_eco!("expected {}", what);
- let error = NodeKind::Error(SpanPos::Full, msg);
+ let error = NodeKind::Error(ErrorPos::Full, msg);
self.children.insert(marker.0, NodeData::new(error, 0).into());
}
@@ -422,7 +423,7 @@ impl Parser<'_> {
match self.peek() {
Some(found) => {
let msg = format_eco!("expected {}, found {}", thing, found.name());
- let error = NodeKind::Error(SpanPos::Full, msg);
+ let error = NodeKind::Error(ErrorPos::Full, msg);
self.perform(error, Self::eat);
}
None => self.expected(thing),
@@ -494,7 +495,7 @@ impl Marker {
msg.push_str(", found ");
msg.push_str(child.kind().name());
}
- let error = NodeKind::Error(SpanPos::Full, msg);
+ let error = NodeKind::Error(ErrorPos::Full, msg);
let inner = mem::take(child);
*child = InnerNode::with_child(error, inner).into();
}
diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs
index d3c497f3..7cba1823 100644
--- a/src/parse/tokens.rs
+++ b/src/parse/tokens.rs
@@ -4,9 +4,10 @@ use unicode_xid::UnicodeXID;
use unscanny::Scanner;
use super::resolve::{resolve_hex, resolve_raw, resolve_string};
+use crate::diag::ErrorPos;
use crate::geom::{AngleUnit, LengthUnit};
use crate::syntax::ast::{RawNode, Unit};
-use crate::syntax::{NodeKind, SpanPos};
+use crate::syntax::NodeKind;
use crate::util::EcoString;
/// An iterator over the tokens of a string of source code.
@@ -109,7 +110,7 @@ impl<'s> Iterator for Tokens<'s> {
'/' if self.s.eat_if('/') => self.line_comment(),
'/' if self.s.eat_if('*') => self.block_comment(),
'*' if self.s.eat_if('/') => {
- NodeKind::Error(SpanPos::Full, "unexpected end of block comment".into())
+ NodeKind::Error(ErrorPos::Full, "unexpected end of block comment".into())
}
c if c.is_whitespace() => self.whitespace(c),
@@ -279,13 +280,13 @@ impl<'s> Tokens<'s> {
NodeKind::Escape(c)
} else {
NodeKind::Error(
- SpanPos::Full,
+ ErrorPos::Full,
"invalid unicode escape sequence".into(),
)
}
} else {
self.terminated = false;
- NodeKind::Error(SpanPos::End, "expected closing brace".into())
+ NodeKind::Error(ErrorPos::End, "expected closing brace".into())
}
}
@@ -388,7 +389,7 @@ impl<'s> Tokens<'s> {
let remaining = backticks - found;
let noun = if remaining == 1 { "backtick" } else { "backticks" };
NodeKind::Error(
- SpanPos::End,
+ ErrorPos::End,
if found == 0 {
format_eco!("expected {} {}", remaining, noun)
} else {
@@ -416,11 +417,11 @@ impl<'s> Tokens<'s> {
if !label.is_empty() {
NodeKind::Label(label.into())
} else {
- NodeKind::Error(SpanPos::Full, "label cannot be empty".into())
+ NodeKind::Error(ErrorPos::Full, "label cannot be empty".into())
}
} else {
self.terminated = false;
- NodeKind::Error(SpanPos::End, "expected closing angle bracket".into())
+ NodeKind::Error(ErrorPos::End, "expected closing angle bracket".into())
}
}
@@ -519,7 +520,7 @@ impl<'s> Tokens<'s> {
'"' => self.string(),
// Invalid token.
- _ => NodeKind::Error(SpanPos::Full, "not valid here".into()),
+ _ => NodeKind::Error(ErrorPos::Full, "not valid here".into()),
}
}
@@ -578,10 +579,10 @@ impl<'s> Tokens<'s> {
"em" => NodeKind::Numeric(f, Unit::Em),
"fr" => NodeKind::Numeric(f, Unit::Fr),
"%" => NodeKind::Numeric(f, Unit::Percent),
- _ => NodeKind::Error(SpanPos::Full, "invalid number suffix".into()),
+ _ => NodeKind::Error(ErrorPos::Full, "invalid number suffix".into()),
}
} else {
- NodeKind::Error(SpanPos::Full, "invalid number".into())
+ NodeKind::Error(ErrorPos::Full, "invalid number".into())
}
}
@@ -601,7 +602,7 @@ impl<'s> Tokens<'s> {
NodeKind::Str(string)
} else {
self.terminated = false;
- NodeKind::Error(SpanPos::End, "expected quote".into())
+ NodeKind::Error(ErrorPos::End, "expected quote".into())
}
}
}
@@ -713,9 +714,9 @@ mod tests {
use super::*;
use crate::parse::tests::check;
+ use ErrorPos::*;
use NodeKind::*;
use Option::None;
- use SpanPos::*;
use TokenMode::{Code, Markup};
fn Space(newlines: usize) -> NodeKind {
@@ -742,7 +743,7 @@ mod tests {
NodeKind::Ident(ident.into())
}
- fn Error(pos: SpanPos, message: &str) -> NodeKind {
+ fn Error(pos: ErrorPos, message: &str) -> NodeKind {
NodeKind::Error(pos, message.into())
}