From e8a4a82e4db4e1c023e53b6232fb2375ce1eec87 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sun, 23 Oct 2016 18:46:04 -0700 Subject: [PATCH] TokenClass -> TokenKind 'Kind' seems to be the rust convention, or close too it. See std::io::ErrorKind and compiler internals. --- notes | 3 +-- src/lib.rs | 20 ++++++++++---------- src/tests.rs | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/notes b/notes index d16c4c9..7beabd5 100644 --- a/notes +++ b/notes @@ -9,8 +9,6 @@ notes although maybe only after a '--': j build -- a=hello - parse lines into {{fragments}} and allow argument substitution - change error messages to underline problem token -- try clippy -- use "kind" instead of class - should i use // comments, since that's what's used in rust? - allow calling recipes in a justfile in a different directory: - just ../foo # ../justfile:foo @@ -66,3 +64,4 @@ later: and dir with --directory/-d, so i can do: alias .j='just -j ~/.justfile -d ~' - run recipes asyncronously +- lint with clippy once it runs on stable diff --git a/src/lib.rs b/src/lib.rs index 0b87d8c..d08b010 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -259,7 +259,7 @@ enum ErrorKind<'a> { AssignmentUnimplemented, UnknownDependency{recipe: &'a str, unknown: &'a str}, UnknownStartOfToken, - UnexpectedToken{expected: Vec, found: TokenClass}, + UnexpectedToken{expected: Vec, found: TokenKind}, InternalError{message: String}, } @@ -476,7 +476,7 @@ struct Token<'a> { text: &'a str, prefix: &'a str, lexeme: &'a str, - class: TokenClass, + class: TokenKind, } impl<'a> Token<'a> { @@ -493,7 +493,7 @@ impl<'a> Token<'a> { } #[derive(Debug, PartialEq, Clone, Copy)] -enum TokenClass { +enum TokenKind { Name, Colon, Equals, @@ -505,7 +505,7 @@ enum TokenClass { Eof, } -impl Display for TokenClass { +impl Display for TokenKind { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { try!(write!(f, "{}", match *self { Name => "name", @@ -522,7 +522,7 @@ impl Display for TokenClass { } } -use TokenClass::*; +use TokenKind::*; fn token(pattern: &str) -> Regex { let mut s = String::new(); @@ -714,11 +714,11 @@ struct Parser<'a> { } impl<'a> Parser<'a> { - fn peek(&mut self, class: TokenClass) -> bool { + fn peek(&mut self, class: TokenKind) -> bool { self.tokens.peek().unwrap().class == class } - fn accept(&mut self, class: TokenClass) -> Option> { + fn accept(&mut self, class: TokenKind) -> Option> { if self.peek(class) { self.tokens.next() } else { @@ -726,11 +726,11 @@ impl<'a> Parser<'a> { } } - fn accepted(&mut self, class: TokenClass) -> bool { + fn accepted(&mut self, class: TokenKind) -> bool { self.accept(class).is_some() } - fn expect(&mut self, class: TokenClass) -> Option> { + fn expect(&mut self, class: TokenKind) -> Option> { if self.peek(class) { self.tokens.next(); None @@ -828,7 +828,7 @@ impl<'a> Parser<'a> { }) } - fn unexpected_token(&self, found: &Token<'a>, expected: &[TokenClass]) -> Error<'a> { + fn unexpected_token(&self, found: &Token<'a>, expected: &[TokenKind]) -> Error<'a> { found.error(ErrorKind::UnexpectedToken { expected: expected.to_vec(), found: found.class, diff --git a/src/tests.rs b/src/tests.rs index e07c5e6..aeac690 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -2,7 +2,7 @@ extern crate tempdir; use super::{Token, Error, ErrorKind, Justfile}; -use super::TokenClass::*; +use super::TokenKind::*; fn tokenize_success(text: &str, expected_summary: &str) { let tokens = super::tokenize(text).unwrap(); @@ -32,15 +32,15 @@ fn tokenize_error(text: &str, expected: Error) { fn token_summary(tokens: &[Token]) -> String { tokens.iter().map(|t| { match t.class { - super::TokenClass::Line{..} => "*", - super::TokenClass::Name => "N", - super::TokenClass::Colon => ":", - super::TokenClass::Equals => "=", - super::TokenClass::Comment{..} => "#", - super::TokenClass::Indent{..} => ">", - super::TokenClass::Dedent => "<", - super::TokenClass::Eol => "$", - super::TokenClass::Eof => ".", + super::TokenKind::Line{..} => "*", + super::TokenKind::Name => "N", + super::TokenKind::Colon => ":", + super::TokenKind::Equals => "=", + super::TokenKind::Comment{..} => "#", + super::TokenKind::Indent{..} => ">", + super::TokenKind::Dedent => "<", + super::TokenKind::Eol => "$", + super::TokenKind::Eof => ".", } }).collect::>().join("") }