mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
LibGUI: Fix off-by-one error in Lexer tokens
This changes the INI and GML lexers to conform to the now-fixed rendering of syntax highlighting spans in GUI::TextEditor. The other user of GMLToken::m_end, GMLAutocompleteProvider, has been modified to take into account that end position columns have been incremented by one.
This commit is contained in:
parent
e7b5dbe1ac
commit
cb5a50d3f7
5 changed files with 6 additions and 10 deletions
|
@ -107,7 +107,7 @@ void GMLAutocompleteProvider::provide_completions(Function<void(Vector<Entry>)>
|
||||||
Vector<GUI::AutocompleteProvider::Entry> class_entries, identifier_entries;
|
Vector<GUI::AutocompleteProvider::Entry> class_entries, identifier_entries;
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case Free:
|
case Free:
|
||||||
if (last_seen_token && last_seen_token->m_end.column + 1 != cursor.column() && last_seen_token->m_end.line == cursor.line()) {
|
if (last_seen_token && last_seen_token->m_end.column != cursor.column() && last_seen_token->m_end.line == cursor.line()) {
|
||||||
// After some token, but with extra space, not on a new line.
|
// After some token, but with extra space, not on a new line.
|
||||||
// Nothing to put here.
|
// Nothing to put here.
|
||||||
break;
|
break;
|
||||||
|
@ -121,7 +121,7 @@ void GMLAutocompleteProvider::provide_completions(Function<void(Vector<Entry>)>
|
||||||
case InClassName:
|
case InClassName:
|
||||||
if (class_names.is_empty())
|
if (class_names.is_empty())
|
||||||
break;
|
break;
|
||||||
if (last_seen_token && last_seen_token->m_end.column + 1 != cursor.column() && last_seen_token->m_end.line == cursor.line()) {
|
if (last_seen_token && last_seen_token->m_end.column != cursor.column() && last_seen_token->m_end.line == cursor.line()) {
|
||||||
// After a class name, but haven't seen braces.
|
// After a class name, but haven't seen braces.
|
||||||
// TODO: Suggest braces?
|
// TODO: Suggest braces?
|
||||||
break;
|
break;
|
||||||
|
@ -136,7 +136,7 @@ void GMLAutocompleteProvider::provide_completions(Function<void(Vector<Entry>)>
|
||||||
case InIdentifier: {
|
case InIdentifier: {
|
||||||
if (class_names.is_empty())
|
if (class_names.is_empty())
|
||||||
break;
|
break;
|
||||||
if (last_seen_token && last_seen_token->m_end.column + 1 != cursor.column() && last_seen_token->m_end.line == cursor.line()) {
|
if (last_seen_token && last_seen_token->m_end.column != cursor.column() && last_seen_token->m_end.line == cursor.line()) {
|
||||||
// After an identifier, but with extra space
|
// After an identifier, but with extra space
|
||||||
// TODO: Maybe suggest a colon?
|
// TODO: Maybe suggest a colon?
|
||||||
break;
|
break;
|
||||||
|
@ -158,7 +158,7 @@ void GMLAutocompleteProvider::provide_completions(Function<void(Vector<Entry>)>
|
||||||
}
|
}
|
||||||
case AfterClassName: {
|
case AfterClassName: {
|
||||||
if (last_seen_token && last_seen_token->m_end.line == cursor.line()) {
|
if (last_seen_token && last_seen_token->m_end.line == cursor.line()) {
|
||||||
if (last_seen_token->m_type != GUI::GMLToken::Type::Identifier || last_seen_token->m_end.column + 1 != cursor.column()) {
|
if (last_seen_token->m_type != GUI::GMLToken::Type::Identifier || last_seen_token->m_end.column != cursor.column()) {
|
||||||
// Inside braces, but on the same line as some other stuff (and not the continuation of one!)
|
// Inside braces, but on the same line as some other stuff (and not the continuation of one!)
|
||||||
// The user expects nothing here.
|
// The user expects nothing here.
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -26,7 +26,6 @@ char GMLLexer::consume()
|
||||||
{
|
{
|
||||||
VERIFY(m_index < m_input.length());
|
VERIFY(m_index < m_input.length());
|
||||||
char ch = m_input[m_index++];
|
char ch = m_input[m_index++];
|
||||||
m_previous_position = m_position;
|
|
||||||
if (ch == '\n') {
|
if (ch == '\n') {
|
||||||
m_position.line++;
|
m_position.line++;
|
||||||
m_position.column = 0;
|
m_position.column = 0;
|
||||||
|
@ -68,7 +67,7 @@ Vector<GMLToken> GMLLexer::lex()
|
||||||
token.m_view = m_input.substring_view(token_start_index, m_index - token_start_index);
|
token.m_view = m_input.substring_view(token_start_index, m_index - token_start_index);
|
||||||
token.m_type = type;
|
token.m_type = type;
|
||||||
token.m_start = token_start_position;
|
token.m_start = token_start_position;
|
||||||
token.m_end = m_previous_position;
|
token.m_end = m_position;
|
||||||
tokens.append(token);
|
tokens.append(token);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,6 @@ private:
|
||||||
|
|
||||||
StringView m_input;
|
StringView m_input;
|
||||||
size_t m_index { 0 };
|
size_t m_index { 0 };
|
||||||
GMLPosition m_previous_position { 0, 0 };
|
|
||||||
GMLPosition m_position { 0, 0 };
|
GMLPosition m_position { 0, 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ char IniLexer::consume()
|
||||||
{
|
{
|
||||||
VERIFY(m_index < m_input.length());
|
VERIFY(m_index < m_input.length());
|
||||||
char ch = m_input[m_index++];
|
char ch = m_input[m_index++];
|
||||||
m_previous_position = m_position;
|
|
||||||
if (ch == '\n') {
|
if (ch == '\n') {
|
||||||
m_position.line++;
|
m_position.line++;
|
||||||
m_position.column = 0;
|
m_position.column = 0;
|
||||||
|
@ -47,9 +46,9 @@ Vector<IniToken> IniLexer::lex()
|
||||||
IniToken token;
|
IniToken token;
|
||||||
token.m_type = type;
|
token.m_type = type;
|
||||||
token.m_start = m_position;
|
token.m_start = m_position;
|
||||||
|
consume();
|
||||||
token.m_end = m_position;
|
token.m_end = m_position;
|
||||||
tokens.append(token);
|
tokens.append(token);
|
||||||
consume();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto begin_token = [&] {
|
auto begin_token = [&] {
|
||||||
|
|
|
@ -62,7 +62,6 @@ private:
|
||||||
|
|
||||||
StringView m_input;
|
StringView m_input;
|
||||||
size_t m_index { 0 };
|
size_t m_index { 0 };
|
||||||
IniPosition m_previous_position { 0, 0 };
|
|
||||||
IniPosition m_position { 0, 0 };
|
IniPosition m_position { 0, 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue