MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / addErrorHighlighting

Function addErrorHighlighting

tools/shell/linenoise.cpp:1665–1857  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1663}
1664
1665void addErrorHighlighting(uint64_t render_start, uint64_t render_end,
1666 std::vector<highlightToken>& tokens, struct linenoiseState* l) {
1667 enum class ScanState {
1668 STANDARD,
1669 IN_SINGLE_QUOTE,
1670 IN_DOUBLE_QUOTE,
1671 IN_COMMENT,
1672 IN_MULTILINE_COMMENT
1673 };
1674
1675 static constexpr const uint64_t MAX_ERROR_LENGTH = 2000;
1676 if (l->len >= MAX_ERROR_LENGTH) {
1677 return;
1678 }
1679 // do a pass over the buffer to collect errors:
1680 // * brackets without matching closing/opening bracket
1681 // * single quotes without matching closing single quote
1682 // * double quote without matching double quote
1683 ScanState state = ScanState::STANDARD;
1684 std::vector<uint64_t> brackets; // ()
1685 std::vector<uint64_t> square_brackets; // []
1686 std::vector<uint64_t> curly_brackets; // {}
1687 std::vector<uint64_t> errors;
1688 std::vector<uint64_t> cursor_brackets;
1689 std::vector<uint64_t> comment_start;
1690 std::vector<uint64_t> comment_end;
1691 std::string dollar_quote_marker;
1692 uint64_t quote_pos = 0;
1693 for (uint64_t i = 0; i < l->len; i++) {
1694 auto c = l->buf[i];
1695 switch (state) {
1696 case ScanState::STANDARD:
1697 switch (c) {
1698 case '/':
1699 if (i + 1 < l->len && l->buf[i + 1] == '/') {
1700 // // puts us in a comment
1701 comment_start.push_back(i);
1702 i++;
1703 state = ScanState::IN_COMMENT;
1704 } else if (i + 1 < l->len && l->buf[i + 1] == '*') {
1705 // /* puts us in a multiline comment
1706 comment_start.push_back(i);
1707 i++;
1708 state = ScanState::IN_MULTILINE_COMMENT;
1709 }
1710 break;
1711 case '\'':
1712 state = ScanState::IN_SINGLE_QUOTE;
1713 quote_pos = i;
1714 break;
1715 case '\"':
1716 state = ScanState::IN_DOUBLE_QUOTE;
1717 quote_pos = i;
1718 break;
1719 case '(':
1720 openBracket(brackets, cursor_brackets, l->pos, i);
1721 break;
1722 case '[':

Callers 1

refreshMultiLineFunction · 0.85

Calls 9

openBracketFunction · 0.85
closeBracketFunction · 0.85
HandleBracketErrorsFunction · 0.85
insertTokenFunction · 0.85
push_backMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected