mirror of
https://github.com/nushell/nushell.git
synced 2025-01-01 12:00:10 +01:00
3379c23a49
Blocks, paths, and others Plus a bunch of other infra improvements
48 lines
1.0 KiB
Rust
48 lines
1.0 KiB
Rust
use crate::parser::parse::span::*;
|
|
use crate::parser::parse::unit::*;
|
|
use crate::Text;
|
|
use std::fmt;
|
|
|
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
|
pub enum RawToken {
|
|
Integer(i64),
|
|
Size(i64, Unit),
|
|
String(Span),
|
|
Variable(Span),
|
|
Bare,
|
|
}
|
|
|
|
impl RawToken {
|
|
pub fn type_name(&self) -> &'static str {
|
|
match self {
|
|
RawToken::Integer(_) => "Integer",
|
|
RawToken::Size(..) => "Size",
|
|
RawToken::String(_) => "String",
|
|
RawToken::Variable(_) => "Variable",
|
|
RawToken::Bare => "String",
|
|
}
|
|
}
|
|
}
|
|
|
|
pub type Token = Spanned<RawToken>;
|
|
|
|
impl Token {
|
|
pub fn debug(&self, source: &'a Text) -> DebugToken<'a> {
|
|
DebugToken {
|
|
node: *self,
|
|
source,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct DebugToken<'a> {
|
|
node: Token,
|
|
source: &'a Text,
|
|
}
|
|
|
|
impl fmt::Debug for DebugToken<'a> {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, "{}", self.node.span().slice(self.source))
|
|
}
|
|
}
|