diff options
author | Sam Atkins <atkinssj@gmail.com> | 2021-07-30 17:06:48 +0100 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-08-02 19:01:25 +0430 |
commit | eadcdd21e3367f4a3c0a4376099fca69d856b37c (patch) | |
tree | 6826e8085f2d02572df094c26add18863d79c9ce | |
parent | f4b3ab19c0118d1b77bd0eaa4050b451356bf367 (diff) | |
download | serenity-eadcdd21e3367f4a3c0a4376099fca69d856b37c.zip |
LibWeb: Clarify naming and publicity of CSS Parser methods
`parse_as_foo()` implies that the Parser's internal data is used,
whereas `parse_a_foo()` implies that the passed-in data is used.
Also, made all the `parse_a_foo()` methods private, as they are only
required within the Parser, and this makes the API clearer to outsiders.
The `parse_a(s)_foo()` naming is a little awkward, but it comes from
section 5.3 of the spec, so seemed worth keeping:
https://www.w3.org/TR/css-syntax-3/#parser-entry-points
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 42 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 66 |
2 files changed, 50 insertions, 58 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 4ca81a9c1f..c367dd1b95 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -155,11 +155,11 @@ Parser::~Parser() NonnullRefPtr<CSSStyleSheet> Parser::parse_as_stylesheet() { - return parse_as_stylesheet(m_token_stream); + return parse_a_stylesheet(m_token_stream); } template<typename T> -NonnullRefPtr<CSSStyleSheet> Parser::parse_as_stylesheet(TokenStream<T>& tokens) +NonnullRefPtr<CSSStyleSheet> Parser::parse_a_stylesheet(TokenStream<T>& tokens) { dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_stylesheet"); @@ -179,7 +179,7 @@ NonnullRefPtr<CSSStyleSheet> Parser::parse_as_stylesheet(TokenStream<T>& tokens) return stylesheet; } -Optional<SelectorList> Parser::parse_a_selector() +Optional<SelectorList> Parser::parse_as_selector() { return parse_a_selector(m_token_stream); } @@ -196,7 +196,7 @@ Optional<SelectorList> Parser::parse_a_selector(TokenStream<T>& tokens) return {}; } -Optional<SelectorList> Parser::parse_a_relative_selector() +Optional<SelectorList> Parser::parse_as_relative_selector() { return parse_a_relative_selector(m_token_stream); } @@ -218,7 +218,7 @@ Optional<SelectorList> Parser::parse_a_selector_list(TokenStream<T>& tokens) { dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_a_selector_list"); - auto comma_separated_lists = parse_as_comma_separated_list_of_component_values(tokens); + auto comma_separated_lists = parse_a_comma_separated_list_of_component_values(tokens); NonnullRefPtrVector<Selector> selectors; for (auto& selector_parts : comma_separated_lists) { @@ -241,7 +241,7 @@ Optional<SelectorList> Parser::parse_a_relative_selector_list(TokenStream<T>& to { dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_a_relative_selector_list"); - auto comma_separated_lists = parse_as_comma_separated_list_of_component_values(tokens); + auto comma_separated_lists = parse_a_comma_separated_list_of_component_values(tokens); NonnullRefPtrVector<Selector> selectors; for (auto& selector_parts : comma_separated_lists) { @@ -991,11 +991,11 @@ Vector<DeclarationOrAtRule> Parser::consume_a_list_of_declarations(TokenStream<T RefPtr<CSSRule> Parser::parse_as_rule() { - return parse_as_rule(m_token_stream); + return parse_a_rule(m_token_stream); } template<typename T> -RefPtr<CSSRule> Parser::parse_as_rule(TokenStream<T>& tokens) +RefPtr<CSSRule> Parser::parse_a_rule(TokenStream<T>& tokens) { dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_rule"); @@ -1030,11 +1030,11 @@ RefPtr<CSSRule> Parser::parse_as_rule(TokenStream<T>& tokens) NonnullRefPtrVector<CSSRule> Parser::parse_as_list_of_rules() { - return parse_as_list_of_rules(m_token_stream); + return parse_a_list_of_rules(m_token_stream); } template<typename T> -NonnullRefPtrVector<CSSRule> Parser::parse_as_list_of_rules(TokenStream<T>& tokens) +NonnullRefPtrVector<CSSRule> Parser::parse_a_list_of_rules(TokenStream<T>& tokens) { dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_list_of_rules"); @@ -1052,11 +1052,11 @@ NonnullRefPtrVector<CSSRule> Parser::parse_as_list_of_rules(TokenStream<T>& toke Optional<StyleProperty> Parser::parse_as_declaration() { - return parse_as_declaration(m_token_stream); + return parse_a_declaration(m_token_stream); } template<typename T> -Optional<StyleProperty> Parser::parse_as_declaration(TokenStream<T>& tokens) +Optional<StyleProperty> Parser::parse_a_declaration(TokenStream<T>& tokens) { dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_declaration"); @@ -1077,11 +1077,11 @@ Optional<StyleProperty> Parser::parse_as_declaration(TokenStream<T>& tokens) RefPtr<CSSStyleDeclaration> Parser::parse_as_list_of_declarations() { - return parse_as_list_of_declarations(m_token_stream); + return parse_a_list_of_declarations(m_token_stream); } template<typename T> -RefPtr<CSSStyleDeclaration> Parser::parse_as_list_of_declarations(TokenStream<T>& tokens) +RefPtr<CSSStyleDeclaration> Parser::parse_a_list_of_declarations(TokenStream<T>& tokens) { dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_list_of_declarations"); @@ -1114,11 +1114,11 @@ RefPtr<CSSStyleDeclaration> Parser::parse_as_list_of_declarations(TokenStream<T> Optional<StyleComponentValueRule> Parser::parse_as_component_value() { - return parse_as_component_value(m_token_stream); + return parse_a_component_value(m_token_stream); } template<typename T> -Optional<StyleComponentValueRule> Parser::parse_as_component_value(TokenStream<T>& tokens) +Optional<StyleComponentValueRule> Parser::parse_a_component_value(TokenStream<T>& tokens) { dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_component_value"); @@ -1144,11 +1144,11 @@ Optional<StyleComponentValueRule> Parser::parse_as_component_value(TokenStream<T Vector<StyleComponentValueRule> Parser::parse_as_list_of_component_values() { - return parse_as_list_of_component_values(m_token_stream); + return parse_a_list_of_component_values(m_token_stream); } template<typename T> -Vector<StyleComponentValueRule> Parser::parse_as_list_of_component_values(TokenStream<T>& tokens) +Vector<StyleComponentValueRule> Parser::parse_a_list_of_component_values(TokenStream<T>& tokens) { dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_list_of_component_values"); @@ -1167,11 +1167,11 @@ Vector<StyleComponentValueRule> Parser::parse_as_list_of_component_values(TokenS Vector<Vector<StyleComponentValueRule>> Parser::parse_as_comma_separated_list_of_component_values() { - return parse_as_comma_separated_list_of_component_values(m_token_stream); + return parse_a_comma_separated_list_of_component_values(m_token_stream); } template<typename T> -Vector<Vector<StyleComponentValueRule>> Parser::parse_as_comma_separated_list_of_component_values(TokenStream<T>& tokens) +Vector<Vector<StyleComponentValueRule>> Parser::parse_a_comma_separated_list_of_component_values(TokenStream<T>& tokens) { dbgln_if(CSS_PARSER_DEBUG, "Parser::parse_as_comma_separated_list_of_component_values"); @@ -1293,7 +1293,7 @@ RefPtr<CSSStyleDeclaration> Parser::convert_to_declaration(NonnullRefPtr<StyleBl return {}; auto stream = TokenStream(block->m_values); - return parse_as_list_of_declarations(stream); + return parse_a_list_of_declarations(stream); } Optional<StyleProperty> Parser::convert_to_style_property(StyleDeclarationRule& declaration) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 0baa8c5ffd..2e2f35a34d 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -75,59 +75,56 @@ public: // The normal parser entry point, for parsing stylesheets. NonnullRefPtr<CSSStyleSheet> parse_as_stylesheet(); - template<typename T> - NonnullRefPtr<CSSStyleSheet> parse_as_stylesheet(TokenStream<T>&); - // For the content of at-rules such as @media. It differs from "Parse a stylesheet" in the handling of <CDO-token> and <CDC-token>. NonnullRefPtrVector<CSSRule> parse_as_list_of_rules(); - template<typename T> - NonnullRefPtrVector<CSSRule> parse_as_list_of_rules(TokenStream<T>&); - // For use by the CSSStyleSheet#insertRule method, and similar functions which might exist, which parse text into a single rule. RefPtr<CSSRule> parse_as_rule(); - template<typename T> - RefPtr<CSSRule> parse_as_rule(TokenStream<T>&); - // Used in @supports conditions. [CSS3-CONDITIONAL] Optional<StyleProperty> parse_as_declaration(); - template<typename T> - Optional<StyleProperty> parse_as_declaration(TokenStream<T>&); - // For the contents of a style attribute, which parses text into the contents of a single style rule. RefPtr<CSSStyleDeclaration> parse_as_list_of_declarations(); - template<typename T> - RefPtr<CSSStyleDeclaration> parse_as_list_of_declarations(TokenStream<T>&); - // For things that need to consume a single value, like the parsing rules for attr(). Optional<StyleComponentValueRule> parse_as_component_value(); - template<typename T> - Optional<StyleComponentValueRule> parse_as_component_value(TokenStream<T>&); - // For the contents of presentational attributes, which parse text into a single declaration’s value, or for parsing a stand-alone selector [SELECT] or list of Media Queries [MEDIAQ], as in Selectors API or the media HTML attribute. Vector<StyleComponentValueRule> parse_as_list_of_component_values(); - template<typename T> - Vector<StyleComponentValueRule> parse_as_list_of_component_values(TokenStream<T>&); - Vector<Vector<StyleComponentValueRule>> parse_as_comma_separated_list_of_component_values(); - template<typename T> - Vector<Vector<StyleComponentValueRule>> parse_as_comma_separated_list_of_component_values(TokenStream<T>&); - - Optional<Selector::SimpleSelector::ANPlusBPattern> parse_a_n_plus_b_pattern(TokenStream<StyleComponentValueRule>&); - // FIXME: https://www.w3.org/TR/selectors-4/ // Contrary to the name, these parse a comma-separated list of selectors, according to the spec. - Optional<SelectorList> parse_a_selector(); + Optional<SelectorList> parse_as_selector(); + Optional<SelectorList> parse_as_relative_selector(); + + // FIXME: These want to be private, but StyleResolver still uses them for now. + RefPtr<StyleValue> parse_css_value(PropertyID, TokenStream<StyleComponentValueRule>&); + static RefPtr<StyleValue> parse_css_value(ParsingContext const&, PropertyID, StyleComponentValueRule const&); + +private: + template<typename T> + NonnullRefPtr<CSSStyleSheet> parse_a_stylesheet(TokenStream<T>&); + template<typename T> + NonnullRefPtrVector<CSSRule> parse_a_list_of_rules(TokenStream<T>&); + template<typename T> + RefPtr<CSSRule> parse_a_rule(TokenStream<T>&); + template<typename T> + Optional<StyleProperty> parse_a_declaration(TokenStream<T>&); + template<typename T> + RefPtr<CSSStyleDeclaration> parse_a_list_of_declarations(TokenStream<T>&); + template<typename T> + Optional<StyleComponentValueRule> parse_a_component_value(TokenStream<T>&); + template<typename T> + Vector<StyleComponentValueRule> parse_a_list_of_component_values(TokenStream<T>&); + template<typename T> + Vector<Vector<StyleComponentValueRule>> parse_a_comma_separated_list_of_component_values(TokenStream<T>&); template<typename T> Optional<SelectorList> parse_a_selector(TokenStream<T>&); - - Optional<SelectorList> parse_a_relative_selector(); template<typename T> Optional<SelectorList> parse_a_relative_selector(TokenStream<T>&); + template<typename T> + Optional<SelectorList> parse_a_selector_list(TokenStream<T>&); + template<typename T> + Optional<SelectorList> parse_a_relative_selector_list(TokenStream<T>&); - RefPtr<StyleValue> parse_css_value(PropertyID, TokenStream<StyleComponentValueRule>&); - static RefPtr<StyleValue> parse_css_value(ParsingContext const&, PropertyID, StyleComponentValueRule const&); + Optional<Selector::SimpleSelector::ANPlusBPattern> parse_a_n_plus_b_pattern(TokenStream<StyleComponentValueRule>&); -private: [[nodiscard]] NonnullRefPtrVector<StyleRule> consume_a_list_of_rules(bool top_level); template<typename T> [[nodiscard]] NonnullRefPtrVector<StyleRule> consume_a_list_of_rules(TokenStream<T>&, bool top_level); @@ -191,11 +188,6 @@ private: static OwnPtr<CalculatedStyleValue::CalcNumberSumPartWithOperator> parse_calc_number_sum_part_with_operator(ParsingContext const&, TokenStream<StyleComponentValueRule>&); static OwnPtr<CalculatedStyleValue::CalcSum> parse_calc_expression(ParsingContext const&, Vector<StyleComponentValueRule> const&); - template<typename T> - Optional<SelectorList> parse_a_selector_list(TokenStream<T>&); - template<typename T> - Optional<SelectorList> parse_a_relative_selector_list(TokenStream<T>&); - enum class SelectorParsingResult { Done, SyntaxError, |