Lexer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/Token.h>
  10. namespace CMake {
  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_whitespace_or_comments();
  19. void consume_command_invocation();
  20. void consume_arguments();
  21. void consume_argument();
  22. void consume_bracket_argument();
  23. void consume_quoted_argument();
  24. void consume_unquoted_argument();
  25. void consume_comment();
  26. void consume_open_paren();
  27. void consume_close_paren();
  28. void consume_garbage();
  29. StringView read_bracket_argument();
  30. static Vector<VariableReference> parse_variable_references_from_argument(StringView argument_value, Position argument_start);
  31. Position position() const;
  32. void next_line();
  33. void emit_token(Token::Type, StringView value, Position start, Position end, Optional<ControlKeywordType> = {}, Vector<VariableReference> = {});
  34. Vector<Token> m_tokens;
  35. size_t m_line { 0 };
  36. size_t m_string_offset_after_previous_newline { 0 };
  37. };
  38. }