Skip to content

Commit

Permalink
Partial validation when setting selection on PN
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDTill committed Aug 5, 2023
1 parent 192ef14 commit b6c77a1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion meta/ast_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def main():
source_file.write(
f"void ParseTree::{setter}(ParseNode pn, {T} {field.property}) noexcept {{\n")
if field.property == "selection":
source_file.write(" //assert(selection.inValidState()); //DO THIS\n")
source_file.write(" assert(selection.inValidState(false));\n")
source_file.write(
" assert(isNode(pn));\n"
f" {ref} = {field.property};\n"
Expand Down
9 changes: 6 additions & 3 deletions src/typeset_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ std::array<double, 4> Selection::getDimensionsLines() const noexcept {
#endif

#ifndef NDEBUG
bool Selection::inValidState() const noexcept {
bool Selection::inValidState(bool require_markers_on_same_level) const noexcept {
if(!left.inValidState()){
std::cout << "Left marker invalid" << std::endl;
return false;
Expand All @@ -509,7 +509,7 @@ bool Selection::inValidState() const noexcept {
return false;
}

if(left.phrase() != right.phrase() && (left.isNested() || right.isNested())){
if(require_markers_on_same_level && left.phrase() != right.phrase() && (left.isNested() || right.isNested())){
std::cout << "Markers are not on same level" << std::endl;
return false;
}
Expand All @@ -523,8 +523,11 @@ bool Selection::inValidState() const noexcept {
}
}else if(isPhraseSelection()){
return tR->id > tL->id;
}else{
}else if(!left.isNested() && !right.isNested()){
return lR->id > lL->id;
}else{
assert(!require_markers_on_same_level);
return left.precedesInclusive(right);
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/typeset_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Selection{
#endif

#ifndef NDEBUG
bool inValidState() const noexcept;
bool inValidState(bool require_markers_on_same_level = true) const noexcept;
#endif

#ifdef QT_CORE_LIB
Expand Down

0 comments on commit b6c77a1

Please sign in to comment.