summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKshitij Bansal <kshitij@cs.nyu.edu>2014-07-10 13:05:45 -0400
committerKshitij Bansal <kshitij@cs.nyu.edu>2014-07-10 13:05:45 -0400
commit2cfbaa1de281ce0b85e2c7a6d058a05d940f5aaf (patch)
tree26c097f0ecb380b38c805b141e84292d1e7f0c89 /src
parent211304a663417c69552ea9efc43aaef855d7cd70 (diff)
reorganize friendlyparser, behavior unchanged
Diffstat (limited to 'src')
-rw-r--r--src/parser/antlr_input.cpp50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/parser/antlr_input.cpp b/src/parser/antlr_input.cpp
index ca8f805b4..d72b311cb 100644
--- a/src/parser/antlr_input.cpp
+++ b/src/parser/antlr_input.cpp
@@ -400,32 +400,38 @@ std::string parseErrorHelper(const char* lineStart, int charPositionInLine, cons
}
}
} else {
- // go to nearest alphanumeric string (before current position),
- // see if that word can be found in original message. If so,
- // point to that, else keep pointer where it was.
- int nearestWordEn = caretPos - 1;
- while(nearestWordEn > 0 && !isSimpleChar(slice[nearestWordEn])) {
- --nearestWordEn;
- }
- if(isSimpleChar(slice[nearestWordEn])) {
- int nearestWordSt = nearestWordEn;
- while(nearestWordSt > 0 && isSimpleChar(slice[nearestWordSt - 1])) {
- --nearestWordSt;
+ bool foundCaretPos = false;
+
+ for(int tries = 0; tries < 1 && caretPos > 0 && !foundCaretPos; ++tries) {
+ // go to nearest alphanumeric string (before current position),
+ // see if that word can be found in original message. If so,
+ // point to that, else keep pointer where it was.
+ int nearestWordEn = caretPos - 1;
+ while(nearestWordEn > 0 && !isSimpleChar(slice[nearestWordEn])) {
+ --nearestWordEn;
}
- string word = slice.substr(nearestWordSt, (nearestWordEn - nearestWordSt + 1));
- size_t matchLoc = wholeWordMatch(message, word, isSimpleChar);
- Debug("friendlyparser") << "[friendlyparser] nearest word = " << word << std::endl;
- Debug("friendlyparser") << "[friendlyparser] matchLoc = " << matchLoc << endl;
- if( matchLoc != string::npos ) {
- Debug("friendlyparser") << "[friendlyparser] strong evidence that caret should be at "
- << nearestWordSt << std::endl;
+ if(isSimpleChar(slice[nearestWordEn])) {
+ int nearestWordSt = nearestWordEn;
+ while(nearestWordSt > 0 && isSimpleChar(slice[nearestWordSt - 1])) {
+ --nearestWordSt;
+ }
+ string word = slice.substr(nearestWordSt, (nearestWordEn - nearestWordSt + 1));
+ size_t matchLoc = wholeWordMatch(message, word, isSimpleChar);
+ Debug("friendlyparser") << "[friendlyparser] nearest word = " << word << std::endl;
+ Debug("friendlyparser") << "[friendlyparser] matchLoc = " << matchLoc << endl;
+ if( matchLoc != string::npos ) {
+ Debug("friendlyparser") << "[friendlyparser] strong evidence that caret should be at "
+ << nearestWordSt << std::endl;
+ foundCaretPos = true;
+ }
caretPos = nearestWordSt;
- } else {
- // this doesn't look good. caret generally getting printed
- // at unhelpful positions. improve upstream?
- return message;
}
}
+ if( !foundCaretPos) {
+ // this doesn't look good. caret generally getting printed
+ // at unhelpful positions. improve upstream?
+ return message;
+ }
}
caretPos += caretPosExtra;
}// end of caret position computation/heuristics
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback