Browse Source

RCSS: Never require end-semicolon for the last property.

Michael Ragazzon 5 years ago
parent
commit
55580edfd3
2 changed files with 13 additions and 11 deletions
  1. 10 6
      Source/Core/StyleSheetParser.cpp
  2. 3 5
      Source/Core/StyleSheetParser.h

+ 10 - 6
Source/Core/StyleSheetParser.cpp

@@ -55,7 +55,10 @@ public:
 */
 class PropertySpecificationParser : public AbstractPropertyParser {
 private:
+	// The dictionary to store the properties in.
 	PropertyDictionary& properties;
+
+	// The specification used to parse the values. Normally the default stylesheet specification, but not for e.g. all at-rules such as decorators.
 	const PropertySpecification& specification;
 
 public:
@@ -499,7 +502,7 @@ bool StyleSheetParser::ParseProperties(PropertyDictionary& parsed_properties, co
 	StreamMemory stream_owner((const byte*)properties.c_str(), properties.size());
 	stream = &stream_owner;
 	PropertySpecificationParser parser(parsed_properties, StyleSheetSpecification::GetPropertySpecification());
-	bool success = ReadProperties(parser, false);
+	bool success = ReadProperties(parser);
 	stream = nullptr;
 	return success;
 }
@@ -525,7 +528,7 @@ StyleSheetNodeListRaw StyleSheetParser::ConstructNodes(StyleSheetNode& root_node
 }
 
 
-bool StyleSheetParser::ReadProperties(AbstractPropertyParser& property_parser, bool require_end_semicolon)
+bool StyleSheetParser::ReadProperties(AbstractPropertyParser& property_parser)
 {
 	String name;
 	String value;
@@ -555,7 +558,7 @@ bool StyleSheetParser::ReadProperties(AbstractPropertyParser& property_parser, b
 				else if (character == '}')
 				{
 					name = StringUtilities::StripWhitespace(name);
-					if (!StringUtilities::StripWhitespace(name).empty())
+					if (!name.empty())
 						Log::Message(Log::LT_WARNING, "End of rule encountered while parsing property declaration '%s' at %s:%d", name.c_str(), stream_file_name.c_str(), line_number);
 					return true;
 				}
@@ -584,8 +587,7 @@ bool StyleSheetParser::ReadProperties(AbstractPropertyParser& property_parser, b
 				}
 				else if (character == '}')
 				{
-					Log::Message(Log::LT_WARNING, "End of rule encountered while parsing property declaration '%s: %s;' in %s: %d.", name.c_str(), value.c_str(), stream_file_name.c_str(), line_number);
-					return true;
+					break;
 				}
 				else
 				{
@@ -605,10 +607,12 @@ bool StyleSheetParser::ReadProperties(AbstractPropertyParser& property_parser, b
 			break;
 		}
 
+		if (character == '}')
+			break;
 		previous_character = character;
 	}
 
-	if (!require_end_semicolon && !name.empty() && !value.empty())
+	if (state == VALUE && !name.empty() && !value.empty())
 	{
 		value = StringUtilities::StripWhitespace(value);
 

+ 3 - 5
Source/Core/StyleSheetParser.h

@@ -84,11 +84,9 @@ private:
 	// Current line number we're parsing.
 	size_t line_number;
 
-	// Parses properties from the parse buffer into the dictionary
-	// @param properties The dictionary to store the properties in
-	// @param property_specification The specification used to parse the values. Normally the default stylesheet specification, but not for e.g. all at-rules such as decorators.
-	// @param require_end_semicolon True to require a ';' character after the final property.
-	bool ReadProperties(AbstractPropertyParser& property_parser, bool require_end_semicolon = true);
+	// Parses properties from the parse buffer.
+	// @param property_parser An abstract parser which specifies how the properties are parsed and stored.
+	bool ReadProperties(AbstractPropertyParser& property_parser);
 
 	// Import properties into the stylesheet node
 	// @param node Node to import into