Token: Add range operators, rename for consistency
This commit is contained in:
@@ -5,64 +5,66 @@ use std::fmt::Display;
|
||||
impl Display for Type {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Type::Invalid => Display::fmt("invalid", f),
|
||||
Type::Comment => Display::fmt("comment", f),
|
||||
Type::Identifier => Display::fmt("identifier", f),
|
||||
Type::Keyword(k) => Display::fmt(k, f),
|
||||
Type::Integer => Display::fmt("integer literal", f),
|
||||
Type::Float => Display::fmt("float literal", f),
|
||||
Type::String => Display::fmt("string literal", f),
|
||||
Type::Character => Display::fmt("char literal", f),
|
||||
Type::LCurly => Display::fmt("left curly", f),
|
||||
Type::RCurly => Display::fmt("right curly", f),
|
||||
Type::LBrack => Display::fmt("left brack", f),
|
||||
Type::RBrack => Display::fmt("right brack", f),
|
||||
Type::LParen => Display::fmt("left paren", f),
|
||||
Type::RParen => Display::fmt("right paren", f),
|
||||
Type::Lsh => Display::fmt("shift left", f),
|
||||
Type::Rsh => Display::fmt("shift right", f),
|
||||
Type::AmpAmp => Display::fmt("and-and", f),
|
||||
Type::BarBar => Display::fmt("or-or", f),
|
||||
Type::NotNot => Display::fmt("not-not", f),
|
||||
Type::CatEar => Display::fmt("cat-ears", f),
|
||||
Type::EqEq => Display::fmt("equal to", f),
|
||||
Type::GtEq => Display::fmt("greater than or equal to", f),
|
||||
Type::LtEq => Display::fmt("less than or equal to", f),
|
||||
Type::NotEq => Display::fmt("not equal to", f),
|
||||
Type::StarEq => Display::fmt("star-assign", f),
|
||||
Type::DivEq => Display::fmt("div-assign", f),
|
||||
Type::RemEq => Display::fmt("rem-assign", f),
|
||||
Type::AddEq => Display::fmt("add-assign", f),
|
||||
Type::SubEq => Display::fmt("sub-assign", f),
|
||||
Type::AndEq => Display::fmt("and-assign", f),
|
||||
Type::OrEq => Display::fmt("or-assign", f),
|
||||
Type::XorEq => Display::fmt("xor-assign", f),
|
||||
Type::LshEq => Display::fmt("shift left-assign", f),
|
||||
Type::RshEq => Display::fmt("shift right-assign", f),
|
||||
Type::Arrow => Display::fmt("arrow", f),
|
||||
Type::FatArrow => Display::fmt("fat arrow", f),
|
||||
Type::Semi => Display::fmt("ignore", f),
|
||||
Type::Dot => Display::fmt("dot", f),
|
||||
Type::Star => Display::fmt("star", f),
|
||||
Type::Div => Display::fmt("div", f),
|
||||
Type::Plus => Display::fmt("add", f),
|
||||
Type::Minus => Display::fmt("sub", f),
|
||||
Type::Rem => Display::fmt("rem", f),
|
||||
Type::Bang => Display::fmt("bang", f),
|
||||
Type::Eq => Display::fmt("assign", f),
|
||||
Type::Lt => Display::fmt("less than", f),
|
||||
Type::Gt => Display::fmt("greater than", f),
|
||||
Type::Amp => Display::fmt("and", f),
|
||||
Type::Bar => Display::fmt("or", f),
|
||||
Type::Xor => Display::fmt("xor", f),
|
||||
Type::Hash => Display::fmt("hash", f),
|
||||
Type::At => Display::fmt("at", f),
|
||||
Type::Colon => Display::fmt("colon", f),
|
||||
Type::Backslash => Display::fmt("backslash", f),
|
||||
Type::Question => Display::fmt("huh?", f),
|
||||
Type::Comma => Display::fmt("comma", f),
|
||||
Type::Tilde => Display::fmt("tilde", f),
|
||||
Type::Grave => Display::fmt("grave", f),
|
||||
Type::Invalid => "invalid".fmt(f),
|
||||
Type::Comment => "comment".fmt(f),
|
||||
Type::Identifier => "identifier".fmt(f),
|
||||
Type::Keyword(k) => k.fmt(f),
|
||||
Type::Integer => "integer literal".fmt(f),
|
||||
Type::Float => "float literal".fmt(f),
|
||||
Type::String => "string literal".fmt(f),
|
||||
Type::Character => "char literal".fmt(f),
|
||||
Type::LCurly => "left curly".fmt(f),
|
||||
Type::RCurly => "right curly".fmt(f),
|
||||
Type::LBrack => "left brack".fmt(f),
|
||||
Type::RBrack => "right brack".fmt(f),
|
||||
Type::LParen => "left paren".fmt(f),
|
||||
Type::RParen => "right paren".fmt(f),
|
||||
Type::Amp => "and".fmt(f),
|
||||
Type::AmpAmp => "and-and".fmt(f),
|
||||
Type::AmpEq => "and-assign".fmt(f),
|
||||
Type::Arrow => "arrow".fmt(f),
|
||||
Type::At => "at".fmt(f),
|
||||
Type::Backslash => "backslash".fmt(f),
|
||||
Type::Bang => "bang".fmt(f),
|
||||
Type::BangBang => "not-not".fmt(f),
|
||||
Type::BangEq => "not equal to".fmt(f),
|
||||
Type::Bar => "or".fmt(f),
|
||||
Type::BarBar => "or-or".fmt(f),
|
||||
Type::BarEq => "or-assign".fmt(f),
|
||||
Type::Colon => "colon".fmt(f),
|
||||
Type::Comma => "comma".fmt(f),
|
||||
Type::Dot => "dot".fmt(f),
|
||||
Type::DotDot => "exclusive range".fmt(f),
|
||||
Type::DotDotEq => "inclusive range".fmt(f),
|
||||
Type::Eq => "assign".fmt(f),
|
||||
Type::EqEq => "equal to".fmt(f),
|
||||
Type::FatArrow => "fat arrow".fmt(f),
|
||||
Type::Grave => "grave".fmt(f),
|
||||
Type::Gt => "greater than".fmt(f),
|
||||
Type::GtEq => "greater than or equal to".fmt(f),
|
||||
Type::GtGt => "shift right".fmt(f),
|
||||
Type::GtGtEq => "shift right-assign".fmt(f),
|
||||
Type::Hash => "hash".fmt(f),
|
||||
Type::Lt => "less than".fmt(f),
|
||||
Type::LtEq => "less than or equal to".fmt(f),
|
||||
Type::LtLt => "shift left".fmt(f),
|
||||
Type::LtLtEq => "shift left-assign".fmt(f),
|
||||
Type::Minus => "sub".fmt(f),
|
||||
Type::MinusEq => "sub-assign".fmt(f),
|
||||
Type::Plus => "add".fmt(f),
|
||||
Type::PlusEq => "add-assign".fmt(f),
|
||||
Type::Question => "huh?".fmt(f),
|
||||
Type::Rem => "rem".fmt(f),
|
||||
Type::RemEq => "rem-assign".fmt(f),
|
||||
Type::Semi => "ignore".fmt(f),
|
||||
Type::Slash => "div".fmt(f),
|
||||
Type::SlashEq => "div-assign".fmt(f),
|
||||
Type::Star => "star".fmt(f),
|
||||
Type::StarEq => "star-assign".fmt(f),
|
||||
Type::Tilde => "tilde".fmt(f),
|
||||
Type::Xor => "xor".fmt(f),
|
||||
Type::XorEq => "xor-assign".fmt(f),
|
||||
Type::XorXor => "cat-ears".fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,23 +72,23 @@ impl Display for Type {
|
||||
impl Display for Keyword {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Break => Display::fmt("break", f),
|
||||
Self::Continue => Display::fmt("continue", f),
|
||||
Self::Else => Display::fmt("else", f),
|
||||
Self::False => Display::fmt("false", f),
|
||||
Self::For => Display::fmt("for", f),
|
||||
Self::Fn => Display::fmt("fn", f),
|
||||
Self::If => Display::fmt("if", f),
|
||||
Self::In => Display::fmt("in", f),
|
||||
Self::Let => Display::fmt("let", f),
|
||||
Self::Return => Display::fmt("return", f),
|
||||
Self::True => Display::fmt("true", f),
|
||||
Self::While => Display::fmt("while", f),
|
||||
Self::Break => "break".fmt(f),
|
||||
Self::Continue => "continue".fmt(f),
|
||||
Self::Else => "else".fmt(f),
|
||||
Self::False => "false".fmt(f),
|
||||
Self::For => "for".fmt(f),
|
||||
Self::Fn => "fn".fmt(f),
|
||||
Self::If => "if".fmt(f),
|
||||
Self::In => "in".fmt(f),
|
||||
Self::Let => "let".fmt(f),
|
||||
Self::Return => "return".fmt(f),
|
||||
Self::True => "true".fmt(f),
|
||||
Self::While => "while".fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl std::str::FromStr for Keyword {
|
||||
type Err = ();
|
||||
type Err = (); // If an identifier isn't a keyword, that's okay.
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(match s {
|
||||
"break" => Self::Break,
|
||||
|
||||
Reference in New Issue
Block a user