Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions cfgrammar/src/lib/markmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,48 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
Ok(())
}

/// Similar to `merge_from` except the `MergeBehavior` of self is used when merging into `*other*`.
#[doc(hidden)]
pub fn merge_into(mut self, other: &'_ mut Self) -> Result<(), MergeError<K, Box<V>>> {
for (src_key, src_mark, src_val) in self.contents.drain(..) {
let pos = other.contents.binary_search_by(|x| x.0.cmp(&src_key));
match pos {
Ok(pos) => {
let (_, dest_mark, dest_val) = &mut other.contents[pos];
let theirs_mark = Mark::MergeBehavior(MergeBehavior::Theirs).repr();
let ours_mark = Mark::MergeBehavior(MergeBehavior::Ours).repr();
let exclusive_mark =
Mark::MergeBehavior(MergeBehavior::MutuallyExclusive).repr();
let merge_behavior = (src_mark & exclusive_mark)
| (src_mark & ours_mark)
| (src_mark & theirs_mark);
if merge_behavior == exclusive_mark || merge_behavior == 0 {
// If only clippy could convince me and the borrow checker this is actually unnecessary.
#[allow(clippy::unnecessary_unwrap)]
if src_val.is_some() && dest_val.is_some() {
return Err(MergeError::Exclusivity(
src_key,
Box::new(src_val.unwrap()),
));
} else if dest_val.is_none() {
*dest_val = src_val;
}
} else if merge_behavior == ours_mark && src_val.is_some()
|| merge_behavior == theirs_mark && dest_val.is_none()
{
*dest_mark = src_mark;
*dest_val = src_val;
}
}
Err(pos) => {
other.contents
.insert(pos, (src_key, src_mark, src_val));
}
}
}
Ok(())
}

/// Returns whether `key` has been marked as used.
#[doc(hidden)]
pub fn is_used<Q>(&self, key: &Q) -> bool
Expand Down
22 changes: 0 additions & 22 deletions cfgrammar/src/lib/yacc/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ pub enum YaccGrammarErrorKind {
UnknownEPP(String),
ExpectedInput(char),
InvalidYaccKind,
InvalidYaccKindNamespace,
InvalidActionKind,
InvalidActionKindNamespace,
InvalidGrmtoolsSectionEntry,
DuplicateGrmtoolsSectionEntry,
MissingGrmtoolsSection,
}

/// Any error from the Yacc parser returns an instance of this struct.
Expand Down Expand Up @@ -184,17 +178,7 @@ impl fmt::Display for YaccGrammarErrorKind {
name
)
}
YaccGrammarErrorKind::MissingGrmtoolsSection => "Missing '%grmtools' section",
YaccGrammarErrorKind::DuplicateGrmtoolsSectionEntry => {
"Duplicate entry in %grmtools section"
}
YaccGrammarErrorKind::InvalidGrmtoolsSectionEntry => {
"Invalid entry in %grmtools section"
}
YaccGrammarErrorKind::InvalidYaccKind => "Invalid yacc kind",
YaccGrammarErrorKind::InvalidYaccKindNamespace => "Invalid yacc kind namespace",
YaccGrammarErrorKind::InvalidActionKind => "Invalid action kind",
YaccGrammarErrorKind::InvalidActionKindNamespace => "Invalid action kind namespace",
};
write!(f, "{}", s)
}
Expand Down Expand Up @@ -303,12 +287,7 @@ impl Spanned for YaccGrammarError {
| YaccGrammarErrorKind::UnknownRuleRef(_)
| YaccGrammarErrorKind::UnknownToken(_)
| YaccGrammarErrorKind::NoPrecForToken(_)
| YaccGrammarErrorKind::MissingGrmtoolsSection
| YaccGrammarErrorKind::InvalidGrmtoolsSectionEntry
| YaccGrammarErrorKind::InvalidYaccKind
| YaccGrammarErrorKind::InvalidYaccKindNamespace
| YaccGrammarErrorKind::InvalidActionKind
| YaccGrammarErrorKind::InvalidActionKindNamespace
| YaccGrammarErrorKind::ExpectedInput(_)
| YaccGrammarErrorKind::UnknownEPP(_) => SpansKind::Error,
YaccGrammarErrorKind::DuplicatePrecedence
Expand All @@ -318,7 +297,6 @@ impl Spanned for YaccGrammarError {
| YaccGrammarErrorKind::DuplicateImplicitTokensDeclaration
| YaccGrammarErrorKind::DuplicateStartDeclaration
| YaccGrammarErrorKind::DuplicateActiontypeDeclaration
| YaccGrammarErrorKind::DuplicateGrmtoolsSectionEntry
| YaccGrammarErrorKind::DuplicateEPP => SpansKind::DuplicationError,
}
}
Expand Down
Loading