This repository has been archived on 2020-09-15. You can view files and clone it, but cannot push or open issues or pull requests.
Files
not-python-old.2020-08-27/src/syn/token.rs

103 lines
1.9 KiB
Rust
Raw Normal View History

use crate::syn::span::*;
use std::fmt::{self, Display, Formatter};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TokenKind {
KwReturn,
Ident,
Num,
Str,
Sym,
LParen,
RParen,
LBrace,
RBrace,
LBracket,
RBracket,
ObjBrace,
Comma,
Eq,
BangEq,
EqEq,
LtEq,
GtEq,
Lt,
Gt,
Arrow,
Plus,
Minus,
Splat,
FSlash,
Dot,
Bang,
Eol,
Newline,
}
impl Display for TokenKind {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
use TokenKind::*;
let s = match self {
KwReturn => "return keyword",
Ident => "identifier",
Num => "number",
Str => "string",
Sym => "symbol",
LParen => "left paren",
RParen => "right paren",
LBrace => "left brace",
RBrace => "right brace",
ObjBrace => "object brace",
LBracket => "left bracket",
RBracket => "right bracket",
Comma => "comma",
Eq => "equals",
BangEq => "not equals",
EqEq => "double equals",
LtEq => "less than or equal to",
GtEq => "greater than or equal to",
Lt => "less than",
Gt => "greater than",
Arrow => "arrow",
Plus => "plus",
Minus => "minus",
Splat => "splat (or times)",
FSlash => "fslash (or divide)",
Dot => "dot",
Bang => "not",
Eol => "line end",
Newline => "newline",
};
Display::fmt(s, fmt)
}
}
#[derive(Debug, Clone, Copy)]
pub struct Token {
kind: TokenKind,
span: Span,
}
impl Token {
pub fn new(kind: TokenKind, span: Span) -> Self {
Token { kind, span }
}
pub fn kind(&self) -> TokenKind {
self.kind
}
}
impl Spanned for Token {
fn span(&self) -> Span {
self.span
}
}