mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:42:43 +00:00 
			
		
		
		
	 1682f0b760
			
		
	
	
		1682f0b760
		
	
	
	
	
		
			
			SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
		
			
				
	
	
		
			69 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | ||
|  * Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
 | ||
|  *
 | ||
|  * SPDX-License-Identifier: BSD-2-Clause
 | ||
|  */
 | ||
| 
 | ||
| #pragma once
 | ||
| 
 | ||
| #include <AK/StringView.h>
 | ||
| 
 | ||
| namespace GUI {
 | ||
| 
 | ||
| #define FOR_EACH_TOKEN_TYPE \
 | ||
|     __TOKEN(Unknown)        \
 | ||
|     __TOKEN(Comment)        \
 | ||
|     __TOKEN(Whitespace)     \
 | ||
|     __TOKEN(section)        \
 | ||
|     __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
 | ||
|     };
 | ||
| 
 | ||
|     const char* to_string() const
 | ||
|     {
 | ||
|         switch (m_type) {
 | ||
| #define __TOKEN(x) \
 | ||
|     case Type::x:  \
 | ||
|         return #x;
 | ||
|             FOR_EACH_TOKEN_TYPE
 | ||
| #undef __TOKEN
 | ||
|         }
 | ||
|         VERIFY_NOT_REACHED();
 | ||
|     }
 | ||
| 
 | ||
|     Type m_type { Type::Unknown };
 | ||
|     IniPosition m_start;
 | ||
|     IniPosition m_end;
 | ||
| };
 | ||
| 
 | ||
| class IniLexer {
 | ||
| public:
 | ||
|     IniLexer(const StringView&);
 | ||
| 
 | ||
|     Vector<IniToken> lex();
 | ||
| 
 | ||
| private:
 | ||
|     char peek(size_t offset = 0) const;
 | ||
|     char consume();
 | ||
| 
 | ||
|     StringView m_input;
 | ||
|     size_t m_index { 0 };
 | ||
|     IniPosition m_previous_position { 0, 0 };
 | ||
|     IniPosition m_position { 0, 0 };
 | ||
| };
 | ||
| 
 | ||
| }
 |