mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 04:07:46 +00:00
LibCMake: Introduce a CMake lexer
This commit is contained in:
parent
ca4cc03269
commit
3d8cc2257f
8 changed files with 581 additions and 0 deletions
51
Userland/Libraries/LibCMake/Lexer.h
Normal file
51
Userland/Libraries/LibCMake/Lexer.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/GenericLexer.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCMake/Token.h>
|
||||
|
||||
namespace CMake {
|
||||
|
||||
class Lexer : private GenericLexer {
|
||||
public:
|
||||
static ErrorOr<Vector<Token>> lex(StringView input);
|
||||
|
||||
private:
|
||||
Lexer(StringView input);
|
||||
|
||||
ErrorOr<Vector<Token>> lex_file();
|
||||
|
||||
void skip_whitespace();
|
||||
|
||||
void consume_whitespace_or_comments();
|
||||
void consume_command_invocation();
|
||||
void consume_arguments();
|
||||
void consume_argument();
|
||||
void consume_bracket_argument();
|
||||
void consume_quoted_argument();
|
||||
void consume_unquoted_argument();
|
||||
void consume_comment();
|
||||
void consume_open_paren();
|
||||
void consume_close_paren();
|
||||
void consume_garbage();
|
||||
|
||||
StringView read_bracket_argument();
|
||||
static Vector<VariableReference> parse_variable_references_from_argument(StringView argument_value, Position argument_start);
|
||||
|
||||
Position position() const;
|
||||
void next_line();
|
||||
|
||||
void emit_token(Token::Type, StringView value, Position start, Position end, Optional<ControlKeywordType> = {}, Vector<VariableReference> = {});
|
||||
|
||||
Vector<Token> m_tokens;
|
||||
size_t m_line { 0 };
|
||||
size_t m_string_offset_after_previous_newline { 0 };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue