|
| 1 | +use std::fmt::{ |
| 2 | + self, |
| 3 | + Display, |
| 4 | +}; |
| 5 | + |
1 | 6 | use logos::Logos;
|
2 | 7 |
|
3 | 8 | use super::literal::*;
|
4 | 9 | use crate::misc::SmolStr;
|
5 | 10 |
|
6 |
| -#[derive(Debug, Logos, Clone)] |
| 11 | +#[derive(Debug, Logos, Clone, PartialEq)] |
7 | 12 | #[logos(skip r"[ \r\t\f]+")]
|
8 | 13 | #[logos(skip r"#[^\n]*\n")]
|
9 | 14 | pub enum Token {
|
@@ -234,3 +239,123 @@ pub enum Token {
|
234 | 239 | #[token("var")]
|
235 | 240 | Var,
|
236 | 241 | }
|
| 242 | + |
| 243 | +impl Display for Token { |
| 244 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 245 | + match self { |
| 246 | + Token::Name(name) => write!(f, "name{}", name), |
| 247 | + Token::Define => write!(f, "%define"), |
| 248 | + Token::Undef => write!(f, "%undef"), |
| 249 | + Token::Newline => write!(f, "\n"), |
| 250 | + Token::Backslash => write!(f, "\\"), |
| 251 | + Token::Arg(name) => write!(f, "${}", name), |
| 252 | + Token::Bin(value) => write!(f, "bin{}", value), |
| 253 | + Token::Oct(value) => write!(f, "oct{}", value), |
| 254 | + Token::Int(value) => write!(f, "int{}", value), |
| 255 | + Token::Hex(value) => write!(f, "hex{}", value), |
| 256 | + Token::Float(value) => write!(f, "float{}", value), |
| 257 | + Token::Str(value) => write!(f, "str{}", value), |
| 258 | + Token::Cmd(value) => write!(f, "cmd{}", value), |
| 259 | + Token::Costumes => write!(f, "costumes"), |
| 260 | + Token::Sounds => write!(f, "sounds"), |
| 261 | + Token::Local => write!(f, "local"), |
| 262 | + Token::Proc => write!(f, "proc"), |
| 263 | + Token::Func => write!(f, "func"), |
| 264 | + Token::Return => write!(f, "return"), |
| 265 | + Token::NoWarp => write!(f, "nowarp"), |
| 266 | + Token::On => write!(f, "on"), |
| 267 | + Token::OnFlag => write!(f, "onflag"), |
| 268 | + Token::OnKey => write!(f, "onkey"), |
| 269 | + Token::OnClick => write!(f, "onclick"), |
| 270 | + Token::OnBackdrop => write!(f, "onbackdrop"), |
| 271 | + Token::OnLoudness => write!(f, "onloudness"), |
| 272 | + Token::OnTimer => write!(f, "ontimer"), |
| 273 | + Token::OnClone => write!(f, "onclone"), |
| 274 | + Token::If => write!(f, "if"), |
| 275 | + Token::Else => write!(f, "else"), |
| 276 | + Token::Elif => write!(f, "elif"), |
| 277 | + Token::Until => write!(f, "until"), |
| 278 | + Token::Forever => write!(f, "forever"), |
| 279 | + Token::Repeat => write!(f, "repeat"), |
| 280 | + Token::Comma => write!(f, ","), |
| 281 | + Token::LParen => write!(f, "("), |
| 282 | + Token::RParen => write!(f, ")"), |
| 283 | + Token::LBrace => write!(f, "{{"), |
| 284 | + Token::RBrace => write!(f, "}}"), |
| 285 | + Token::Assign => write!(f, "="), |
| 286 | + Token::Eq => write!(f, "=="), |
| 287 | + Token::Increment => write!(f, "++"), |
| 288 | + Token::Decrement => write!(f, "--"), |
| 289 | + Token::AssignAdd => write!(f, "+="), |
| 290 | + Token::AssignSubtract => write!(f, "-="), |
| 291 | + Token::AssignMultiply => write!(f, "*="), |
| 292 | + Token::AssignDivide => write!(f, "/="), |
| 293 | + Token::AssignFloorDiv => write!(f, "//="), |
| 294 | + Token::AssignModulo => write!(f, "%="), |
| 295 | + Token::AssignJoin => write!(f, "&="), |
| 296 | + Token::LBracket => write!(f, "["), |
| 297 | + Token::RBracket => write!(f, "]"), |
| 298 | + Token::Dot => write!(f, "."), |
| 299 | + Token::Ne => write!(f, "!="), |
| 300 | + Token::Lt => write!(f, "<"), |
| 301 | + Token::Gt => write!(f, ">"), |
| 302 | + Token::Le => write!(f, "<="), |
| 303 | + Token::Ge => write!(f, ">="), |
| 304 | + Token::Not => write!(f, "not"), |
| 305 | + Token::And => write!(f, "and"), |
| 306 | + Token::Or => write!(f, "or"), |
| 307 | + Token::In => write!(f, "in"), |
| 308 | + Token::Amp => write!(f, "&"), |
| 309 | + Token::Plus => write!(f, "+"), |
| 310 | + Token::Minus => write!(f, "-"), |
| 311 | + Token::Star => write!(f, "*"), |
| 312 | + Token::Slash => write!(f, "/"), |
| 313 | + Token::FloorDiv => write!(f, "//"), |
| 314 | + Token::Percent => write!(f, "%"), |
| 315 | + Token::Semicolon => write!(f, ";"), |
| 316 | + Token::Colon => write!(f, ":"), |
| 317 | + Token::Length => write!(f, "length"), |
| 318 | + Token::Round => write!(f, "round"), |
| 319 | + Token::Abs => write!(f, "abs"), |
| 320 | + Token::Floor => write!(f, "floor"), |
| 321 | + Token::Ceil => write!(f, "ceil"), |
| 322 | + Token::Sqrt => write!(f, "sqrt"), |
| 323 | + Token::Sin => write!(f, "sin"), |
| 324 | + Token::Cos => write!(f, "cos"), |
| 325 | + Token::Tan => write!(f, "tan"), |
| 326 | + Token::Asin => write!(f, "asin"), |
| 327 | + Token::Acos => write!(f, "acos"), |
| 328 | + Token::Atan => write!(f, "atan"), |
| 329 | + Token::Ln => write!(f, "ln"), |
| 330 | + Token::Log => write!(f, "log"), |
| 331 | + Token::Antiln => write!(f, "antiln"), |
| 332 | + Token::Antilog => write!(f, "antilog"), |
| 333 | + Token::Show => write!(f, "show"), |
| 334 | + Token::Hide => write!(f, "hide"), |
| 335 | + Token::Add => write!(f, "add"), |
| 336 | + Token::To => write!(f, "to"), |
| 337 | + Token::Delete => write!(f, "delete"), |
| 338 | + Token::Insert => write!(f, "insert"), |
| 339 | + Token::At => write!(f, "at"), |
| 340 | + Token::Of => write!(f, "of"), |
| 341 | + Token::As => write!(f, "as"), |
| 342 | + Token::Enum => write!(f, "enum"), |
| 343 | + Token::Struct => write!(f, "struct"), |
| 344 | + Token::True => write!(f, "true"), |
| 345 | + Token::False => write!(f, "false"), |
| 346 | + Token::List => write!(f, "list"), |
| 347 | + Token::Cloud => write!(f, "cloud"), |
| 348 | + Token::Pipe => write!(f, "|>"), |
| 349 | + Token::SetX => write!(f, "set_x"), |
| 350 | + Token::SetY => write!(f, "set_y"), |
| 351 | + Token::SetSize => write!(f, "set_size"), |
| 352 | + Token::PointInDirection => write!(f, "point_in_direction"), |
| 353 | + Token::SetVolume => write!(f, "set_volume"), |
| 354 | + Token::SetRotationStyleLeftRight => write!(f, "set_rotation_style_left_right"), |
| 355 | + Token::SetRotationStyleAllAround => write!(f, "set_rotation_style_all_around"), |
| 356 | + Token::SetRotationStyleDoNotRotate => write!(f, "set_rotation_style_do_not_rotate"), |
| 357 | + Token::SetLayerOrder => write!(f, "set_layer_order"), |
| 358 | + Token::Var => write!(f, "var"), |
| 359 | + } |
| 360 | + } |
| 361 | +} |
0 commit comments