cargo fmt

This commit is contained in:
Markus Westerlind 2020-03-10 15:55:37 +01:00
parent 8f73c9dcfb
commit 165cf03bd1
7 changed files with 27 additions and 23 deletions

View File

@ -6,7 +6,7 @@ pub enum Expr {
Error,
}
pub enum ExprSymbol<'input>{
pub enum ExprSymbol<'input> {
NumSymbol(&'input str),
Op(Box<ExprSymbol<'input>>, Opcode, Box<ExprSymbol<'input>>),
Error,

View File

@ -131,7 +131,7 @@ lalrpop_mod!(pub calculator7);
fn calculator7() {
let scale = 2;
let expr = calculator7::ExprParser::new()
.parse(scale,"11 * 22 + 33")
.parse(scale, "11 * 22 + 33")
.unwrap();
assert_eq!(&format!("{:?}", expr), "((22 * 44) + 66)");
}
@ -144,9 +144,7 @@ use tok8::Lexer;
fn calculator8() {
let input = "22 * pi + 66";
let lexer = Lexer::new(input);
let expr = calculator8::ExprParser::new()
.parse(input,lexer)
.unwrap();
let expr = calculator8::ExprParser::new().parse(input, lexer).unwrap();
assert_eq!(&format!("{:?}", expr), "((\"22\" * \"pi\") + \"66\")");
}

View File

@ -33,7 +33,7 @@ impl<'input> Iterator for Lexer<'input> {
fn next(&mut self) -> Option<Self::Item> {
loop {
match self.chars.next() {
Some((_, ' ')) | Some((_, '\n')) | Some((_, '\t')) => continue,
Some((_, ' ')) | Some((_, '\n')) | Some((_, '\t')) => continue,
Some((i, ')')) => return Some(Ok((i, Tok::ParenClose, i + 1))),
Some((i, '(')) => return Some(Ok((i, Tok::ParenOpen, i + 1))),
Some((i, '+')) => return Some(Ok((i, Tok::ExprOp(Opcode::Add), i + 1))),
@ -42,17 +42,23 @@ impl<'input> Iterator for Lexer<'input> {
Some((i, '/')) => return Some(Ok((i, Tok::FactorOp(Opcode::Div), i + 1))),
None => return None, // End of file
Some((i,_)) => {
loop {
match self.chars.peek() {
Some((j, ')'))|Some((j, '('))|Some((j, '+'))|Some((j, '-'))|Some((j, '*'))|Some((j, '/'))|Some((j,' '))
=> return Some(Ok((i, Tok::NumSymbol(&self.input[i..*j]), *j))),
None => return Some(Ok((i, Tok::NumSymbol(&self.input[i..]),self.input.len()))),
_ => {},
Some((i, _)) => loop {
match self.chars.peek() {
Some((j, ')')) | Some((j, '(')) | Some((j, '+')) | Some((j, '-'))
| Some((j, '*')) | Some((j, '/')) | Some((j, ' ')) => {
return Some(Ok((i, Tok::NumSymbol(&self.input[i..*j]), *j)))
}
self.chars.next();
None => {
return Some(Ok((
i,
Tok::NumSymbol(&self.input[i..]),
self.input.len(),
)))
}
_ => {}
}
}
self.chars.next();
},
}
}
}

View File

@ -4,8 +4,8 @@
use lexer::re::Regex;
use regex_syntax::hir::{
Anchor, Class, ClassBytesRange, ClassUnicodeRange, GroupKind, Hir, HirKind, Literal, RepetitionKind,
RepetitionRange,
Anchor, Class, ClassBytesRange, ClassUnicodeRange, GroupKind, Hir, HirKind, Literal,
RepetitionKind, RepetitionRange,
};
use std::char;
use std::fmt::{Debug, Error as FmtError, Formatter};
@ -133,7 +133,7 @@ impl NFA {
pub fn is_rejecting_state(&self, from: NFAStateIndex) -> bool {
self.states[from.0].kind == StateKind::Reject
}
///////////////////////////////////////////////////////////////////////////
// Private methods for building an NFA

View File

@ -1,4 +1,4 @@
use grammar::parse_tree::{ActionKind, Alternative, ExprSymbol, Symbol, SymbolKind, Name};
use grammar::parse_tree::{ActionKind, Alternative, ExprSymbol, Name, Symbol, SymbolKind};
#[derive(Debug)]
pub enum AlternativeAction<'a> {
@ -131,5 +131,4 @@ mod test {
check_between_braces("bl{<> } b")
);
}
}

View File

@ -129,7 +129,8 @@ fn expandable_expression_requires_named_variables() {
check_err(
r#"Using `<>` between curly braces \(e.g., `\{<>\}`\) only works when your parsed values have been given names \(e.g., `<x:Foo>`, not just `<Foo>`\)"#,
r#"grammar; Term = { <A> => Foo {<>} };"#,
r#" ~~~~~~~~~~~~~~~~ "#);
r#" ~~~~~~~~~~~~~~~~ "#,
);
}
#[test]

View File

@ -4,9 +4,9 @@ use parser;
#[test]
fn match_block() {
let blocks = vec![
r#"grammar; match { _ }"#, // Minimal
r#"grammar; match { _ }"#, // Minimal
r#"grammar; match { _ } else { _ }"#, // Doesn't really make sense, but should be allowed
r#"grammar; match { "abc" }"#, // Single token
r#"grammar; match { "abc" }"#, // Single token
r#"grammar; match { "abc" => "QUOTED" }"#, // Single token with quoted alias
r#"grammar; match { "abc" => UNQUOTED }"#, // Single token with unquoted alias
r#"grammar; match { r"(?i)begin" => BEGIN }"#, // Regex