Rename Scanner to Lexer (#276)

This commit is contained in:
Casey Rodarmor 2017-12-01 11:22:32 +01:00 committed by GitHub
parent c5eeb8944e
commit 66391de3f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 13 deletions

View File

@ -19,7 +19,7 @@ fn mixed_whitespace(text: &str) -> bool {
!(text.chars().all(|c| c == ' ') || text.chars().all(|c| c == '\t')) !(text.chars().all(|c| c == ' ') || text.chars().all(|c| c == '\t'))
} }
pub struct Scanner<'a> { pub struct Lexer<'a> {
tokens: Vec<Token<'a>>, tokens: Vec<Token<'a>>,
text: &'a str, text: &'a str,
rest: &'a str, rest: &'a str,
@ -37,9 +37,9 @@ enum State<'a> {
Interpolation, Interpolation,
} }
impl<'a> Scanner<'a> { impl<'a> Lexer<'a> {
pub fn scan(text: &'a str) -> CompilationResult<Vec<Token<'a>>> { pub fn lex(text: &'a str) -> CompilationResult<Vec<Token<'a>>> {
let scanner = Scanner{ let lexer = Lexer{
tokens: vec![], tokens: vec![],
text: text, text: text,
rest: text, rest: text,
@ -49,7 +49,7 @@ impl<'a> Scanner<'a> {
state: vec![State::Start], state: vec![State::Start],
}; };
scanner.inner() lexer.inner()
} }
fn error(&self, kind: CompilationErrorKind<'a>) -> CompilationError<'a> { fn error(&self, kind: CompilationErrorKind<'a>) -> CompilationError<'a> {
@ -75,7 +75,7 @@ impl<'a> Scanner<'a> {
} }
} }
fn scan_indent(&mut self) -> CompilationResult<'a, Option<Token<'a>>> { fn lex_indent(&mut self) -> CompilationResult<'a, Option<Token<'a>>> {
lazy_static! { lazy_static! {
static ref INDENT: Regex = re(r"^([ \t]*)[^ \t\n\r]"); static ref INDENT: Regex = re(r"^([ \t]*)[^ \t\n\r]");
} }
@ -150,7 +150,7 @@ impl<'a> Scanner<'a> {
} }
loop { loop {
if let Some(token) = self.scan_indent()? { if let Some(token) = self.lex_indent()? {
self.tokens.push(token); self.tokens.push(token);
} }
@ -306,7 +306,7 @@ mod test {
fn $name() { fn $name() {
let input = $input; let input = $input;
let expected = $expected; let expected = $expected;
let tokens = ::Scanner::scan(input).unwrap(); let tokens = ::Lexer::lex(input).unwrap();
let roundtrip = tokens.iter().map(|t| { let roundtrip = tokens.iter().map(|t| {
let mut s = String::new(); let mut s = String::new();
s += t.prefix; s += t.prefix;
@ -369,7 +369,7 @@ mod test {
kind: $kind, kind: $kind,
}; };
if let Err(error) = Scanner::scan(input) { if let Err(error) = Lexer::lex(input) {
assert_eq!(error.text, expected.text); assert_eq!(error.text, expected.text);
assert_eq!(error.index, expected.index); assert_eq!(error.index, expected.index);
assert_eq!(error.line, expected.line); assert_eq!(error.line, expected.line);

View File

@ -24,6 +24,7 @@ mod cooked_string;
mod expression; mod expression;
mod fragment; mod fragment;
mod justfile; mod justfile;
mod lexer;
mod misc; mod misc;
mod parameter; mod parameter;
mod parser; mod parser;
@ -33,7 +34,6 @@ mod recipe;
mod recipe_resolver; mod recipe_resolver;
mod run; mod run;
mod runtime_error; mod runtime_error;
mod scanner;
mod shebang; mod shebang;
mod token; mod token;
@ -68,7 +68,7 @@ mod common {
pub use recipe::Recipe; pub use recipe::Recipe;
pub use recipe_resolver::RecipeResolver; pub use recipe_resolver::RecipeResolver;
pub use runtime_error::{RuntimeError, RunResult}; pub use runtime_error::{RuntimeError, RunResult};
pub use scanner::Scanner; pub use lexer::Lexer;
pub use shebang::Shebang; pub use shebang::Shebang;
pub use token::{Token, TokenKind}; pub use token::{Token, TokenKind};
} }

View File

@ -15,7 +15,7 @@ pub struct Parser<'a> {
impl<'a> Parser<'a> { impl<'a> Parser<'a> {
pub fn parse(text: &'a str) -> CompilationResult<'a, Justfile> { pub fn parse(text: &'a str) -> CompilationResult<'a, Justfile> {
let tokens = Scanner::scan(text)?; let tokens = Lexer::lex(text)?;
let parser = Parser::new(text, tokens); let parser = Parser::new(text, tokens);
parser.justfile() parser.justfile()
} }

View File

@ -30,7 +30,7 @@ macro_rules! compilation_error_test {
kind: $kind, kind: $kind,
}; };
let tokens = ::Scanner::scan(input).unwrap(); let tokens = ::Lexer::lex(input).unwrap();
let parser = ::Parser::new(input, tokens); let parser = ::Parser::new(input, tokens);
if let Err(error) = parser.justfile() { if let Err(error) = parser.justfile() {