| 
									
										
										
										
											2021-03-09 17:18:08 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-04-28 22:46:44 +02:00
										 |  |  |  * Copyright (c) 2020-2021, the SerenityOS developers. | 
					
						
							| 
									
										
										
										
											2021-07-01 14:52:12 +01:00
										 |  |  |  * Copyright (c) 2021, Sam Atkins <atkinssj@gmail.com> | 
					
						
							| 
									
										
										
										
											2021-03-09 17:18:08 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2021-03-09 17:18:08 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/String.h>
 | 
					
						
							|  |  |  | #include <AK/StringBuilder.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Token { | 
					
						
							|  |  |  |     friend class Parser; | 
					
						
							|  |  |  |     friend class Tokenizer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-07-09 20:54:06 +01:00
										 |  |  |     enum class Type { | 
					
						
							| 
									
										
										
										
											2021-03-09 17:18:08 +01:00
										 |  |  |         Invalid, | 
					
						
							|  |  |  |         EndOfFile, | 
					
						
							|  |  |  |         Ident, | 
					
						
							|  |  |  |         Function, | 
					
						
							|  |  |  |         AtKeyword, | 
					
						
							|  |  |  |         Hash, | 
					
						
							|  |  |  |         String, | 
					
						
							|  |  |  |         BadString, | 
					
						
							|  |  |  |         Url, | 
					
						
							|  |  |  |         BadUrl, | 
					
						
							|  |  |  |         Delim, | 
					
						
							|  |  |  |         Number, | 
					
						
							|  |  |  |         Percentage, | 
					
						
							|  |  |  |         Dimension, | 
					
						
							|  |  |  |         Whitespace, | 
					
						
							|  |  |  |         CDO, | 
					
						
							|  |  |  |         CDC, | 
					
						
							|  |  |  |         Colon, | 
					
						
							|  |  |  |         Semicolon, | 
					
						
							|  |  |  |         Comma, | 
					
						
							|  |  |  |         OpenSquare, | 
					
						
							|  |  |  |         CloseSquare, | 
					
						
							|  |  |  |         OpenParen, | 
					
						
							|  |  |  |         CloseParen, | 
					
						
							|  |  |  |         OpenCurly, | 
					
						
							|  |  |  |         CloseCurly | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     enum class HashType { | 
					
						
							|  |  |  |         Id, | 
					
						
							|  |  |  |         Unrestricted, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     enum class NumberType { | 
					
						
							|  |  |  |         Integer, | 
					
						
							|  |  |  |         Number, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-09 20:54:06 +01:00
										 |  |  |     bool is(Type type) const { return m_type == type; } | 
					
						
							| 
									
										
										
										
											2021-07-01 14:52:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     StringView ident() const | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-07-03 15:06:53 +01:00
										 |  |  |         VERIFY(m_type == Type::Ident); | 
					
						
							| 
									
										
										
										
											2021-07-01 14:52:12 +01:00
										 |  |  |         return m_value.string_view(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     StringView delim() const | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-07-03 15:06:53 +01:00
										 |  |  |         VERIFY(m_type == Type::Delim); | 
					
						
							| 
									
										
										
										
											2021-07-01 14:52:12 +01:00
										 |  |  |         return m_value.string_view(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     StringView string() const | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-07-03 15:06:53 +01:00
										 |  |  |         VERIFY(m_type == Type::String); | 
					
						
							| 
									
										
										
										
											2021-07-01 14:52:12 +01:00
										 |  |  |         return m_value.string_view(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-03-09 17:18:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-09 21:04:34 +01:00
										 |  |  |     int integer() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         VERIFY(m_type == Type::Number && m_number_type == NumberType::Integer); | 
					
						
							|  |  |  |         return m_value.string_view().to_int().value(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-09 20:54:06 +01:00
										 |  |  |     Type mirror_variant() const; | 
					
						
							| 
									
										
										
										
											2021-03-09 17:18:08 +01:00
										 |  |  |     String bracket_string() const; | 
					
						
							|  |  |  |     String bracket_mirror_string() const; | 
					
						
							|  |  |  |     String to_string() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2021-07-09 20:54:06 +01:00
										 |  |  |     Type m_type { Type::Invalid }; | 
					
						
							| 
									
										
										
										
											2021-03-09 17:18:08 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     StringBuilder m_value; | 
					
						
							|  |  |  |     StringBuilder m_unit; | 
					
						
							|  |  |  |     HashType m_hash_type { HashType::Unrestricted }; | 
					
						
							|  |  |  |     NumberType m_number_type { NumberType::Integer }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |