diff options
author | Nadrieril | 2019-02-27 15:36:12 +0100 |
---|---|---|
committer | Nadrieril | 2019-02-27 15:36:12 +0100 |
commit | 8a1012be323459440032813c2b21b62174924c6c (patch) | |
tree | d2a64f401f552106318f2ededd7043f5aefbd92e | |
parent | d5bc8da87f3fed99a010d867a3e34d2768caf768 (diff) |
Revert "Try to update to latest nom"
This reverts commit d5bc8da87f3fed99a010d867a3e34d2768caf768.
Diffstat (limited to '')
-rw-r--r-- | Cargo.lock | 34 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/grammar.lalrpop | 2 | ||||
-rw-r--r-- | src/lexer.rs | 54 | ||||
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/parser.rs | 2 |
6 files changed, 50 insertions, 46 deletions
@@ -101,7 +101,7 @@ dependencies = [ "bytecount 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "lalrpop 0.16.3 (registry+https://github.com/rust-lang/crates.io-index)", "lalrpop-util 0.16.3 (registry+https://github.com/rust-lang/crates.io-index)", - "nom 4.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "term-painter 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -123,7 +123,7 @@ name = "docopt" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", @@ -214,7 +214,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -232,6 +232,14 @@ dependencies = [ [[package]] name = "memchr" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "memchr" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -242,11 +250,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "nom" -version = "4.2.1" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -479,7 +486,7 @@ name = "string_cache" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "new_debug_unreachable 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)", "precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -552,7 +559,7 @@ name = "thread_local" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -576,11 +583,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "version_check" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] name = "winapi" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -637,12 +639,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lalrpop 0.16.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4e2e80bee40b22bca46665b4ef1f3cd88ed0fb043c971407eac17a0712c02572" "checksum lalrpop-util 0.16.3 (registry+https://github.com/rust-lang/crates.io-index)" = "33b27d8490dbe1f9704b0088d61e8d46edc10d5673a8829836c6ded26a9912c7" -"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" +"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)" = "413f3dfc802c5dc91dc570b05125b6cda9855edfaa9825c9849807876376e70e" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" +"checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" "checksum new_debug_unreachable 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f40f005c60db6e03bae699e414c58bf9aa7ea02a2d0b9bfbcf19286cc4c82b30" -"checksum nom 4.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4836e9d6036552017e107edc598c97b2dee245161ff1b1ad4af215004774b354" +"checksum nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05aec50c70fd288702bcd93284a8444607f3292dbdf2a30de5ea5dcdbe72287b" "checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409" "checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" "checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f" @@ -683,7 +686,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" -"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" @@ -10,5 +10,5 @@ lalrpop = "0.16.3" [dependencies] bytecount = "0.5.1" lalrpop-util = "0.16.3" -nom = "4.0.0" +nom = "3.0.0" term-painter = "0.2.3" diff --git a/src/grammar.lalrpop b/src/grammar.lalrpop index 1e4d323..35716fc 100644 --- a/src/grammar.lalrpop +++ b/src/grammar.lalrpop @@ -13,7 +13,7 @@ grammar<'input>; extern { type Location = usize; - type Error = LexicalError<'input>; + type Error = LexicalError; enum Tok<'input> { Pi => Tok::Pi, diff --git a/src/lexer.rs b/src/lexer.rs index 8617f4b..0b58293 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -64,7 +64,10 @@ pub enum Tok<'i> { } #[derive(Debug)] -pub struct LexicalError<'a>(pub usize, pub nom::Err<&'a str>); +pub enum LexicalError { + Error(usize, nom::simple_errors::Err<u32>), + Incomplete(nom::Needed), +} pub type Spanned<Tok, Loc, Error> = Result<(Loc, Tok, Loc), Error>; @@ -106,11 +109,11 @@ named!(identifier<&str, &str>, recognize!(preceded!( macro_rules! ident_tag { ($i:expr, $tag:expr) => { match identifier($i) { - Ok((i, s)) => { + nom::IResult::Done(i, s) => { if s == $tag { - Ok((i, s)) + nom::IResult::Done(i, s) } else { - Err(nom::Err::Error(error_position!($i, nom::ErrorKind::Tag))) + nom::IResult::Error(error_position!(nom::ErrorKind::Tag, $i)) } } r => r, @@ -143,20 +146,20 @@ named!(string_escape_numeric<&str, char>, map_opt!(alt!( ), ::std::char::from_u32)); fn string_lit_inner(input: &str) -> nom::IResult<&str, String> { - use nom::Err; + use nom::IResult::*;; use nom::ErrorKind; let mut s = String::new(); let mut cs = input.char_indices().peekable(); while let Some((i, c)) = cs.next() { match c { - '"' => return Ok((&input[i..], s)), + '"' => return nom::IResult::Done(&input[i..], s), '\\' => match cs.next() { Some((_, s)) if s.is_whitespace() => { while cs.peek().map(|&(_, s)| s.is_whitespace()) == Some(true) { let _ = cs.next(); } if cs.next().map(|p| p.1) != Some('\\') { - return Err(Err::Error(error_position!(input, ErrorKind::Custom(4 /* FIXME */)))); + return Error(error_position!(ErrorKind::Custom(4 /* FIXME */), input)); } } Some((j, ec)) => { @@ -165,23 +168,24 @@ fn string_lit_inner(input: &str) -> nom::IResult<&str, String> { // FIXME Named ASCII escapes and control character escapes } else { match string_escape_numeric(&input[j..]) { - Ok((rest, esc)) => { + Done(rest, esc) => { let &(k, _) = cs.peek().unwrap(); // digits are always single byte ASCII characters let consumed = input[k..].len() - rest.len(); for _ in 0..consumed { let _ = cs.next(); } s.push(esc); } - Err(e) => return Err(e), + Incomplete(s) => return Incomplete(s), + Error(e) => return Error(e), } } }, - _ => return Err(Err::Error(error_position!(input, ErrorKind::Custom(5 /* FIXME */)))), + _ => return Error(error_position!(ErrorKind::Custom(5 /* FIXME */), input)), }, _ => s.push(c), } } - Err(Err::Error(error_position!(input, ErrorKind::Custom(3 /* FIXME */)))) + Error(error_position!(ErrorKind::Custom(3 /* FIXME */), input)) } named!(string_lit<&str, String>, delimited!(tag!("\""), string_lit_inner, tag!("\""))); @@ -318,26 +322,30 @@ impl<'input> Lexer<'input> { } impl<'input> Iterator for Lexer<'input> { - type Item = Spanned<Tok<'input>, usize, LexicalError<'input>>; + type Item = Spanned<Tok<'input>, usize, LexicalError>; fn next(&mut self) -> Option<Self::Item> { + use nom::IResult::*; self.skip_comments_and_whitespace(); let input = self.current_input(); if input.is_empty() { return None; } match token(input) { - Ok((rest, t)) => { + Done(rest, t) => { let parsed_len = input.len() - rest.len(); //println!("parsed {} bytes => {:?}", parsed_len, t); let start = self.offset; self.offset += parsed_len; Some(Ok((start, t, self.offset))) } - Err(e) => { + Error(e) => { let offset = self.offset; - // self.offset = self.input.len(); - Some(Err(LexicalError(offset, e))) + self.offset = self.input.len(); + Some(Err(LexicalError::Error(offset, e))) + } + Incomplete(needed) => { + Some(Err(LexicalError::Incomplete(needed))) } } } @@ -346,12 +354,6 @@ impl<'input> Iterator for Lexer<'input> { #[test] fn test_lex() { use self::Tok::*; - let s = "22"; - let expected = [Lambda, Bool(false)]; - let lexer = Lexer::new(s); - let tokens = lexer.map(|r| r.unwrap().1).collect::<Vec<_>>(); - assert_eq!(&tokens, &expected); - let s = "λ(b : Bool) → b == False"; let expected = [Lambda, ParenL, @@ -367,9 +369,9 @@ fn test_lex() { let tokens = lexer.map(|r| r.unwrap().1).collect::<Vec<_>>(); assert_eq!(&tokens, &expected); - assert_eq!(string_lit(r#""a\&b""#), Ok(("", "ab".to_owned()))); - assert_eq!(string_lit(r#""a\ \b""#), Ok(("", "ab".to_owned()))); + assert_eq!(string_lit(r#""a\&b""#).to_result(), Ok("ab".to_owned())); + assert_eq!(string_lit(r#""a\ \b""#).to_result(), Ok("ab".to_owned())); assert!(string_lit(r#""a\ b""#).is_err()); - assert_eq!(string_lit(r#""a\nb""#), Ok(("", "a\nb".to_owned()))); - assert_eq!(string_lit(r#""\o141\x62\99""#), Ok(("", "abd".to_owned()))); + assert_eq!(string_lit(r#""a\nb""#).to_result(), Ok("a\nb".to_owned())); + assert_eq!(string_lit(r#""\o141\x62\99""#).to_result(), Ok("abc".to_owned())); } diff --git a/src/main.rs b/src/main.rs index 2a1eb11..fde3978 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,7 +71,7 @@ fn main() { io::stdin().read_to_string(&mut buffer).unwrap(); let expr = match parser::parse_expr(&buffer) { Ok(e) => e, - Err(lalrpop_util::ParseError::User { error: lexer::LexicalError(pos, e) }) => { + Err(lalrpop_util::ParseError::User { error: lexer::LexicalError::Error(pos, e) }) => { print_error(&format!("Unexpected token {:?}", e), &buffer, pos, pos); return; } diff --git a/src/parser.rs b/src/parser.rs index 1127d86..3ad7ffc 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -4,7 +4,7 @@ use grammar; use grammar_util::BoxExpr; use lexer::{Lexer, LexicalError, Tok}; -pub type ParseError<'i> = lalrpop_util::ParseError<usize, Tok<'i>, LexicalError<'i>>; +pub type ParseError<'i> = lalrpop_util::ParseError<usize, Tok<'i>, LexicalError>; pub fn parse_expr(s: &str) -> Result<BoxExpr, ParseError> { grammar::ExprParser::new().parse(Lexer::new(s)) |