Lexer.h 963 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/GenericLexer.h>
  8. #include <AK/Vector.h>
  9. #include <LibCMake/CMakeCache/Token.h>
  10. namespace CMake::Cache {
  11. class Lexer : private GenericLexer {
  12. public:
  13. static ErrorOr<Vector<Token>> lex(StringView input);
  14. private:
  15. Lexer(StringView input);
  16. ErrorOr<Vector<Token>> lex_file();
  17. void skip_whitespace();
  18. void consume_comment();
  19. void consume_help_text();
  20. void consume_variable_definition();
  21. void consume_key();
  22. void consume_colon();
  23. void consume_type();
  24. void consume_equals();
  25. void consume_value();
  26. void consume_garbage();
  27. Position position() const;
  28. void next_line();
  29. void emit_token(Token::Type, StringView value, Position start, Position end);
  30. Vector<Token> m_tokens;
  31. size_t m_line { 0 };
  32. size_t m_string_offset_after_previous_newline { 0 };
  33. };
  34. }