Update to match cl v0.0.5

This commit is contained in:
John 2024-04-13 03:40:20 -05:00
parent 700c990a11
commit c048cdfbf4
3 changed files with 42 additions and 43 deletions

14
Cargo.lock generated
View File

@ -59,14 +59,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "cl-ast" name = "cl-ast"
version = "0.0.4" version = "0.0.5"
dependencies = [ dependencies = [
"cl-structures", "cl-structures",
] ]
[[package]] [[package]]
name = "cl-interpret" name = "cl-interpret"
version = "0.0.4" version = "0.0.5"
dependencies = [ dependencies = [
"cl-ast", "cl-ast",
"cl-structures", "cl-structures",
@ -74,7 +74,7 @@ dependencies = [
[[package]] [[package]]
name = "cl-lexer" name = "cl-lexer"
version = "0.0.4" version = "0.0.5"
dependencies = [ dependencies = [
"cl-structures", "cl-structures",
"cl-token", "cl-token",
@ -83,7 +83,7 @@ dependencies = [
[[package]] [[package]]
name = "cl-parser" name = "cl-parser"
version = "0.0.4" version = "0.0.5"
dependencies = [ dependencies = [
"cl-ast", "cl-ast",
"cl-lexer", "cl-lexer",
@ -93,7 +93,7 @@ dependencies = [
[[package]] [[package]]
name = "cl-repl" name = "cl-repl"
version = "0.0.4" version = "0.0.5"
dependencies = [ dependencies = [
"argh", "argh",
"cl-ast", "cl-ast",
@ -106,11 +106,11 @@ dependencies = [
[[package]] [[package]]
name = "cl-structures" name = "cl-structures"
version = "0.0.4" version = "0.0.5"
[[package]] [[package]]
name = "cl-token" name = "cl-token"
version = "0.0.4" version = "0.0.5"
[[package]] [[package]]
name = "crossterm" name = "crossterm"

View File

@ -194,7 +194,7 @@ pub mod parser {
pub mod token { pub mod token {
//! Custom token type, plus a [Tokenizer] iterator adapter for cl-lexer's token type //! Custom token type, plus a [Tokenizer] iterator adapter for cl-lexer's token type
use cl_token::{token_type::Op as Tkop, *}; use cl_token::{token_type::Punct as Tkop, *};
pub struct Tokenizer<'t> { pub struct Tokenizer<'t> {
lexer: cl_lexer::lexer_iter::LexerIter<'t>, lexer: cl_lexer::lexer_iter::LexerIter<'t>,
@ -212,12 +212,11 @@ pub mod token {
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
let token = self.lexer.next()?.ok()?; let token = self.lexer.next()?.ok()?;
let (ty, data) = (token.ty(), token.into_data()); let (ty, data) = (token.ty(), token.into_data());
match (ty, data) {
match data { (TokenKind::Literal, TokenData::Integer(v)) => return Some(Token::Int(v as _)),
TokenData::Integer(v) => return Some(Token::Int(v as _)), (TokenKind::Literal, TokenData::Character(v)) => return Some(Token::Char(v)),
TokenData::Character(v) => return Some(Token::Char(v)), (TokenKind::Literal, TokenData::String(v)) => return Some(Token::Str(v)),
TokenData::Identifier(v) => return Some(Token::Ident(v.into_string())), (TokenKind::Identifier, TokenData::String(v)) => return Some(Token::Ident(v)),
TokenData::String(v) => return Some(Token::Str(v.to_owned())),
_ => {} _ => {}
} }
@ -291,44 +290,44 @@ pub mod token {
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Op { pub enum Op {
// Delimiter // Delimiter
#["("] Lpa = TokenKind::Op(Tkop::LParen), #["("] Lpa = TokenKind::Punct(Tkop::LParen),
#[")"] Rpa = TokenKind::Op(Tkop::RParen), #[")"] Rpa = TokenKind::Punct(Tkop::RParen),
#["["] Lbk = TokenKind::Op(Tkop::LBrack), #["["] Lbk = TokenKind::Punct(Tkop::LBrack),
#["]"] Rbk = TokenKind::Op(Tkop::RBrack), #["]"] Rbk = TokenKind::Punct(Tkop::RBrack),
// Member // Member
#["."] Dot = TokenKind::Op(Tkop::Dot), #["."] Dot = TokenKind::Punct(Tkop::Dot),
// Factor // Factor
#["*"] Mul = TokenKind::Op(Tkop::Star), #["*"] Mul = TokenKind::Punct(Tkop::Star),
#["/"] Div = TokenKind::Op(Tkop::Slash), #["/"] Div = TokenKind::Punct(Tkop::Slash),
#["%"] Rem = TokenKind::Op(Tkop::Rem), #["%"] Rem = TokenKind::Punct(Tkop::Rem),
// Term // Term
#["+"] Add = TokenKind::Op(Tkop::Plus), #["+"] Add = TokenKind::Punct(Tkop::Plus),
#["-"] Sub = TokenKind::Op(Tkop::Minus), #["-"] Sub = TokenKind::Punct(Tkop::Minus),
// Shift // Shift
#["<<"] Shl = TokenKind::Op(Tkop::LtLt), #["<<"] Shl = TokenKind::Punct(Tkop::LtLt),
#[">>"] Shr = TokenKind::Op(Tkop::GtGt), #[">>"] Shr = TokenKind::Punct(Tkop::GtGt),
// Bitwise // Bitwise
#["&"] Ban = TokenKind::Op(Tkop::Amp), #["&"] Ban = TokenKind::Punct(Tkop::Amp),
#["|"] Bor = TokenKind::Op(Tkop::Bar), #["|"] Bor = TokenKind::Punct(Tkop::Bar),
#["^"] Bxr = TokenKind::Op(Tkop::Xor), #["^"] Bxr = TokenKind::Punct(Tkop::Xor),
// Logic // Logic
#["&&"] Lan = TokenKind::Op(Tkop::AmpAmp), #["&&"] Lan = TokenKind::Punct(Tkop::AmpAmp),
#["||"] Lor = TokenKind::Op(Tkop::BarBar), #["||"] Lor = TokenKind::Punct(Tkop::BarBar),
#["^^"] Lxr = TokenKind::Op(Tkop::XorXor), #["^^"] Lxr = TokenKind::Punct(Tkop::XorXor),
// Range // Range
#["..="] Inc = TokenKind::Op(Tkop::DotDotEq), #["..="] Inc = TokenKind::Punct(Tkop::DotDotEq),
#[".."] Exc = TokenKind::Op(Tkop::DotDot), #[".."] Exc = TokenKind::Punct(Tkop::DotDot),
// Compare // Compare
#["<"] Lt = TokenKind::Op(Tkop::Lt), #["<"] Lt = TokenKind::Punct(Tkop::Lt),
#["<="] Lte = TokenKind::Op(Tkop::LtEq), #["<="] Lte = TokenKind::Punct(Tkop::LtEq),
#["=="] Eq = TokenKind::Op(Tkop::EqEq), #["=="] Eq = TokenKind::Punct(Tkop::EqEq),
#["!="] Neq = TokenKind::Op(Tkop::BangEq), #["!="] Neq = TokenKind::Punct(Tkop::BangEq),
#[">="] Gte = TokenKind::Op(Tkop::GtEq), #[">="] Gte = TokenKind::Punct(Tkop::GtEq),
#[">"] Gt = TokenKind::Op(Tkop::Gt), #[">"] Gt = TokenKind::Punct(Tkop::Gt),
// Unary-only // Unary-only
#["!"] Not = TokenKind::Op(Tkop::Bang), #["!"] Not = TokenKind::Punct(Tkop::Bang),
// Postfix unary // Postfix unary
#["?"] Huh = TokenKind::Op(Tkop::Question), #["?"] Huh = TokenKind::Punct(Tkop::Question),
} }
} }

View File

@ -6,7 +6,7 @@ fn main() {
while let Ok(line) = rl.read() { while let Ok(line) = rl.read() {
if let Some(expr) = parser::expr(&line) { if let Some(expr) = parser::expr(&line) {
println!("\x1b[G\x1b[J{expr:?}"); println!("\x1b[G\x1b[J{expr}");
rl.accept(); rl.accept();
} }
} }