Update to match changes in cl-token
This commit is contained in:
parent
edad0a2685
commit
4342483529
72
src/lib.rs
72
src/lib.rs
@ -214,10 +214,10 @@ pub mod token {
|
||||
let (ty, data) = (token.ty(), token.into_data());
|
||||
|
||||
match data {
|
||||
Data::Integer(v) => return Some(Token::Int(v as _)),
|
||||
Data::Character(v) => return Some(Token::Char(v)),
|
||||
Data::Identifier(v) => return Some(Token::Ident(v.into_string())),
|
||||
Data::String(v) => return Some(Token::Str(v.to_owned())),
|
||||
TokenData::Integer(v) => return Some(Token::Int(v as _)),
|
||||
TokenData::Character(v) => return Some(Token::Char(v)),
|
||||
TokenData::Identifier(v) => return Some(Token::Ident(v.into_string())),
|
||||
TokenData::String(v) => return Some(Token::Str(v.to_owned())),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@ -274,12 +274,12 @@ pub mod token {
|
||||
match self { $($Name::$name => $rep,)* }.fmt(f)
|
||||
}
|
||||
}
|
||||
impl TryFrom<cl_token::Type> for $Name {
|
||||
impl TryFrom<cl_token::TokenKind> for $Name {
|
||||
type Error = $crate::token::Er;
|
||||
fn try_from(value: cl_token::Type) -> Result<Self, Self::Error> {
|
||||
fn try_from(value: cl_token::TokenKind) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
cl_token::Type::Comment |
|
||||
cl_token::Type::Invalid => Err(Er::Invalid),
|
||||
cl_token::TokenKind::Comment |
|
||||
cl_token::TokenKind::Invalid => Err(Er::Invalid),
|
||||
$($try_from => Ok($Name::$name),)*
|
||||
_ => Err(Er::NotAnOp)
|
||||
}
|
||||
@ -291,44 +291,44 @@ pub mod token {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Op {
|
||||
// Delimiter
|
||||
#["("] Lpa = Type::LParen,
|
||||
#[")"] Rpa = Type::RParen,
|
||||
#["["] Lbk = Type::LBrack,
|
||||
#["]"] Rbk = Type::RBrack,
|
||||
#["("] Lpa = TokenKind::LParen,
|
||||
#[")"] Rpa = TokenKind::RParen,
|
||||
#["["] Lbk = TokenKind::LBrack,
|
||||
#["]"] Rbk = TokenKind::RBrack,
|
||||
// Member
|
||||
#["."] Dot = Type::Dot,
|
||||
#["."] Dot = TokenKind::Dot,
|
||||
// Factor
|
||||
#["*"] Mul = Type::Star,
|
||||
#["/"] Div = Type::Slash,
|
||||
#["%"] Rem = Type::Rem,
|
||||
#["*"] Mul = TokenKind::Star,
|
||||
#["/"] Div = TokenKind::Slash,
|
||||
#["%"] Rem = TokenKind::Rem,
|
||||
// Term
|
||||
#["+"] Add = Type::Plus,
|
||||
#["-"] Sub = Type::Minus,
|
||||
#["+"] Add = TokenKind::Plus,
|
||||
#["-"] Sub = TokenKind::Minus,
|
||||
// Shift
|
||||
#["<<"] Shl = Type::LtLt,
|
||||
#[">>"] Shr = Type::GtGt,
|
||||
#["<<"] Shl = TokenKind::LtLt,
|
||||
#[">>"] Shr = TokenKind::GtGt,
|
||||
// Bitwise
|
||||
#["&"] Ban = Type::Amp,
|
||||
#["|"] Bor = Type::Bar,
|
||||
#["^"] Bxr = Type::Xor,
|
||||
#["&"] Ban = TokenKind::Amp,
|
||||
#["|"] Bor = TokenKind::Bar,
|
||||
#["^"] Bxr = TokenKind::Xor,
|
||||
// Logic
|
||||
#["&&"] Lan = Type::AmpAmp,
|
||||
#["||"] Lor = Type::BarBar,
|
||||
#["^^"] Lxr = Type::XorXor,
|
||||
#["&&"] Lan = TokenKind::AmpAmp,
|
||||
#["||"] Lor = TokenKind::BarBar,
|
||||
#["^^"] Lxr = TokenKind::XorXor,
|
||||
// Range
|
||||
#["..="] Inc = Type::DotDotEq,
|
||||
#[".."] Exc = Type::DotDot,
|
||||
#["..="] Inc = TokenKind::DotDotEq,
|
||||
#[".."] Exc = TokenKind::DotDot,
|
||||
// Compare
|
||||
#["<"] Lt = Type::Lt,
|
||||
#["<="] Lte = Type::LtEq,
|
||||
#["=="] Eq = Type::EqEq,
|
||||
#["!="] Neq = Type::BangEq,
|
||||
#[">="] Gte = Type::GtEq,
|
||||
#[">"] Gt = Type::Gt,
|
||||
#["<"] Lt = TokenKind::Lt,
|
||||
#["<="] Lte = TokenKind::LtEq,
|
||||
#["=="] Eq = TokenKind::EqEq,
|
||||
#["!="] Neq = TokenKind::BangEq,
|
||||
#[">="] Gte = TokenKind::GtEq,
|
||||
#[">"] Gt = TokenKind::Gt,
|
||||
// Unary-only
|
||||
#["!"] Not = Type::Bang,
|
||||
#["!"] Not = TokenKind::Bang,
|
||||
// Postfix unary
|
||||
#["?"] Huh = Type::Question,
|
||||
#["?"] Huh = TokenKind::Question,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user