Skip to content

Commit

Permalink
Add support for older Rust versions (down to 1.25.0).
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Jun 20, 2018
1 parent b112e46 commit 844ccfd
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 63 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: rust
rust:
- 1.25.0
- stable
- beta
- nightly
Expand Down
6 changes: 3 additions & 3 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub enum Uop {

impl fmt::Display for Uop {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{}", match self {
write!(f, "{}", match *self {
Uop::Plus => "+",
Uop::Minus => "-",
Uop::Invert => "~",
Expand Down Expand Up @@ -144,7 +144,7 @@ pub enum Bop {

impl fmt::Display for Bop {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{}", match self {
write!(f, "{}", match *self {
Bop::Add => "+",
Bop::Sub => "-",
Bop::Mult => "*",
Expand Down Expand Up @@ -290,7 +290,7 @@ pub enum AugAssignOp {

impl fmt::Display for AugAssignOp {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{}", match self {
write!(f, "{}", match *self {
AugAssignOp::Add => "+=",
AugAssignOp::Sub => "-=",
AugAssignOp::Mult => "*=",
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ named!(pub spaces_nl<StrSpan, ()>,
pub fn spaces_nonl(i: StrSpan) -> Result<(StrSpan, ()), ::nom::Err<StrSpan>> {
let mut it = i.fragment.chars().enumerate().peekable();
while let Some((index, c)) = it.next() {
let next_char = it.peek().map(|(_,c)|*c);
let next_char = it.peek().map(|&(_,c)|c);
match c {
' ' | '\t' | '\x0c' => (),
'\\' if next_char.unwrap_or(' ') == '\n' => {it.next();},
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
//! # Example
//!
//! ```
//! extern crate python_parser;
//! use python_parser::ast::*;
//! let code = "print(2 + 3, fd=sys.stderr)";
//! let ast = python_parser::file_input(python_parser::make_strspan(code))
Expand Down
16 changes: 5 additions & 11 deletions src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,13 @@ named!(escapedchar<StrSpan, Option<PyStringCodePoint>>,
unicode_names2::character(&name.iter().collect::<String>()).map(cp_from_char)
}
| preceded!(char!('u'), count!(one_of!("0123456789abcdefABCDEF"), 4)) => { |v: Vec<char>| {
let it: Vec<u32> = v.iter().map(|c| c.to_digit(16).unwrap()).collect();
if let [d1, d2, d3, d4] = &it[..] {
cp_from_u32((d1 << 12) + (d2 << 8) + (d3 << 4) + d4)
}
else { unreachable!() }
let v: Vec<u32> = v.iter().map(|c| c.to_digit(16).unwrap()).collect();
cp_from_u32((v[0] << 12) + (v[1] << 8) + (v[2] << 4) + v[3])
}}
| preceded!(char!('U'), count!(one_of!("0123456789abcdefABCDEF"), 8)) => { |v: Vec<char>| {
let it: Vec<u32> = v.iter().map(|c| c.to_digit(16).unwrap()).collect();
if let [d1, d2, d3, d4, d5, d6, d7, d8] = &it[..] {
cp_from_u32((d1 << 28) + (d2 << 24) + (d3 << 20) + (d4 << 16) +
(d5 << 12) + (d6 << 8) + (d7 << 4) + d8)
}
else { unreachable!() }
let v: Vec<u32> = v.iter().map(|c| c.to_digit(16).unwrap()).collect();
cp_from_u32((v[0] << 28) + (v[1] << 24) + (v[2] << 20) + (v[3] << 16) +
(v[4] << 12) + (v[5] << 8 ) + (v[6] << 4 ) + v[7])
}}
)
)
Expand Down
Loading

0 comments on commit 844ccfd

Please sign in to comment.