2021-10-19 22:24:27 -07:00
|
|
|
#![allow(clippy::upper_case_acronyms)]
|
|
|
|
|
2018-02-23 01:58:06 -08:00
|
|
|
use itertools::Itertools;
|
2021-10-14 02:47:19 -07:00
|
|
|
use std::{iter::{Iterator, Peekable}, convert::TryFrom, rc::Rc, fmt};
|
2021-10-14 06:18:17 -07:00
|
|
|
use std::convert::TryInto;
|
2018-02-23 01:58:06 -08:00
|
|
|
|
2021-10-19 16:42:48 -07:00
|
|
|
/// A location in a particular source file. Note that the
|
|
|
|
/// sizes of the internal unsigned integer types limit
|
|
|
|
/// the size of a source file to 2^32 lines of
|
|
|
|
/// at most 2^16 characters, which should be plenty big.
|
2021-10-14 06:18:17 -07:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
|
|
|
pub struct Location {
|
2021-10-19 16:42:48 -07:00
|
|
|
pub(crate) line_num: u32,
|
|
|
|
pub(crate) char_num: u16,
|
2021-10-14 06:18:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Location {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}:{}", self.line_num, self.char_num)
|
|
|
|
}
|
|
|
|
}
|
2019-10-23 00:48:59 -07:00
|
|
|
|
2018-02-23 01:58:06 -08:00
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
2018-11-16 23:17:34 -08:00
|
|
|
pub enum TokenKind {
|
2018-02-23 01:58:06 -08:00
|
|
|
Newline, Semicolon,
|
|
|
|
|
|
|
|
LParen, RParen,
|
|
|
|
LSquareBracket, RSquareBracket,
|
|
|
|
LAngleBracket, RAngleBracket,
|
|
|
|
LCurlyBrace, RCurlyBrace,
|
2018-11-05 18:50:45 -08:00
|
|
|
Pipe, Backslash,
|
2018-02-23 01:58:06 -08:00
|
|
|
|
|
|
|
Comma, Period, Colon, Underscore,
|
2019-06-16 16:07:27 -07:00
|
|
|
Slash, Equals,
|
2018-02-23 01:58:06 -08:00
|
|
|
|
|
|
|
Operator(Rc<String>),
|
|
|
|
DigitGroup(Rc<String>), HexLiteral(Rc<String>), BinNumberSigil,
|
2019-11-05 02:22:11 -08:00
|
|
|
StrLiteral {
|
|
|
|
s: Rc<String>,
|
|
|
|
prefix: Option<Rc<String>>
|
|
|
|
},
|
2018-02-23 01:58:06 -08:00
|
|
|
Identifier(Rc<String>),
|
|
|
|
Keyword(Kw),
|
|
|
|
|
|
|
|
EOF,
|
|
|
|
|
|
|
|
Error(String),
|
|
|
|
}
|
2018-11-16 23:17:34 -08:00
|
|
|
use self::TokenKind::*;
|
2018-02-23 01:58:06 -08:00
|
|
|
|
2018-11-16 23:17:34 -08:00
|
|
|
impl fmt::Display for TokenKind {
|
2018-03-02 22:11:25 -08:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
&Operator(ref s) => write!(f, "Operator({})", **s),
|
|
|
|
&DigitGroup(ref s) => write!(f, "DigitGroup({})", s),
|
|
|
|
&HexLiteral(ref s) => write!(f, "HexLiteral({})", s),
|
2019-11-05 02:22:11 -08:00
|
|
|
&StrLiteral {ref s, .. } => write!(f, "StrLiteral({})", s),
|
2018-03-02 22:11:25 -08:00
|
|
|
&Identifier(ref s) => write!(f, "Identifier({})", s),
|
|
|
|
&Error(ref s) => write!(f, "Error({})", s),
|
|
|
|
other => write!(f, "{:?}", other),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-23 01:58:06 -08:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
pub enum Kw {
|
2018-06-19 00:07:28 -07:00
|
|
|
If, Then, Else,
|
|
|
|
Is,
|
2018-02-23 01:58:06 -08:00
|
|
|
Func,
|
2018-05-12 23:49:02 -07:00
|
|
|
For, While,
|
2018-07-11 16:44:15 -07:00
|
|
|
Const, Let, In,
|
|
|
|
Mut,
|
2018-02-23 01:58:06 -08:00
|
|
|
Return,
|
|
|
|
Alias, Type, SelfType, SelfIdent,
|
2018-04-24 16:30:17 -07:00
|
|
|
Interface, Impl,
|
2018-02-23 01:58:06 -08:00
|
|
|
True, False,
|
2019-09-20 18:19:29 -07:00
|
|
|
Module, Import
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
|
|
|
|
2021-10-14 02:47:19 -07:00
|
|
|
impl TryFrom<&str> for Kw {
|
|
|
|
type Error = ();
|
|
|
|
|
|
|
|
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
|
|
|
Ok(match value {
|
2018-02-23 01:58:06 -08:00
|
|
|
"if" => Kw::If,
|
2018-06-19 00:07:28 -07:00
|
|
|
"then" => Kw::Then,
|
2018-02-23 01:58:06 -08:00
|
|
|
"else" => Kw::Else,
|
2018-06-19 00:07:28 -07:00
|
|
|
"is" => Kw::Is,
|
2018-02-23 01:58:06 -08:00
|
|
|
"fn" => Kw::Func,
|
|
|
|
"for" => Kw::For,
|
2018-05-12 23:49:02 -07:00
|
|
|
"while" => Kw::While,
|
2018-02-23 01:58:06 -08:00
|
|
|
"const" => Kw::Const,
|
|
|
|
"let" => Kw::Let,
|
|
|
|
"in" => Kw::In,
|
2018-07-11 16:44:15 -07:00
|
|
|
"mut" => Kw::Mut,
|
2018-02-23 01:58:06 -08:00
|
|
|
"return" => Kw::Return,
|
|
|
|
"alias" => Kw::Alias,
|
|
|
|
"type" => Kw::Type,
|
|
|
|
"Self" => Kw::SelfType,
|
|
|
|
"self" => Kw::SelfIdent,
|
2018-04-24 16:30:17 -07:00
|
|
|
"interface" => Kw::Interface,
|
2018-02-23 01:58:06 -08:00
|
|
|
"impl" => Kw::Impl,
|
|
|
|
"true" => Kw::True,
|
|
|
|
"false" => Kw::False,
|
|
|
|
"module" => Kw::Module,
|
2019-09-20 18:19:29 -07:00
|
|
|
"import" => Kw::Import,
|
2021-10-14 02:47:19 -07:00
|
|
|
_ => return Err(()),
|
|
|
|
})
|
|
|
|
}
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
|
|
|
|
2019-10-22 02:11:49 -07:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2018-02-23 01:58:06 -08:00
|
|
|
pub struct Token {
|
2018-11-16 23:17:34 -08:00
|
|
|
pub kind: TokenKind,
|
2021-10-14 06:18:17 -07:00
|
|
|
pub(crate) location: Location,
|
2018-11-16 03:51:03 -08:00
|
|
|
}
|
|
|
|
|
2018-02-23 01:58:06 -08:00
|
|
|
impl Token {
|
2018-03-02 22:11:25 -08:00
|
|
|
pub fn to_string_with_metadata(&self) -> String {
|
2019-10-23 00:48:59 -07:00
|
|
|
format!("{}({})", self.kind, self.location)
|
2018-03-02 22:11:25 -08:00
|
|
|
}
|
2018-11-16 03:51:03 -08:00
|
|
|
|
2018-11-16 23:17:34 -08:00
|
|
|
pub fn get_kind(&self) -> TokenKind {
|
|
|
|
self.kind.clone()
|
2018-11-16 03:51:03 -08:00
|
|
|
}
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
|
|
|
|
2018-03-17 19:12:58 -07:00
|
|
|
const OPERATOR_CHARS: [char; 18] = ['!', '$', '%', '&', '*', '+', '-', '.', ':', '<', '>', '=', '?', '@', '^', '|', '~', '`'];
|
2018-02-23 01:58:06 -08:00
|
|
|
fn is_operator(c: &char) -> bool {
|
|
|
|
OPERATOR_CHARS.iter().any(|x| x == c)
|
|
|
|
}
|
|
|
|
|
2018-05-11 02:08:05 -07:00
|
|
|
type CharData = (usize, usize, char);
|
2018-03-02 02:57:04 -08:00
|
|
|
|
2018-02-23 01:58:06 -08:00
|
|
|
pub fn tokenize(input: &str) -> Vec<Token> {
|
|
|
|
let mut tokens: Vec<Token> = Vec::new();
|
2018-03-02 02:57:04 -08:00
|
|
|
|
2021-10-07 00:51:45 -07:00
|
|
|
let mut input = Iterator::intersperse(input.lines().enumerate(), (0, "\n"))
|
2021-10-19 21:27:05 -07:00
|
|
|
.flat_map(|(line_idx, line)| {
|
2018-03-02 02:57:04 -08:00
|
|
|
line.chars().enumerate().map(move |(ch_idx, ch)| (line_idx, ch_idx, ch))
|
2018-03-24 18:38:28 -07:00
|
|
|
})
|
|
|
|
.peekable();
|
2018-03-02 02:57:04 -08:00
|
|
|
|
2019-01-08 02:11:19 -08:00
|
|
|
while let Some((line_num, char_num, c)) = input.next() {
|
2018-11-16 23:17:34 -08:00
|
|
|
let cur_tok_kind = match c {
|
2018-03-17 22:25:43 -07:00
|
|
|
'/' => match input.peek().map(|t| t.2) {
|
|
|
|
Some('/') => {
|
2021-10-19 21:27:05 -07:00
|
|
|
for (_, _, c) in input.by_ref() {
|
|
|
|
if c == '\n' {
|
|
|
|
break;
|
|
|
|
}
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
2018-03-17 19:12:58 -07:00
|
|
|
continue;
|
|
|
|
},
|
2018-03-17 22:25:43 -07:00
|
|
|
Some('*') => {
|
|
|
|
input.next();
|
|
|
|
let mut comment_level = 1;
|
|
|
|
while let Some((_, _, c)) = input.next() {
|
|
|
|
if c == '*' && input.peek().map(|t| t.2) == Some('/') {
|
|
|
|
input.next();
|
|
|
|
comment_level -= 1;
|
|
|
|
} else if c == '/' && input.peek().map(|t| t.2) == Some('*') {
|
|
|
|
input.next();
|
|
|
|
comment_level += 1;
|
|
|
|
}
|
|
|
|
if comment_level == 0 {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-10-14 03:05:25 -07:00
|
|
|
if comment_level != 0 {
|
|
|
|
Error("Unclosed comment".to_string())
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
2018-03-17 19:12:58 -07:00
|
|
|
},
|
|
|
|
_ => Slash
|
2018-02-23 01:58:06 -08:00
|
|
|
},
|
|
|
|
c if c.is_whitespace() && c != '\n' => continue,
|
|
|
|
'\n' => Newline, ';' => Semicolon,
|
|
|
|
':' => Colon, ',' => Comma,
|
|
|
|
'(' => LParen, ')' => RParen,
|
|
|
|
'{' => LCurlyBrace, '}' => RCurlyBrace,
|
|
|
|
'[' => LSquareBracket, ']' => RSquareBracket,
|
2019-11-05 02:22:11 -08:00
|
|
|
'"' => handle_quote(&mut input, None),
|
2018-11-05 18:50:45 -08:00
|
|
|
'\\' => Backslash,
|
2018-02-23 01:58:06 -08:00
|
|
|
c if c.is_digit(10) => handle_digit(c, &mut input),
|
2019-01-08 02:38:10 -08:00
|
|
|
c if c.is_alphabetic() || c == '_' => handle_alphabetic(c, &mut input),
|
2018-02-23 01:58:06 -08:00
|
|
|
c if is_operator(&c) => handle_operator(c, &mut input),
|
|
|
|
unknown => Error(format!("Unexpected character: {}", unknown)),
|
|
|
|
};
|
2021-10-19 16:42:48 -07:00
|
|
|
let location = Location { line_num: line_num.try_into().unwrap(), char_num: char_num.try_into().unwrap() };
|
2019-10-23 00:48:59 -07:00
|
|
|
tokens.push(Token { kind: cur_tok_kind, location });
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
|
|
|
tokens
|
|
|
|
}
|
|
|
|
|
2018-11-16 23:17:34 -08:00
|
|
|
fn handle_digit(c: char, input: &mut Peekable<impl Iterator<Item=CharData>>) -> TokenKind {
|
2021-10-19 21:27:05 -07:00
|
|
|
let next_ch = input.peek().map(|&(_, _, c)| c);
|
|
|
|
|
|
|
|
if c == '0' && next_ch == Some('x') {
|
|
|
|
input.next();
|
|
|
|
let rest: String = input.peeking_take_while(|&(_, _, ref c)| c.is_digit(16) || *c == '_').map(|(_, _, c)| { c }).collect();
|
|
|
|
HexLiteral(Rc::new(rest))
|
|
|
|
} else if c == '0' && next_ch == Some('b') {
|
|
|
|
input.next();
|
|
|
|
BinNumberSigil
|
|
|
|
} else {
|
|
|
|
let mut buf = c.to_string();
|
|
|
|
buf.extend(input.peeking_take_while(|&(_, _, ref c)| c.is_digit(10)).map(|(_, _, c)| { c }));
|
|
|
|
DigitGroup(Rc::new(buf))
|
|
|
|
}
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
|
|
|
|
2019-11-05 02:22:11 -08:00
|
|
|
fn handle_quote(input: &mut Peekable<impl Iterator<Item=CharData>>, quote_prefix: Option<&str>) -> TokenKind {
|
2018-02-23 01:58:06 -08:00
|
|
|
let mut buf = String::new();
|
|
|
|
loop {
|
2018-03-02 15:15:12 -08:00
|
|
|
match input.next().map(|(_, _, c)| { c }) {
|
2018-02-23 01:58:06 -08:00
|
|
|
Some('"') => break,
|
|
|
|
Some('\\') => {
|
2018-03-02 15:15:12 -08:00
|
|
|
let next = input.peek().map(|&(_, _, c)| { c });
|
2018-02-23 01:58:06 -08:00
|
|
|
if next == Some('n') {
|
|
|
|
input.next();
|
|
|
|
buf.push('\n')
|
|
|
|
} else if next == Some('"') {
|
|
|
|
input.next();
|
|
|
|
buf.push('"');
|
|
|
|
} else if next == Some('t') {
|
|
|
|
input.next();
|
|
|
|
buf.push('\t');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Some(c) => buf.push(c),
|
2021-10-14 03:12:05 -07:00
|
|
|
None => return TokenKind::Error("Unclosed string".to_string()),
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
|
|
|
}
|
2019-11-05 02:22:11 -08:00
|
|
|
TokenKind::StrLiteral { s: Rc::new(buf), prefix: quote_prefix.map(|s| Rc::new(s.to_string())) }
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
|
|
|
|
2018-11-16 23:17:34 -08:00
|
|
|
fn handle_alphabetic(c: char, input: &mut Peekable<impl Iterator<Item=CharData>>) -> TokenKind {
|
2018-02-23 01:58:06 -08:00
|
|
|
let mut buf = String::new();
|
|
|
|
buf.push(c);
|
2021-10-19 21:27:05 -07:00
|
|
|
let next_is_alphabetic = input.peek().map(|&(_, _, c)| !c.is_alphabetic()).unwrap_or(true);
|
|
|
|
if c == '_' && next_is_alphabetic {
|
2018-11-16 23:17:34 -08:00
|
|
|
return TokenKind::Underscore
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
loop {
|
2018-03-02 15:15:12 -08:00
|
|
|
match input.peek().map(|&(_, _, c)| { c }) {
|
2019-11-05 02:22:11 -08:00
|
|
|
Some(c) if c == '"' => {
|
|
|
|
input.next();
|
|
|
|
return handle_quote(input, Some(&buf));
|
|
|
|
},
|
2018-11-15 16:19:53 -08:00
|
|
|
Some(c) if c.is_alphanumeric() || c == '_' => {
|
2018-02-23 01:58:06 -08:00
|
|
|
input.next();
|
|
|
|
buf.push(c);
|
|
|
|
},
|
|
|
|
_ => break,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-14 02:47:19 -07:00
|
|
|
match Kw::try_from(buf.as_str()) {
|
|
|
|
Ok(kw) => TokenKind::Keyword(kw),
|
|
|
|
Err(()) => TokenKind::Identifier(Rc::new(buf)),
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-16 23:17:34 -08:00
|
|
|
fn handle_operator(c: char, input: &mut Peekable<impl Iterator<Item=CharData>>) -> TokenKind {
|
2018-02-23 01:58:06 -08:00
|
|
|
match c {
|
2019-06-16 16:07:27 -07:00
|
|
|
'<' | '>' | '|' | '.' | '=' => {
|
2021-10-19 21:27:05 -07:00
|
|
|
let next = &input.peek().map(|&(_, _, c)| { c });
|
|
|
|
let next_is_op = next.map(|n| { is_operator(&n) }).unwrap_or(false);
|
|
|
|
if !next_is_op {
|
2018-02-23 01:58:06 -08:00
|
|
|
return match c {
|
|
|
|
'<' => LAngleBracket,
|
|
|
|
'>' => RAngleBracket,
|
|
|
|
'|' => Pipe,
|
|
|
|
'.' => Period,
|
2019-06-16 16:07:27 -07:00
|
|
|
'=' => Equals,
|
2018-02-23 01:58:06 -08:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => (),
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut buf = String::new();
|
2018-04-25 03:01:41 -07:00
|
|
|
|
|
|
|
if c == '`' {
|
|
|
|
loop {
|
|
|
|
match input.peek().map(|&(_, _, c)| { c }) {
|
|
|
|
Some(c) if c.is_alphabetic() || c == '_' => {
|
|
|
|
input.next();
|
|
|
|
buf.push(c);
|
|
|
|
},
|
|
|
|
Some('`') => {
|
|
|
|
input.next();
|
|
|
|
break;
|
|
|
|
},
|
|
|
|
_ => break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
buf.push(c);
|
|
|
|
loop {
|
|
|
|
match input.peek().map(|&(_, _, c)| { c }) {
|
|
|
|
Some(c) if is_operator(&c) => {
|
|
|
|
input.next();
|
|
|
|
buf.push(c);
|
|
|
|
},
|
|
|
|
_ => break
|
|
|
|
}
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
|
|
|
}
|
2018-11-16 23:17:34 -08:00
|
|
|
TokenKind::Operator(Rc::new(buf))
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod schala_tokenizer_tests {
|
|
|
|
use super::*;
|
2018-02-23 01:59:53 -08:00
|
|
|
use super::Kw::*;
|
2018-02-23 01:58:06 -08:00
|
|
|
|
|
|
|
macro_rules! digit { ($ident:expr) => { DigitGroup(Rc::new($ident.to_string())) } }
|
|
|
|
macro_rules! ident { ($ident:expr) => { Identifier(Rc::new($ident.to_string())) } }
|
|
|
|
macro_rules! op { ($ident:expr) => { Operator(Rc::new($ident.to_string())) } }
|
|
|
|
|
2021-10-14 05:23:24 -07:00
|
|
|
fn token_kinds(input: &str) -> Vec<TokenKind> {
|
|
|
|
tokenize(input).into_iter().map(move |tok| tok.kind).collect()
|
|
|
|
}
|
|
|
|
|
2018-02-23 01:58:06 -08:00
|
|
|
#[test]
|
|
|
|
fn tokens() {
|
2021-10-14 05:23:24 -07:00
|
|
|
let output = token_kinds("let a: A<B> = c ++ d");
|
|
|
|
assert_eq!(output, vec![Keyword(Let), ident!("a"), Colon, ident!("A"),
|
2019-06-16 16:07:27 -07:00
|
|
|
LAngleBracket, ident!("B"), RAngleBracket, Equals, ident!("c"), op!("++"), ident!("d")]);
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn underscores() {
|
2021-10-14 05:23:24 -07:00
|
|
|
let output = token_kinds("4_8");
|
|
|
|
assert_eq!(output, vec![digit!("4"), Underscore, digit!("8")]);
|
2018-11-15 16:19:53 -08:00
|
|
|
|
2021-10-14 05:23:24 -07:00
|
|
|
let output = token_kinds("aba_yo");
|
|
|
|
assert_eq!(output, vec![ident!("aba_yo")]);
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|
2018-03-17 22:25:43 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn comments() {
|
2021-10-14 05:23:24 -07:00
|
|
|
let output = token_kinds("1 + /* hella /* bro */ */ 2");
|
|
|
|
assert_eq!(output, vec![digit!("1"), op!("+"), digit!("2")]);
|
|
|
|
|
|
|
|
let output = token_kinds("1 + /* hella /* bro */ 2");
|
|
|
|
assert_eq!(output, vec![digit!("1"), op!("+"), Error("Unclosed comment".to_string())]);
|
2021-10-14 03:12:05 -07:00
|
|
|
|
2021-10-14 05:23:24 -07:00
|
|
|
//TODO not sure if I want this behavior
|
|
|
|
let output = token_kinds("1 + /* hella */ bro */ 2");
|
|
|
|
assert_eq!(output, vec![digit!("1"), op!("+"), Identifier(Rc::new("bro".to_string())), Operator(Rc::new("*".to_string())), Slash, DigitGroup(Rc::new("2".to_string()))]);
|
2018-03-17 22:25:43 -07:00
|
|
|
}
|
2018-04-25 03:01:41 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn backtick_operators() {
|
2021-10-14 05:23:24 -07:00
|
|
|
let output = token_kinds("1 `plus` 2");
|
|
|
|
assert_eq!(output, vec![digit!("1"), op!("plus"), digit!("2")]);
|
2018-04-25 03:01:41 -07:00
|
|
|
}
|
2019-11-05 02:22:11 -08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn string_literals() {
|
2021-10-14 05:23:24 -07:00
|
|
|
let output = token_kinds(r#""some string""#);
|
|
|
|
assert_eq!(output, vec![StrLiteral { s: Rc::new("some string".to_string()), prefix: None }]);
|
2019-11-05 02:22:11 -08:00
|
|
|
|
2021-10-14 05:23:24 -07:00
|
|
|
let output = token_kinds(r#"b"some bytestring""#);
|
|
|
|
assert_eq!(output, vec![StrLiteral { s: Rc::new("some bytestring".to_string()), prefix: Some(Rc::new("b".to_string())) }]);
|
2021-10-14 03:12:05 -07:00
|
|
|
|
2021-10-14 05:23:24 -07:00
|
|
|
let output = token_kinds(r#""Do \n \" escapes work\t""#);
|
|
|
|
assert_eq!(output, vec![StrLiteral { s: Rc::new("Do \n \" escapes work\t".to_string()), prefix: None }]);
|
2019-11-05 02:22:11 -08:00
|
|
|
}
|
2018-02-23 01:58:06 -08:00
|
|
|
}
|