mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 03:58:12 +00:00
LibGUI: Parse #include statements separately
This commit is contained in:
parent
b13417ddb4
commit
d8a73dd979
3 changed files with 36 additions and 0 deletions
|
@ -345,8 +345,40 @@ Vector<CppToken> CppLexer::lex()
|
||||||
}
|
}
|
||||||
if (ch == '#') {
|
if (ch == '#') {
|
||||||
begin_token();
|
begin_token();
|
||||||
|
consume();
|
||||||
|
|
||||||
|
if (is_valid_first_character_of_identifier(peek()))
|
||||||
|
while (peek() && is_valid_nonfirst_character_of_identifier(peek()))
|
||||||
|
consume();
|
||||||
|
|
||||||
|
auto directive = StringView(m_input.characters_without_null_termination() + token_start_index, m_index - token_start_index);
|
||||||
|
if (directive == "#include") {
|
||||||
|
commit_token(CppToken::Type::IncludeStatement);
|
||||||
|
|
||||||
|
begin_token();
|
||||||
|
while (isspace(peek()))
|
||||||
|
consume();
|
||||||
|
commit_token(CppToken::Type::Whitespace);
|
||||||
|
|
||||||
|
begin_token();
|
||||||
|
if (peek() == '<' || peek() == '"') {
|
||||||
|
char closing = consume() == '<' ? '>' : '"';
|
||||||
|
while (peek() != closing && peek() != '\n')
|
||||||
|
consume();
|
||||||
|
|
||||||
|
if (consume() == '\n') {
|
||||||
|
commit_token(CppToken::Type::IncludePath);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
commit_token(CppToken::Type::IncludePath);
|
||||||
|
begin_token();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (peek() && peek() != '\n')
|
while (peek() && peek() != '\n')
|
||||||
consume();
|
consume();
|
||||||
|
|
||||||
commit_token(CppToken::Type::PreprocessorStatement);
|
commit_token(CppToken::Type::PreprocessorStatement);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,8 @@ namespace GUI {
|
||||||
__TOKEN(Unknown) \
|
__TOKEN(Unknown) \
|
||||||
__TOKEN(Whitespace) \
|
__TOKEN(Whitespace) \
|
||||||
__TOKEN(PreprocessorStatement) \
|
__TOKEN(PreprocessorStatement) \
|
||||||
|
__TOKEN(IncludeStatement) \
|
||||||
|
__TOKEN(IncludePath) \
|
||||||
__TOKEN(LeftParen) \
|
__TOKEN(LeftParen) \
|
||||||
__TOKEN(RightParen) \
|
__TOKEN(RightParen) \
|
||||||
__TOKEN(LeftCurly) \
|
__TOKEN(LeftCurly) \
|
||||||
|
|
|
@ -23,10 +23,12 @@ static TextStyle style_for_token_type(CppToken::Type type)
|
||||||
case CppToken::Type::SingleQuotedString:
|
case CppToken::Type::SingleQuotedString:
|
||||||
case CppToken::Type::Integer:
|
case CppToken::Type::Integer:
|
||||||
case CppToken::Type::Float:
|
case CppToken::Type::Float:
|
||||||
|
case CppToken::Type::IncludePath:
|
||||||
return { Color::from_rgb(0x800000) };
|
return { Color::from_rgb(0x800000) };
|
||||||
case CppToken::Type::EscapeSequence:
|
case CppToken::Type::EscapeSequence:
|
||||||
return { Color::from_rgb(0x800080), &Gfx::Font::default_bold_fixed_width_font() };
|
return { Color::from_rgb(0x800080), &Gfx::Font::default_bold_fixed_width_font() };
|
||||||
case CppToken::Type::PreprocessorStatement:
|
case CppToken::Type::PreprocessorStatement:
|
||||||
|
case CppToken::Type::IncludeStatement:
|
||||||
return { Color::from_rgb(0x008080) };
|
return { Color::from_rgb(0x008080) };
|
||||||
case CppToken::Type::Comment:
|
case CppToken::Type::Comment:
|
||||||
return { Color::from_rgb(0x008000) };
|
return { Color::from_rgb(0x008000) };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue