Token.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "Token.h"
  7. namespace CMake {
  8. Optional<ControlKeywordType> control_keyword_from_string(StringView value)
  9. {
  10. if (value.equals_ignoring_ascii_case("if"sv))
  11. return ControlKeywordType::If;
  12. if (value.equals_ignoring_ascii_case("elseif"sv))
  13. return ControlKeywordType::ElseIf;
  14. if (value.equals_ignoring_ascii_case("else"sv))
  15. return ControlKeywordType::Else;
  16. if (value.equals_ignoring_ascii_case("endif"sv))
  17. return ControlKeywordType::EndIf;
  18. if (value.equals_ignoring_ascii_case("foreach"sv))
  19. return ControlKeywordType::ForEach;
  20. if (value.equals_ignoring_ascii_case("endforeach"sv))
  21. return ControlKeywordType::EndForEach;
  22. if (value.equals_ignoring_ascii_case("while"sv))
  23. return ControlKeywordType::While;
  24. if (value.equals_ignoring_ascii_case("endwhile"sv))
  25. return ControlKeywordType::EndWhile;
  26. if (value.equals_ignoring_ascii_case("break"sv))
  27. return ControlKeywordType::Break;
  28. if (value.equals_ignoring_ascii_case("continue"sv))
  29. return ControlKeywordType::Continue;
  30. if (value.equals_ignoring_ascii_case("return"sv))
  31. return ControlKeywordType::Return;
  32. if (value.equals_ignoring_ascii_case("macro"sv))
  33. return ControlKeywordType::Macro;
  34. if (value.equals_ignoring_ascii_case("endmacro"sv))
  35. return ControlKeywordType::EndMacro;
  36. if (value.equals_ignoring_ascii_case("function"sv))
  37. return ControlKeywordType::Function;
  38. if (value.equals_ignoring_ascii_case("endfunction"sv))
  39. return ControlKeywordType::EndFunction;
  40. if (value.equals_ignoring_ascii_case("block"sv))
  41. return ControlKeywordType::Block;
  42. if (value.equals_ignoring_ascii_case("endblock"sv))
  43. return ControlKeywordType::EndBlock;
  44. return {};
  45. }
  46. }