From da2ade654279324a6a5a11b80aeca3f24b8bfec0 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 13 Aug 2020 20:02:07 +0200 Subject: [PATCH] =?UTF-8?q?Remove=20redundant=20`Expr`=20prefix=20from=20t?= =?UTF-8?q?okens=20=F0=9F=A7=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/parsing.rs | 14 ++++++------ src/syntax/tokens.rs | 52 +++++++++++++++++++++---------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs index bf16e1469..b0b15dbfe 100644 --- a/src/syntax/parsing.rs +++ b/src/syntax/parsing.rs @@ -284,7 +284,7 @@ impl<'s> FuncParser<'s> { impl FuncParser<'_> { fn parse_ident(&mut self) -> Option> { self.peek().and_then(|token| match token.v { - Token::ExprIdent(id) => self.eat_span(Ident(id.to_string())), + Token::Ident(id) => self.eat_span(Ident(id.to_string())), _ => None, }) } @@ -360,7 +360,7 @@ impl FuncParser<'_> { let Spanned { v: token, span } = self.peek()?; match token { // This could be a named tuple or an identifier. - Token::ExprIdent(id) => { + Token::Ident(id) => { let name = Spanned::new(Ident(id.to_string()), span); self.eat(); self.skip_white(); @@ -371,17 +371,17 @@ impl FuncParser<'_> { }) } - Token::ExprStr { string, terminated } => { + Token::Str { string, terminated } => { if !terminated { self.expected_at("quote", span.end); } self.eat_span(Expr::Str(unescape_string(string))) } - Token::ExprBool(b) => self.eat_span(Expr::Bool(b)), - Token::ExprNumber(n) => self.eat_span(Expr::Number(n)), - Token::ExprLength(s) => self.eat_span(Expr::Length(s)), - Token::ExprHex(s) => { + Token::Bool(b) => self.eat_span(Expr::Bool(b)), + Token::Number(n) => self.eat_span(Expr::Number(n)), + Token::Length(s) => self.eat_span(Expr::Length(s)), + Token::Hex(s) => { if let Ok(color) = RgbaColor::from_str(s) { self.eat_span(Expr::Color(color)) } else { diff --git a/src/syntax/tokens.rs b/src/syntax/tokens.rs index ef2494714..bf172651c 100644 --- a/src/syntax/tokens.rs +++ b/src/syntax/tokens.rs @@ -54,15 +54,15 @@ pub enum Token<'s> { /// A colon in a function header: `:`. Colon, - /// A comma in a function header: `:`. + /// A comma in a function header: `,`. Comma, /// An equals sign in a function header: `=`. Equals, /// An identifier in a function header: `center`. - ExprIdent(&'s str), + Ident(&'s str), /// A quoted string in a function header: `"..."`. - ExprStr { + Str { /// The string inside the quotes. /// /// _Note_: If the string contains escape sequences these are not yet @@ -73,13 +73,13 @@ pub enum Token<'s> { terminated: bool, }, /// A boolean in a function header: `true | false`. - ExprBool(bool), + Bool(bool), /// A number in a function header: `3.14`. - ExprNumber(f64), + Number(f64), /// A length in a function header: `12pt`. - ExprLength(Length), + Length(Length), /// A hex value in a function header: `#20d82a`. - ExprHex(&'s str), + Hex(&'s str), /// A plus in a function header, signifying the addition of expressions. Plus, /// A hyphen in a function header, signifying the subtraction of @@ -127,12 +127,12 @@ impl<'s> Token<'s> { Colon => "colon", Comma => "comma", Equals => "equals sign", - ExprIdent(_) => "identifier", - ExprStr { .. } => "string", - ExprBool(_) => "bool", - ExprNumber(_) => "number", - ExprLength(_) => "length", - ExprHex(_) => "hex value", + Ident(_) => "identifier", + Str { .. } => "string", + Bool(_) => "bool", + Number(_) => "number", + Length(_) => "length", + Hex(_) => "hex value", Plus => "plus", Hyphen => "minus", Slash => "slash", @@ -370,7 +370,7 @@ impl<'s> Tokens<'s> { fn read_string(&mut self) -> Token<'s> { let (string, terminated) = self.read_until_unescaped('"'); - ExprStr { string, terminated } + Str { string, terminated } } fn read_raw(&mut self) -> Token<'s> { @@ -414,7 +414,7 @@ impl<'s> Tokens<'s> { fn read_hex(&mut self) -> Token<'s> { // This will parse more than the permissable 0-9, a-f, A-F character // ranges to provide nicer error messages later. - ExprHex(self.read_string_until( + Hex(self.read_string_until( |n| !n.is_ascii_alphanumeric(), false, 0, 0 ).0) @@ -422,15 +422,15 @@ impl<'s> Tokens<'s> { fn read_expr(&mut self, text: &'s str) -> Token<'s> { if let Ok(b) = text.parse::() { - ExprBool(b) + Bool(b) } else if let Ok(num) = text.parse::() { - ExprNumber(num) + Number(num) } else if let Some(num) = parse_percentage(text) { - ExprNumber(num / 100.0) + Number(num / 100.0) } else if let Ok(length) = text.parse::() { - ExprLength(length) + Length(length) } else if is_identifier(text) { - ExprIdent(text) + Ident(text) } else { Invalid(text) } @@ -542,11 +542,11 @@ mod tests { LineComment as LC, BlockComment as BC, LeftParen as LP, RightParen as RP, LeftBrace as LB, RightBrace as RB, - ExprIdent as Id, - ExprBool as Bool, - ExprNumber as Num, - ExprLength as Len, - ExprHex as Hex, + Ident as Id, + Bool, + Number as Num, + Length as Len, + Hex, Plus, Hyphen as Min, Slash, @@ -563,7 +563,7 @@ mod tests { } } - fn Str(string: &str, terminated: bool) -> Token { Token::ExprStr { string, terminated } } + fn Str(string: &str, terminated: bool) -> Token { Token::Str { string, terminated } } fn Raw(raw: &str, terminated: bool) -> Token { Token::Raw { raw, terminated } } macro_rules! func {