2020-05-01 02:28:58 +03:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-01 02:28:58 +03:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-01-10 22:57:32 +00:00
|
|
|
|
#include <AK/Utf8View.h>
|
2020-05-01 02:28:58 +03:00
|
|
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
|
|
#define FOR_EACH_TOKEN_TYPE \
|
|
|
|
|
__TOKEN(Unknown) \
|
|
|
|
|
__TOKEN(Comment) \
|
|
|
|
|
__TOKEN(Whitespace) \
|
2021-12-30 13:43:45 +01:00
|
|
|
|
__TOKEN(Section) \
|
2020-05-01 02:28:58 +03:00
|
|
|
|
__TOKEN(LeftBracket) \
|
|
|
|
|
__TOKEN(RightBracket) \
|
|
|
|
|
__TOKEN(Name) \
|
|
|
|
|
__TOKEN(Value) \
|
|
|
|
|
__TOKEN(Equal)
|
|
|
|
|
|
|
|
|
|
struct IniPosition {
|
|
|
|
|
size_t line;
|
|
|
|
|
size_t column;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct IniToken {
|
|
|
|
|
enum class Type {
|
|
|
|
|
#define __TOKEN(x) x,
|
|
|
|
|
FOR_EACH_TOKEN_TYPE
|
|
|
|
|
#undef __TOKEN
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-04 00:01:16 +02:00
|
|
|
|
char const* to_string() const
|
2020-05-01 02:28:58 +03:00
|
|
|
|
{
|
|
|
|
|
switch (m_type) {
|
|
|
|
|
#define __TOKEN(x) \
|
|
|
|
|
case Type::x: \
|
|
|
|
|
return #x;
|
|
|
|
|
FOR_EACH_TOKEN_TYPE
|
|
|
|
|
#undef __TOKEN
|
|
|
|
|
}
|
2021-02-23 20:42:32 +01:00
|
|
|
|
VERIFY_NOT_REACHED();
|
2020-05-01 02:28:58 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Type m_type { Type::Unknown };
|
|
|
|
|
IniPosition m_start;
|
|
|
|
|
IniPosition m_end;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class IniLexer {
|
|
|
|
|
public:
|
2021-11-11 00:55:02 +01:00
|
|
|
|
IniLexer(StringView);
|
2020-05-01 02:28:58 +03:00
|
|
|
|
|
|
|
|
|
Vector<IniToken> lex();
|
|
|
|
|
|
|
|
|
|
private:
|
2023-01-10 22:57:32 +00:00
|
|
|
|
u32 peek(size_t offset = 0) const;
|
|
|
|
|
u32 consume();
|
2020-05-01 02:28:58 +03:00
|
|
|
|
|
2023-01-10 22:57:32 +00:00
|
|
|
|
Utf8View m_input;
|
|
|
|
|
Utf8CodePointIterator m_iterator;
|
2020-05-01 02:28:58 +03:00
|
|
|
|
IniPosition m_position { 0, 0 };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
2022-02-02 21:32:32 +01:00
|
|
|
|
|
|
|
|
|
#undef FOR_EACH_TOKEN_TYPE
|