Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Commit

Permalink
derive eq and partial eq for parse/highlight state
Browse files Browse the repository at this point in the history
  • Loading branch information
TyOverby committed Jul 11, 2016
1 parent 9a6915c commit 6e9ccb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/parsing/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ use fnv::FnvHasher;
///
/// **Note:** Caching is for advanced users who have tons of time to maximize performance or want to do so eventually.
/// It is not recommended that you try caching the first time you implement highlighting.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseState {
stack: Vec<StateLevel>,
first_line: bool,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
struct StateLevel {
context: ContextPtr,
prototype: Option<ContextPtr>,
Expand Down
21 changes: 15 additions & 6 deletions src/parsing/syntax_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub type ContextPtr = Rc<RefCell<Context>>;
/// Some useful public fields are the `name` field which is a human readable
/// name to display in syntax lists, and the `hidden` field which means hide
/// this syntax from any lists because it is for internal use.
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, Eq, PartialEq)]
pub struct SyntaxDefinition {
pub name: String,
pub file_extensions: Vec<String>,
Expand All @@ -35,7 +35,7 @@ pub struct SyntaxDefinition {
pub contexts: HashMap<String, ContextPtr>,
}

#[derive(Debug, RustcEncodable, RustcDecodable)]
#[derive(Debug, RustcEncodable, RustcDecodable, Eq, PartialEq)]
pub struct Context {
pub meta_scope: Vec<Scope>,
pub meta_content_scope: Vec<Scope>,
Expand All @@ -51,7 +51,7 @@ pub struct Context {
pub patterns: Vec<Pattern>,
}

#[derive(Debug, RustcEncodable, RustcDecodable)]
#[derive(Debug, RustcEncodable, RustcDecodable, Eq, PartialEq)]
pub enum Pattern {
Match(MatchPattern),
Include(ContextReference),
Expand All @@ -66,7 +66,7 @@ pub struct MatchIter {
index_stack: Vec<usize>,
}

#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct MatchPattern {
pub has_captures: bool,
pub regex_str: String,
Expand All @@ -84,7 +84,7 @@ pub struct LinkerLink {
pub link: Weak<RefCell<Context>>,
}

#[derive(Debug, RustcEncodable, RustcDecodable)]
#[derive(Debug, RustcEncodable, RustcDecodable, Eq, PartialEq)]
pub enum ContextReference {
Named(String),
ByScope {
Expand All @@ -99,7 +99,7 @@ pub enum ContextReference {
Direct(LinkerLink),
}

#[derive(Debug, RustcEncodable, RustcDecodable)]
#[derive(Debug, RustcEncodable, RustcDecodable, Eq, PartialEq)]
pub enum MatchOperation {
Push(Vec<ContextReference>),
Set(Vec<ContextReference>),
Expand Down Expand Up @@ -276,6 +276,15 @@ impl Decodable for MatchPattern {
}
}

impl Eq for LinkerLink {}

impl PartialEq for LinkerLink {
fn eq(&self, other: &LinkerLink) -> bool {
self.link.upgrade() == other.link.upgrade()
}
}


/// Just panics, we can't do anything with linked up syntaxes
impl Encodable for LinkerLink {
fn encode<S: Encoder>(&self, _: &mut S) -> Result<(), S::Error> {
Expand Down

0 comments on commit 6e9ccb9

Please sign in to comment.