mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-16 17:00:53 +00:00
rather than the hacky Debug impl, just only compare stuff that is more
stable (and more imp't anyway)
This commit is contained in:
parent
8dd121a8e7
commit
048def7654
@ -4,7 +4,6 @@
|
||||
* representation incrementally.
|
||||
*/
|
||||
|
||||
use std::cmp::Ord;
|
||||
use intern::InternedString;
|
||||
use grammar::parse_tree::Span;
|
||||
use std::collections::HashMap;
|
||||
@ -48,7 +47,7 @@ pub enum TypeRepr {
|
||||
Lifetime(InternedString),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Types {
|
||||
terminal_type: TypeRepr,
|
||||
nonterminal_types: HashMap<InternedString, TypeRepr>
|
||||
@ -77,23 +76,6 @@ impl Types {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct DummyTypes<'a> {
|
||||
terminal_type: &'a TypeRepr,
|
||||
nonterminal_types: Vec<(&'a InternedString, &'a TypeRepr)>,
|
||||
}
|
||||
|
||||
impl Debug for Types {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
||||
let mut nonterminal_types: Vec<_> = self.nonterminal_types.iter()
|
||||
.collect();
|
||||
nonterminal_types.sort_by(|k1, k2| Ord::cmp(&k1.0, &k2.0));
|
||||
let dummy = DummyTypes { terminal_type: &self.terminal_type,
|
||||
nonterminal_types: nonterminal_types };
|
||||
Debug::fmt(&dummy, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for TypeRepr {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
||||
match *self {
|
||||
|
@ -16,37 +16,26 @@ grammar Foo {
|
||||
}
|
||||
").unwrap();
|
||||
let actual = normalize(grammar).unwrap();
|
||||
expect_debug(actual,
|
||||
r#"Grammar {
|
||||
action_fn_defns: [
|
||||
fn _(__0: Vec<Tok>) -> Vec<Tok> { (__0) },
|
||||
fn _(v: std::vec::Vec<Tok>, e: std::option::Option<Tok>) -> Vec<Tok> { v.into_iter().chain(e.into_iter()).collect() },
|
||||
fn _(__0: Tok) -> std::option::Option<Tok> { Some(__0) },
|
||||
fn _() -> std::option::Option<Tok> { None },
|
||||
fn _() -> std::vec::Vec<Tok> { vec![] },
|
||||
fn _(v: std::vec::Vec<Tok>, e: Tok) -> std::vec::Vec<Tok> { { let mut v = v; v.push(e); v } },
|
||||
fn _(__0: Tok, _: Tok) -> Tok { (__0) }
|
||||
],
|
||||
productions: [
|
||||
Ids = Comma<"Id"> => ActionFn(0);,
|
||||
Comma<"Id"> = (~"Id" ",")*, "Id"? => ActionFn(1);,
|
||||
"Id"? = "Id" => ActionFn(2);,
|
||||
"Id"? = => ActionFn(3);,
|
||||
(~"Id" ",")* = => ActionFn(4);,
|
||||
(~"Id" ",")* = (~"Id" ",")*, (~"Id" ",") => ActionFn(5);,
|
||||
(~"Id" ",") = "Id", "," => ActionFn(6);
|
||||
],
|
||||
conversions: {},
|
||||
types: DummyTypes {
|
||||
terminal_type: Tok,
|
||||
nonterminal_types: [
|
||||
("\"Id\"?", std::option::Option<Tok>),
|
||||
("(~\"Id\" \",\")", Tok),
|
||||
("(~\"Id\" \",\")*", std::vec::Vec<Tok>),
|
||||
("Comma<\"Id\">", Vec<Tok>),
|
||||
("Ids", Vec<Tok>)
|
||||
]
|
||||
}
|
||||
}"#)
|
||||
|
||||
expect_debug(&actual.productions,
|
||||
r#"[
|
||||
Ids = Comma<"Id"> => ActionFn(0);,
|
||||
Comma<"Id"> = (~"Id" ",")*, "Id"? => ActionFn(1);,
|
||||
"Id"? = "Id" => ActionFn(2);,
|
||||
"Id"? = => ActionFn(3);,
|
||||
(~"Id" ",")* = => ActionFn(4);,
|
||||
(~"Id" ",")* = (~"Id" ",")*, (~"Id" ",") => ActionFn(5);,
|
||||
(~"Id" ",") = "Id", "," => ActionFn(6);
|
||||
]"#);
|
||||
|
||||
expect_debug(&actual.action_fn_defns,
|
||||
r#"[
|
||||
fn _(__0: Vec<Tok>) -> Vec<Tok> { (__0) },
|
||||
fn _(v: std::vec::Vec<Tok>, e: std::option::Option<Tok>) -> Vec<Tok> { v.into_iter().chain(e.into_iter()).collect() },
|
||||
fn _(__0: Tok) -> std::option::Option<Tok> { Some(__0) },
|
||||
fn _() -> std::option::Option<Tok> { None },
|
||||
fn _() -> std::vec::Vec<Tok> { vec![] },
|
||||
fn _(v: std::vec::Vec<Tok>, e: Tok) -> std::vec::Vec<Tok> { { let mut v = v; v.push(e); v } },
|
||||
fn _(__0: Tok, _: Tok) -> Tok { (__0) }
|
||||
]"#);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user