Parser.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. /*
  2. * Copyright (c) 2020-2021, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/SourceLocation.h>
  7. #include <LibWeb/CSS/Parser/AtStyleRule.h>
  8. #include <LibWeb/CSS/Parser/DeclarationOrAtRule.h>
  9. #include <LibWeb/CSS/Parser/Parser.h>
  10. #include <LibWeb/CSS/Parser/QualifiedStyleRule.h>
  11. #include <LibWeb/CSS/Parser/StyleBlockRule.h>
  12. #include <LibWeb/CSS/Parser/StyleComponentValueRule.h>
  13. #include <LibWeb/CSS/Parser/StyleFunctionRule.h>
  14. #include <LibWeb/CSS/Selector.h>
  15. #include <LibWeb/Dump.h>
  16. #define CSS_PARSER_TRACE 1
  17. static void log_parse_error(const SourceLocation& location = SourceLocation::current())
  18. {
  19. dbgln_if(CSS_PARSER_TRACE, "Parse error (CSS) {}", location);
  20. }
  21. namespace Web::CSS {
  22. Parser::Parser(const StringView& input, const String& encoding)
  23. : m_tokenizer(input, encoding)
  24. {
  25. m_tokens = m_tokenizer.parse();
  26. }
  27. Parser::~Parser()
  28. {
  29. }
  30. Token Parser::peek_token()
  31. {
  32. size_t next_offset = m_iterator_offset + 1;
  33. if (next_offset < m_tokens.size()) {
  34. return m_tokens.at(next_offset);
  35. }
  36. return m_tokens.at(m_iterator_offset);
  37. }
  38. Token Parser::next_token()
  39. {
  40. if (m_iterator_offset < (int)m_tokens.size()) {
  41. ++m_iterator_offset;
  42. }
  43. auto token = m_tokens.at(m_iterator_offset);
  44. return token;
  45. }
  46. Token Parser::current_token()
  47. {
  48. return m_tokens.at(m_iterator_offset);
  49. }
  50. Vector<QualifiedStyleRule> Parser::parse_as_stylesheet()
  51. {
  52. auto rules = consume_a_list_of_rules(true);
  53. dbgln("Printing rules:");
  54. for (auto& rule : rules) {
  55. dbgln("PRE:");
  56. for (auto& pre : rule.m_prelude) {
  57. dbgln("{}", pre);
  58. }
  59. dbgln("BLOCK:");
  60. dbgln("{}", rule.m_block.to_string());
  61. dbgln("");
  62. auto selectors = parse_selectors(rule.m_prelude);
  63. CSS::Selector selector = Selector(move(selectors));
  64. dump_selector(selector);
  65. }
  66. return rules;
  67. }
  68. Vector<CSS::Selector::ComplexSelector> Parser::parse_selectors(Vector<String> parts)
  69. {
  70. // TODO:
  71. // This is a mess because the prelude is parsed as a string.
  72. // It should really be parsed as its class, but the cpp gods have forsaken me
  73. // and i cant make it work due to cyclic includes.
  74. Vector<CSS::Selector::ComplexSelector> selectors;
  75. size_t index = 0;
  76. auto parse_simple_selector = [&]() -> Optional<CSS::Selector::SimpleSelector> {
  77. if (index >= parts.size()) {
  78. return {};
  79. }
  80. auto currentToken = parts.at(index);
  81. CSS::Selector::SimpleSelector::Type type;
  82. if (currentToken == "*") {
  83. type = CSS::Selector::SimpleSelector::Type::Universal;
  84. index++;
  85. return CSS::Selector::SimpleSelector {
  86. type,
  87. CSS::Selector::SimpleSelector::PseudoClass::None,
  88. CSS::Selector::SimpleSelector::PseudoElement::None,
  89. String(),
  90. CSS::Selector::SimpleSelector::AttributeMatchType::None,
  91. String(),
  92. String()
  93. };
  94. }
  95. if (currentToken == ".") {
  96. type = CSS::Selector::SimpleSelector::Type::Class;
  97. } else if (currentToken == "#") {
  98. type = CSS::Selector::SimpleSelector::Type::Id;
  99. } else if (currentToken == "*") {
  100. type = CSS::Selector::SimpleSelector::Type::Universal;
  101. } else {
  102. type = CSS::Selector::SimpleSelector::Type::TagName;
  103. }
  104. index++;
  105. auto value = currentToken;
  106. if (type == CSS::Selector::SimpleSelector::Type::TagName) {
  107. value = value.to_lowercase();
  108. }
  109. CSS::Selector::SimpleSelector simple_selector {
  110. type,
  111. CSS::Selector::SimpleSelector::PseudoClass::None,
  112. CSS::Selector::SimpleSelector::PseudoElement::None,
  113. value,
  114. CSS::Selector::SimpleSelector::AttributeMatchType::None,
  115. String(),
  116. String()
  117. };
  118. if (index >= parts.size()) {
  119. return simple_selector;
  120. }
  121. currentToken = parts.at(index);
  122. if (currentToken.starts_with('[')) {
  123. auto adjusted = currentToken.substring(1, currentToken.length() - 2);
  124. // TODO: split on String :^)
  125. Vector<String> attribute_parts = adjusted.split(',');
  126. simple_selector.attribute_match_type = CSS::Selector::SimpleSelector::AttributeMatchType::HasAttribute;
  127. simple_selector.attribute_name = attribute_parts.first();
  128. size_t attribute_index = 1;
  129. if (attribute_index >= attribute_parts.size()) {
  130. return simple_selector;
  131. }
  132. if (attribute_parts.at(attribute_index) == " =") {
  133. simple_selector.attribute_match_type = CSS::Selector::SimpleSelector::AttributeMatchType::ExactValueMatch;
  134. attribute_index++;
  135. }
  136. if (attribute_parts.at(attribute_index) == " ~") {
  137. simple_selector.attribute_match_type = CSS::Selector::SimpleSelector::AttributeMatchType::Contains;
  138. attribute_index += 2;
  139. }
  140. if (attribute_parts.at(attribute_index) == " |") {
  141. simple_selector.attribute_match_type = CSS::Selector::SimpleSelector::AttributeMatchType::StartsWith;
  142. attribute_index += 2;
  143. }
  144. simple_selector.attribute_value = attribute_parts.at(attribute_index);
  145. return simple_selector;
  146. }
  147. if (currentToken == ":") {
  148. bool is_pseudo = false;
  149. index++;
  150. if (index >= parts.size()) {
  151. return {};
  152. }
  153. currentToken = parts.at(index);
  154. if (currentToken == ":") {
  155. is_pseudo = true;
  156. index++;
  157. }
  158. if (index >= parts.size()) {
  159. return {};
  160. }
  161. currentToken = parts.at(index);
  162. auto pseudo_name = currentToken;
  163. index++;
  164. // Ignore for now, otherwise we produce a "false positive" selector
  165. // and apply styles to the element itself, not its pseudo element
  166. if (is_pseudo) {
  167. return {};
  168. }
  169. if (pseudo_name.equals_ignoring_case("link")) {
  170. simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Link;
  171. } else if (pseudo_name.equals_ignoring_case("visited")) {
  172. simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Visited;
  173. } else if (pseudo_name.equals_ignoring_case("hover")) {
  174. simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Hover;
  175. } else if (pseudo_name.equals_ignoring_case("focus")) {
  176. simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Focus;
  177. } else if (pseudo_name.equals_ignoring_case("first-child")) {
  178. simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::FirstChild;
  179. } else if (pseudo_name.equals_ignoring_case("last-child")) {
  180. simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::LastChild;
  181. } else if (pseudo_name.equals_ignoring_case("only-child")) {
  182. simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::OnlyChild;
  183. } else if (pseudo_name.equals_ignoring_case("empty")) {
  184. simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Empty;
  185. } else if (pseudo_name.equals_ignoring_case("root")) {
  186. simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Root;
  187. } else if (pseudo_name.equals_ignoring_case("first-of-type")) {
  188. simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::FirstOfType;
  189. } else if (pseudo_name.equals_ignoring_case("last-of-type")) {
  190. simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::LastOfType;
  191. } else if (pseudo_name.equals_ignoring_case("before")) {
  192. simple_selector.pseudo_element = CSS::Selector::SimpleSelector::PseudoElement::Before;
  193. } else if (pseudo_name.equals_ignoring_case("after")) {
  194. simple_selector.pseudo_element = CSS::Selector::SimpleSelector::PseudoElement::After;
  195. } else {
  196. dbgln("Unknown pseudo class: '{}'", pseudo_name);
  197. return simple_selector;
  198. }
  199. }
  200. return simple_selector;
  201. };
  202. auto parse_complex_selector = [&]() -> Optional<CSS::Selector::ComplexSelector> {
  203. auto relation = CSS::Selector::ComplexSelector::Relation::Descendant;
  204. auto currentToken = parts.at(index);
  205. if (is_combinator(currentToken)) {
  206. if (currentToken == ">") {
  207. relation = CSS::Selector::ComplexSelector::Relation::ImmediateChild;
  208. }
  209. if (currentToken == "+") {
  210. relation = CSS::Selector::ComplexSelector::Relation::AdjacentSibling;
  211. }
  212. if (currentToken == "~") {
  213. relation = CSS::Selector::ComplexSelector::Relation::GeneralSibling;
  214. }
  215. if (currentToken == "||") {
  216. relation = CSS::Selector::ComplexSelector::Relation::Column;
  217. }
  218. index++;
  219. }
  220. Vector<CSS::Selector::SimpleSelector> simple_selectors;
  221. for (;;) {
  222. auto component = parse_simple_selector();
  223. if (!component.has_value()) {
  224. break;
  225. }
  226. simple_selectors.append(component.value());
  227. }
  228. if (simple_selectors.is_empty())
  229. return {};
  230. return CSS::Selector::ComplexSelector { relation, move(simple_selectors) };
  231. };
  232. for (;;) {
  233. auto complex = parse_complex_selector();
  234. if (complex.has_value()) {
  235. selectors.append(complex.value());
  236. }
  237. if (index >= parts.size()) {
  238. break;
  239. }
  240. auto currentToken = parts.at(index);
  241. if (currentToken != ",") {
  242. break;
  243. }
  244. index++;
  245. }
  246. if (selectors.is_empty()) {
  247. return {};
  248. }
  249. selectors.first().relation = CSS::Selector::ComplexSelector::Relation::None;
  250. return selectors;
  251. }
  252. void Parser::dump_all_tokens()
  253. {
  254. dbgln("Dumping all tokens:");
  255. for (auto& token : m_tokens)
  256. dbgln("{}", token.to_string());
  257. }
  258. void Parser::reconsume_current_input_token()
  259. {
  260. --m_iterator_offset;
  261. }
  262. bool Parser::is_combinator(String input)
  263. {
  264. return input == ">" || input == "+" || input == "~" || input == "||";
  265. }
  266. Vector<QualifiedStyleRule> Parser::consume_a_list_of_rules(bool top_level)
  267. {
  268. Vector<QualifiedStyleRule> rules;
  269. for (;;) {
  270. auto token = next_token();
  271. if (token.is_whitespace()) {
  272. continue;
  273. }
  274. if (token.is_eof()) {
  275. break;
  276. }
  277. if (token.is_cdo() || token.is_cdc()) {
  278. if (top_level) {
  279. continue;
  280. }
  281. reconsume_current_input_token();
  282. auto maybe_qualified = consume_a_qualified_rule();
  283. if (maybe_qualified.has_value()) {
  284. rules.append(maybe_qualified.value());
  285. }
  286. continue;
  287. }
  288. if (token.is_at()) {
  289. reconsume_current_input_token();
  290. rules.append(consume_an_at_rule());
  291. continue;
  292. }
  293. reconsume_current_input_token();
  294. auto maybe_qualified = consume_a_qualified_rule();
  295. if (maybe_qualified.has_value()) {
  296. rules.append(maybe_qualified.value());
  297. }
  298. }
  299. return rules;
  300. }
  301. AtStyleRule Parser::consume_an_at_rule()
  302. {
  303. auto initial = next_token();
  304. AtStyleRule rule;
  305. rule.m_name = initial.m_value.to_string();
  306. for (;;) {
  307. auto token = next_token();
  308. if (token.is_semicolon()) {
  309. return rule;
  310. }
  311. if (token.is_eof()) {
  312. log_parse_error();
  313. return rule;
  314. }
  315. if (token.is_open_curly()) {
  316. rule.m_block = consume_a_simple_block();
  317. return rule;
  318. }
  319. // how is "simple block with an associated token of <{-token>" a valid token?
  320. reconsume_current_input_token();
  321. auto value = consume_a_component_value();
  322. if (value.m_type == StyleComponentValueRule::ComponentType::Token) {
  323. if (value.m_token.is_whitespace()) {
  324. continue;
  325. }
  326. }
  327. rule.m_prelude.append(value.to_string());
  328. }
  329. }
  330. Optional<QualifiedStyleRule> Parser::consume_a_qualified_rule()
  331. {
  332. QualifiedStyleRule rule;
  333. for (;;) {
  334. auto token = next_token();
  335. if (token.is_eof()) {
  336. log_parse_error();
  337. return {};
  338. }
  339. if (token.is_open_curly()) {
  340. rule.m_block = consume_a_simple_block();
  341. return rule;
  342. }
  343. // how is "simple block with an associated token of <{-token>" a valid token?
  344. reconsume_current_input_token();
  345. auto value = consume_a_component_value();
  346. if (value.m_type == StyleComponentValueRule::ComponentType::Token) {
  347. if (value.m_token.is_whitespace()) {
  348. continue;
  349. }
  350. }
  351. rule.m_prelude.append(value.to_string());
  352. }
  353. return rule;
  354. }
  355. StyleComponentValueRule Parser::consume_a_component_value()
  356. {
  357. auto token = next_token();
  358. if (token.is_open_curly() || token.is_open_square() || token.is_open_paren()) {
  359. auto component = StyleComponentValueRule(StyleComponentValueRule::ComponentType::Block);
  360. component.m_block = consume_a_simple_block();
  361. return component;
  362. }
  363. if (token.is_function()) {
  364. auto component = StyleComponentValueRule(StyleComponentValueRule::ComponentType::Function);
  365. component.m_function = consume_a_function();
  366. return component;
  367. }
  368. auto component = StyleComponentValueRule(StyleComponentValueRule::ComponentType::Token);
  369. component.m_token = token;
  370. return component;
  371. }
  372. StyleBlockRule Parser::consume_a_simple_block()
  373. {
  374. auto ending_token = current_token().mirror_variant();
  375. StyleBlockRule block;
  376. block.m_token = current_token();
  377. for (;;) {
  378. auto token = next_token();
  379. if (token.m_type == ending_token) {
  380. return block;
  381. }
  382. if (token.is_eof()) {
  383. log_parse_error();
  384. return block;
  385. }
  386. reconsume_current_input_token();
  387. auto value = consume_a_component_value();
  388. if (value.m_type == StyleComponentValueRule::ComponentType::Token) {
  389. if (value.m_token.is_whitespace()) {
  390. continue;
  391. }
  392. }
  393. block.m_values.append(value.to_string());
  394. }
  395. }
  396. StyleFunctionRule Parser::consume_a_function()
  397. {
  398. StyleFunctionRule function;
  399. function.m_name = current_token().m_value.to_string();
  400. for (;;) {
  401. auto token = next_token();
  402. if (token.is_close_paren()) {
  403. return function;
  404. }
  405. if (token.is_eof()) {
  406. log_parse_error();
  407. return function;
  408. }
  409. reconsume_current_input_token();
  410. auto value = consume_a_component_value();
  411. if (value.m_type == StyleComponentValueRule::ComponentType::Token) {
  412. if (value.m_token.is_whitespace()) {
  413. continue;
  414. }
  415. }
  416. function.m_values.append(value.to_string());
  417. }
  418. return function;
  419. }
  420. Optional<StyleDeclarationRule> Parser::consume_a_declaration(Vector<StyleComponentValueRule>)
  421. {
  422. TODO();
  423. }
  424. Optional<StyleDeclarationRule> Parser::consume_a_declaration()
  425. {
  426. auto token = next_token();
  427. StyleDeclarationRule declaration;
  428. declaration.m_name = token.m_value.to_string();
  429. for (;;) {
  430. if (!peek_token().is_whitespace()) {
  431. break;
  432. }
  433. next_token();
  434. }
  435. auto colon = next_token();
  436. if (!colon.is_colon()) {
  437. log_parse_error();
  438. return {};
  439. }
  440. for (;;) {
  441. if (!peek_token().is_whitespace()) {
  442. break;
  443. }
  444. next_token();
  445. }
  446. for (;;) {
  447. if (peek_token().is_eof()) {
  448. break;
  449. }
  450. declaration.m_values.append(consume_a_component_value());
  451. }
  452. auto second_last = declaration.m_values.at(declaration.m_values.size() - 2);
  453. auto last = declaration.m_values.at(declaration.m_values.size() - 1);
  454. if (second_last.m_type == StyleComponentValueRule::ComponentType::Token && last.m_type == StyleComponentValueRule::ComponentType::Token) {
  455. auto last_token = last.m_token;
  456. auto second_last_token = second_last.m_token;
  457. if (second_last_token.is_delim() && second_last_token.m_value.to_string().equals_ignoring_case("!")) {
  458. if (last_token.is_ident() && last_token.m_value.to_string().equals_ignoring_case("important")) {
  459. declaration.m_values.remove(declaration.m_values.size() - 2);
  460. declaration.m_values.remove(declaration.m_values.size() - 1);
  461. declaration.m_important = true;
  462. }
  463. }
  464. }
  465. for (;;) {
  466. auto maybe_whitespace = declaration.m_values.at(declaration.m_values.size() - 1);
  467. if (!(maybe_whitespace.m_type == StyleComponentValueRule::ComponentType::Token && maybe_whitespace.m_token.is_whitespace())) {
  468. break;
  469. }
  470. declaration.m_values.remove(declaration.m_values.size() - 1);
  471. }
  472. return declaration;
  473. }
  474. Vector<DeclarationOrAtRule> Parser::consume_a_list_of_declarations()
  475. {
  476. Vector<DeclarationOrAtRule> list;
  477. for (;;) {
  478. auto token = next_token();
  479. if (token.is_whitespace() || token.is_semicolon()) {
  480. continue;
  481. }
  482. if (token.is_eof()) {
  483. return list;
  484. }
  485. if (token.is_at()) {
  486. reconsume_current_input_token();
  487. list.append(DeclarationOrAtRule(consume_an_at_rule()));
  488. continue;
  489. }
  490. if (token.is_ident()) {
  491. Vector<StyleComponentValueRule> temp;
  492. auto component = StyleComponentValueRule(StyleComponentValueRule::ComponentType::Token);
  493. component.m_token = token;
  494. temp.append(component);
  495. for (;;) {
  496. auto peek = peek_token();
  497. if (peek.is_semicolon() || peek.is_eof()) {
  498. break;
  499. }
  500. temp.append(consume_a_component_value());
  501. }
  502. auto maybe_declaration = consume_a_declaration(temp);
  503. if (maybe_declaration.has_value()) {
  504. list.append(DeclarationOrAtRule(maybe_declaration.value()));
  505. }
  506. }
  507. log_parse_error();
  508. reconsume_current_input_token();
  509. auto peek = peek_token();
  510. if (!(peek.is_semicolon() || peek.is_eof())) {
  511. consume_a_component_value();
  512. }
  513. }
  514. return list;
  515. }
  516. Optional<QualifiedStyleRule> Parser::parse_as_rule()
  517. {
  518. Optional<QualifiedStyleRule> rule;
  519. for (;;) {
  520. auto maybe_whitespace = peek_token();
  521. if (!maybe_whitespace.is_whitespace()) {
  522. break;
  523. }
  524. next_token();
  525. }
  526. auto token = peek_token();
  527. if (token.is_eof()) {
  528. return {};
  529. }
  530. if (token.is_at()) {
  531. rule = consume_an_at_rule();
  532. } else {
  533. rule = consume_a_qualified_rule();
  534. }
  535. for (;;) {
  536. auto maybe_whitespace = peek_token();
  537. if (!token.is_whitespace()) {
  538. break;
  539. }
  540. next_token();
  541. }
  542. auto maybe_eof = peek_token();
  543. if (maybe_eof.is_eof()) {
  544. return rule;
  545. }
  546. return {};
  547. }
  548. Vector<QualifiedStyleRule> Parser::parse_as_list_of_rules()
  549. {
  550. return consume_a_list_of_rules(false);
  551. }
  552. Optional<StyleDeclarationRule> Parser::parse_as_declaration()
  553. {
  554. for (;;) {
  555. auto maybe_whitespace = peek_token();
  556. if (!maybe_whitespace.is_whitespace()) {
  557. break;
  558. }
  559. next_token();
  560. }
  561. auto token = peek_token();
  562. if (!token.is_ident()) {
  563. return {};
  564. }
  565. return consume_a_declaration();
  566. }
  567. Vector<DeclarationOrAtRule> Parser::parse_as_list_of_declarations()
  568. {
  569. return consume_a_list_of_declarations();
  570. }
  571. Optional<StyleComponentValueRule> Parser::parse_as_component_value()
  572. {
  573. for (;;) {
  574. auto maybe_whitespace = peek_token();
  575. if (!maybe_whitespace.is_whitespace()) {
  576. break;
  577. }
  578. next_token();
  579. }
  580. auto token = peek_token();
  581. if (token.is_eof()) {
  582. return {};
  583. }
  584. auto value = consume_a_component_value();
  585. for (;;) {
  586. auto maybe_whitespace = peek_token();
  587. if (!token.is_whitespace()) {
  588. break;
  589. }
  590. next_token();
  591. }
  592. auto maybe_eof = peek_token();
  593. if (maybe_eof.is_eof()) {
  594. return value;
  595. }
  596. return {};
  597. }
  598. Vector<StyleComponentValueRule> Parser::parse_as_list_of_component_values()
  599. {
  600. Vector<StyleComponentValueRule> rules;
  601. for (;;) {
  602. if (peek_token().is_eof()) {
  603. break;
  604. }
  605. rules.append(consume_a_component_value());
  606. }
  607. return rules;
  608. }
  609. Vector<StyleComponentValueRule> Parser::parse_as_list_of_comma_separated_component_values()
  610. {
  611. Vector<StyleComponentValueRule> rules;
  612. for (;;) {
  613. rules.append(consume_a_component_value());
  614. if (peek_token().is_comma())
  615. continue;
  616. if (peek_token().is_eof())
  617. break;
  618. }
  619. return rules;
  620. }
  621. }