CSSGrammar.y.in 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992
  1. /*
  2. * Copyright (C) 2002-2003 Lars Knoll (knoll@kde.org)
  3. * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
  4. * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
  5. * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
  6. * Copyright (C) 2012 Intel Corporation. All rights reserved.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. */
  23. %pure_parser
  24. %parse-param { CSSParser* parser }
  25. %lex-param { CSSParser* parser }
  26. %union {
  27. bool boolean;
  28. char character;
  29. int integer;
  30. double number;
  31. CSSParserString string;
  32. StyleRuleBase* rule;
  33. Vector<RefPtr<StyleRuleBase> >* ruleList;
  34. CSSParserSelector* selector;
  35. Vector<OwnPtr<CSSParserSelector> >* selectorList;
  36. CSSSelector::MarginBoxType marginBox;
  37. CSSSelector::Relation relation;
  38. MediaQuerySet* mediaList;
  39. MediaQuery* mediaQuery;
  40. MediaQuery::Restrictor mediaQueryRestrictor;
  41. MediaQueryExp* mediaQueryExp;
  42. CSSParserValue value;
  43. CSSParserValueList* valueList;
  44. Vector<OwnPtr<MediaQueryExp> >* mediaQueryExpList;
  45. StyleKeyframe* keyframe;
  46. Vector<RefPtr<StyleKeyframe> >* keyframeRuleList;
  47. float val;
  48. CSSPropertyID id;
  49. CSSParser::Location location;
  50. }
  51. %{
  52. static inline int cssyyerror(void*, const char*)
  53. {
  54. return 1;
  55. }
  56. #if YYDEBUG > 0
  57. static inline bool isCSSTokenAString(int yytype)
  58. {
  59. switch (yytype) {
  60. case IDENT:
  61. case STRING:
  62. case NTH:
  63. case HEX:
  64. case IDSEL:
  65. case DIMEN:
  66. case INVALIDDIMEN:
  67. case URI:
  68. case FUNCTION:
  69. case ANYFUNCTION:
  70. case NOTFUNCTION:
  71. case CALCFUNCTION:
  72. case MINFUNCTION:
  73. case MAXFUNCTION:
  74. case VAR_DEFINITION:
  75. case UNICODERANGE:
  76. return true;
  77. default:
  78. return false;
  79. }
  80. }
  81. #endif
  82. %}
  83. #if ENABLE_SHADOW_DOM
  84. %expect 32
  85. #else
  86. %expect 31
  87. #endif
  88. %nonassoc LOWEST_PREC
  89. %left UNIMPORTANT_TOK
  90. %token WHITESPACE SGML_CD
  91. %token TOKEN_EOF 0
  92. %token INCLUDES
  93. %token DASHMATCH
  94. %token BEGINSWITH
  95. %token ENDSWITH
  96. %token CONTAINS
  97. %token <string> STRING
  98. %right <string> IDENT
  99. %token <string> NTH
  100. %nonassoc <string> HEX
  101. %nonassoc <string> IDSEL
  102. %nonassoc ':'
  103. %nonassoc '.'
  104. %nonassoc '['
  105. %nonassoc <string> '*'
  106. %nonassoc error
  107. %left '|'
  108. %token IMPORT_SYM
  109. %token PAGE_SYM
  110. %token MEDIA_SYM
  111. #if ENABLE_CSS3_CONDITIONAL_RULES
  112. %token SUPPORTS_SYM
  113. #endif
  114. %token FONT_FACE_SYM
  115. #if ENABLE_SHADOW_DOM
  116. %token HOST_SYM
  117. #endif
  118. %token CHARSET_SYM
  119. %token NAMESPACE_SYM
  120. %token VARFUNCTION
  121. %token WEBKIT_RULE_SYM
  122. %token WEBKIT_DECLS_SYM
  123. %token WEBKIT_KEYFRAME_RULE_SYM
  124. %token WEBKIT_KEYFRAMES_SYM
  125. %token WEBKIT_VALUE_SYM
  126. %token WEBKIT_MEDIAQUERY_SYM
  127. %token WEBKIT_SELECTOR_SYM
  128. %token WEBKIT_REGION_RULE_SYM
  129. %token WEBKIT_VIEWPORT_RULE_SYM
  130. #if ENABLE_CSS3_CONDITIONAL_RULES
  131. %token WEBKIT_SUPPORTS_CONDITION_SYM
  132. #endif
  133. #if ENABLE_CSS_SHADERS
  134. %token WEBKIT_FILTER_RULE_SYM
  135. #endif
  136. %token <marginBox> TOPLEFTCORNER_SYM
  137. %token <marginBox> TOPLEFT_SYM
  138. %token <marginBox> TOPCENTER_SYM
  139. %token <marginBox> TOPRIGHT_SYM
  140. %token <marginBox> TOPRIGHTCORNER_SYM
  141. %token <marginBox> BOTTOMLEFTCORNER_SYM
  142. %token <marginBox> BOTTOMLEFT_SYM
  143. %token <marginBox> BOTTOMCENTER_SYM
  144. %token <marginBox> BOTTOMRIGHT_SYM
  145. %token <marginBox> BOTTOMRIGHTCORNER_SYM
  146. %token <marginBox> LEFTTOP_SYM
  147. %token <marginBox> LEFTMIDDLE_SYM
  148. %token <marginBox> LEFTBOTTOM_SYM
  149. %token <marginBox> RIGHTTOP_SYM
  150. %token <marginBox> RIGHTMIDDLE_SYM
  151. %token <marginBox> RIGHTBOTTOM_SYM
  152. %token ATKEYWORD
  153. %token IMPORTANT_SYM
  154. %token MEDIA_ONLY
  155. %token MEDIA_NOT
  156. %token MEDIA_AND
  157. #if ENABLE_CSS3_CONDITIONAL_RULES
  158. %token SUPPORTS_NOT
  159. %token SUPPORTS_AND
  160. %token SUPPORTS_OR
  161. #endif
  162. %token <number> REMS
  163. %token <number> CHS
  164. %token <number> QEMS
  165. %token <number> EMS
  166. %token <number> EXS
  167. %token <number> PXS
  168. %token <number> CMS
  169. %token <number> MMS
  170. %token <number> INS
  171. %token <number> PTS
  172. %token <number> PCS
  173. %token <number> DEGS
  174. %token <number> RADS
  175. %token <number> GRADS
  176. %token <number> TURNS
  177. %token <number> MSECS
  178. %token <number> SECS
  179. %token <number> HERTZ
  180. %token <number> KHERTZ
  181. %token <string> DIMEN
  182. %token <string> INVALIDDIMEN
  183. %token <number> PERCENTAGE
  184. %token <number> FLOATTOKEN
  185. %token <number> INTEGER
  186. %token <number> VW
  187. %token <number> VH
  188. %token <number> VMIN
  189. %token <number> VMAX
  190. %token <number> DPPX
  191. %token <number> DPI
  192. %token <number> DPCM
  193. %token <string> URI
  194. %token <string> FUNCTION
  195. %token <string> ANYFUNCTION
  196. #if ENABLE_VIDEO_TRACK
  197. %token <string> CUEFUNCTION
  198. #endif
  199. %token <string> NOTFUNCTION
  200. %token <string> CALCFUNCTION
  201. %token <string> MINFUNCTION
  202. %token <string> MAXFUNCTION
  203. %token <string> VAR_DEFINITION
  204. %token <string> UNICODERANGE
  205. %type <relation> combinator
  206. %type <rule> charset
  207. %type <rule> ignored_charset
  208. %type <rule> ruleset
  209. %type <rule> media
  210. %type <rule> import
  211. %type <rule> namespace
  212. %type <rule> page
  213. %type <rule> margin_box
  214. %type <rule> font_face
  215. #if ENABLE_SHADOW_DOM
  216. %type <rule> host
  217. #endif
  218. %type <rule> keyframes
  219. %type <rule> invalid_rule
  220. %type <rule> save_block
  221. %type <rule> invalid_at
  222. %type <rule> rule
  223. %type <rule> valid_rule
  224. %type <ruleList> block_rule_list
  225. %type <ruleList> region_block_rule_list
  226. %type <rule> block_rule
  227. %type <rule> block_valid_rule
  228. %type <rule> region
  229. #if ENABLE_CSS3_CONDITIONAL_RULES
  230. %type <rule> supports
  231. #endif
  232. #if ENABLE_CSS_DEVICE_ADAPTATION
  233. %type <rule> viewport
  234. #endif
  235. #if ENABLE_CSS_SHADERS
  236. %type <rule> filter
  237. #endif
  238. %type <string> maybe_ns_prefix
  239. %type <string> namespace_selector
  240. %type <string> string_or_uri
  241. %type <string> ident_or_string
  242. %type <string> medium
  243. %type <marginBox> margin_sym
  244. %type <string> media_feature
  245. %type <mediaList> media_list
  246. %type <mediaList> maybe_media_list
  247. %type <mediaQuery> media_query
  248. %type <mediaQueryRestrictor> maybe_media_restrictor
  249. %type <valueList> maybe_media_value
  250. %type <mediaQueryExp> media_query_exp
  251. %type <mediaQueryExpList> media_query_exp_list
  252. %type <mediaQueryExpList> maybe_and_media_query_exp_list
  253. #if ENABLE_CSS3_CONDITIONAL_RULES
  254. %type <boolean> supports_condition
  255. %type <boolean> supports_condition_in_parens
  256. %type <boolean> supports_negation
  257. %type <boolean> supports_conjunction
  258. %type <boolean> supports_disjunction
  259. %type <boolean> supports_declaration_condition
  260. %type <boolean> supports_error
  261. #endif
  262. %type <string> keyframe_name
  263. %type <keyframe> keyframe_rule
  264. %type <keyframeRuleList> keyframes_rule
  265. %type <valueList> key_list
  266. %type <value> key
  267. %type <id> property
  268. %type <selector> specifier
  269. %type <selector> specifier_list
  270. %type <selector> simple_selector
  271. %type <selector> selector
  272. %type <selectorList> selector_list
  273. %type <selectorList> simple_selector_list
  274. %type <selectorList> region_selector
  275. %type <selector> selector_with_trailing_whitespace
  276. %type <selector> class
  277. %type <selector> attrib
  278. %type <selector> pseudo
  279. %type <selector> pseudo_page
  280. %type <selector> page_selector
  281. %type <boolean> declaration_list
  282. %type <boolean> decl_list
  283. %type <boolean> declaration
  284. %type <boolean> declarations_and_margins
  285. %type <boolean> prio
  286. %type <integer> match
  287. %type <integer> unary_operator
  288. %type <integer> maybe_unary_operator
  289. %type <character> operator
  290. %type <valueList> expr
  291. %type <value> term
  292. %type <value> unary_term
  293. %type <value> function
  294. %type <value> calc_func_term
  295. %type <character> calc_func_operator
  296. %type <valueList> calc_func_expr
  297. %type <valueList> calc_func_expr_list
  298. %type <valueList> calc_func_paren_expr
  299. %type <value> calc_function
  300. %type <string> min_or_max
  301. %type <value> min_or_max_function
  302. %type <string> element_name
  303. %type <string> attr_name
  304. %type <location> error_location
  305. %%
  306. stylesheet:
  307. maybe_space maybe_charset maybe_sgml rule_list
  308. | webkit_rule maybe_space
  309. | webkit_decls maybe_space
  310. | webkit_value maybe_space
  311. | webkit_mediaquery maybe_space
  312. | webkit_selector maybe_space
  313. | webkit_keyframe_rule maybe_space
  314. #if ENABLE_CSS3_CONDITIONAL_RULES
  315. | webkit_supports_condition maybe_space
  316. #endif
  317. ;
  318. webkit_rule:
  319. WEBKIT_RULE_SYM '{' maybe_space valid_rule maybe_space '}' {
  320. parser->m_rule = $4;
  321. }
  322. ;
  323. webkit_keyframe_rule:
  324. WEBKIT_KEYFRAME_RULE_SYM '{' maybe_space keyframe_rule maybe_space '}' {
  325. parser->m_keyframe = $4;
  326. }
  327. ;
  328. webkit_decls:
  329. WEBKIT_DECLS_SYM '{' maybe_space_before_declaration declaration_list '}' {
  330. /* can be empty */
  331. }
  332. ;
  333. webkit_value:
  334. WEBKIT_VALUE_SYM '{' maybe_space expr '}' {
  335. if ($4) {
  336. parser->m_valueList = parser->sinkFloatingValueList($4);
  337. int oldParsedProperties = parser->m_parsedProperties.size();
  338. if (!parser->parseValue(parser->m_id, parser->m_important))
  339. parser->rollbackLastProperties(parser->m_parsedProperties.size() - oldParsedProperties);
  340. parser->m_valueList = nullptr;
  341. }
  342. }
  343. ;
  344. webkit_mediaquery:
  345. WEBKIT_MEDIAQUERY_SYM WHITESPACE maybe_space media_query '}' {
  346. parser->m_mediaQuery = parser->sinkFloatingMediaQuery($4);
  347. }
  348. ;
  349. webkit_selector:
  350. WEBKIT_SELECTOR_SYM '{' maybe_space selector_list '}' {
  351. if ($4) {
  352. if (parser->m_selectorListForParseSelector)
  353. parser->m_selectorListForParseSelector->adoptSelectorVector(*$4);
  354. }
  355. }
  356. ;
  357. #if ENABLE_CSS3_CONDITIONAL_RULES
  358. webkit_supports_condition:
  359. WEBKIT_SUPPORTS_CONDITION_SYM '{' maybe_space supports_condition '}' {
  360. parser->m_supportsCondition = $4;
  361. }
  362. ;
  363. #endif
  364. maybe_space:
  365. /* empty */ %prec UNIMPORTANT_TOK
  366. | maybe_space WHITESPACE
  367. ;
  368. maybe_sgml:
  369. /* empty */
  370. | maybe_sgml SGML_CD
  371. | maybe_sgml WHITESPACE
  372. ;
  373. maybe_charset:
  374. /* empty */
  375. | charset {
  376. }
  377. ;
  378. closing_brace:
  379. '}'
  380. | %prec LOWEST_PREC TOKEN_EOF
  381. ;
  382. closing_parenthesis:
  383. ')'
  384. | %prec LOWEST_PREC TOKEN_EOF
  385. ;
  386. charset:
  387. CHARSET_SYM maybe_space STRING maybe_space ';' {
  388. if (parser->m_styleSheet)
  389. parser->m_styleSheet->parserSetEncodingFromCharsetRule($3);
  390. if (parser->isExtractingSourceData() && parser->m_currentRuleDataStack->isEmpty() && parser->m_ruleSourceDataResult)
  391. parser->addNewRuleToSourceTree(CSSRuleSourceData::createUnknown());
  392. $$ = 0;
  393. }
  394. | CHARSET_SYM error invalid_block {
  395. }
  396. | CHARSET_SYM error ';' {
  397. }
  398. ;
  399. ignored_charset:
  400. CHARSET_SYM maybe_space STRING maybe_space ';' {
  401. // Ignore any @charset rule not at the beginning of the style sheet.
  402. $$ = 0;
  403. }
  404. | CHARSET_SYM maybe_space ';' {
  405. $$ = 0;
  406. }
  407. ;
  408. rule_list:
  409. /* empty */
  410. | rule_list rule maybe_sgml {
  411. if ($2 && parser->m_styleSheet)
  412. parser->m_styleSheet->parserAppendRule($2);
  413. }
  414. ;
  415. valid_rule:
  416. ruleset
  417. | media
  418. | page
  419. | font_face
  420. | keyframes
  421. | namespace
  422. | import
  423. | region
  424. #if ENABLE_CSS3_CONDITIONAL_RULES
  425. | supports
  426. #endif
  427. #if ENABLE_SHADOW_DOM
  428. | host
  429. #endif
  430. #if ENABLE_CSS_DEVICE_ADAPTATION
  431. | viewport
  432. #endif
  433. #if ENABLE_CSS_SHADERS
  434. | filter
  435. #endif
  436. ;
  437. rule:
  438. valid_rule {
  439. parser->m_hadSyntacticallyValidCSSRule = true;
  440. }
  441. | ignored_charset
  442. | invalid_rule
  443. | invalid_at
  444. ;
  445. block_rule_list:
  446. /* empty */ { $$ = 0; }
  447. | block_rule_list block_rule maybe_sgml {
  448. $$ = $1;
  449. if ($2) {
  450. if (!$$)
  451. $$ = parser->createRuleList();
  452. $$->append($2);
  453. }
  454. }
  455. ;
  456. region_block_rule_list:
  457. /* empty */ { $$ = 0; }
  458. | region_block_rule_list block_valid_rule maybe_sgml {
  459. $$ = $1;
  460. if ($2) {
  461. if (!$$)
  462. $$ = parser->createRuleList();
  463. $$->append($2);
  464. }
  465. }
  466. ;
  467. block_valid_rule:
  468. ruleset
  469. | page
  470. | font_face
  471. | media
  472. | keyframes
  473. #if ENABLE_CSS3_CONDITIONAL_RULES
  474. | supports
  475. #endif
  476. #if ENABLE_CSS_DEVICE_ADAPTATION
  477. | viewport
  478. #endif
  479. #if ENABLE_CSS_SHADERS
  480. | filter
  481. #endif
  482. ;
  483. block_rule:
  484. block_valid_rule
  485. | invalid_rule
  486. | invalid_at
  487. | namespace
  488. | import
  489. | region
  490. ;
  491. at_import_header_end_maybe_space:
  492. maybe_space {
  493. parser->markRuleHeaderEnd();
  494. parser->markRuleBodyStart();
  495. }
  496. ;
  497. before_import_rule:
  498. /* empty */ {
  499. parser->markRuleHeaderStart(CSSRuleSourceData::IMPORT_RULE);
  500. }
  501. ;
  502. import:
  503. before_import_rule IMPORT_SYM at_import_header_end_maybe_space string_or_uri maybe_space maybe_media_list ';' {
  504. $$ = parser->createImportRule($4, $6);
  505. }
  506. | before_import_rule IMPORT_SYM at_import_header_end_maybe_space string_or_uri maybe_space maybe_media_list TOKEN_EOF {
  507. $$ = parser->createImportRule($4, $6);
  508. }
  509. | before_import_rule IMPORT_SYM at_import_header_end_maybe_space string_or_uri maybe_space maybe_media_list invalid_block {
  510. $$ = 0;
  511. parser->popRuleData();
  512. }
  513. | before_import_rule IMPORT_SYM error ';' {
  514. $$ = 0;
  515. parser->popRuleData();
  516. }
  517. | before_import_rule IMPORT_SYM error invalid_block {
  518. $$ = 0;
  519. parser->popRuleData();
  520. }
  521. ;
  522. namespace:
  523. NAMESPACE_SYM maybe_space maybe_ns_prefix string_or_uri maybe_space ';' {
  524. parser->addNamespace($3, $4);
  525. $$ = 0;
  526. }
  527. | NAMESPACE_SYM maybe_space maybe_ns_prefix string_or_uri maybe_space invalid_block {
  528. $$ = 0;
  529. }
  530. | NAMESPACE_SYM error invalid_block {
  531. $$ = 0;
  532. }
  533. | NAMESPACE_SYM error ';' {
  534. $$ = 0;
  535. }
  536. ;
  537. maybe_ns_prefix:
  538. /* empty */ { $$.clear(); }
  539. | IDENT maybe_space { $$ = $1; }
  540. ;
  541. string_or_uri:
  542. STRING
  543. | URI
  544. ;
  545. media_feature:
  546. IDENT maybe_space {
  547. $$ = $1;
  548. }
  549. ;
  550. maybe_media_value:
  551. /*empty*/ {
  552. $$ = 0;
  553. }
  554. | ':' maybe_space expr maybe_space {
  555. $$ = $3;
  556. }
  557. ;
  558. media_query_exp:
  559. maybe_media_restrictor maybe_space '(' maybe_space media_feature maybe_space maybe_media_value ')' maybe_space {
  560. // If restrictor is specified, media query expression is invalid.
  561. // Create empty media query expression and continue parsing media query.
  562. if ($1 != MediaQuery::None)
  563. $$ = parser->createFloatingMediaQueryExp("", 0);
  564. else {
  565. $5.lower();
  566. $$ = parser->createFloatingMediaQueryExp($5, $7);
  567. }
  568. }
  569. ;
  570. media_query_exp_list:
  571. media_query_exp {
  572. $$ = parser->createFloatingMediaQueryExpList();
  573. $$->append(parser->sinkFloatingMediaQueryExp($1));
  574. }
  575. | media_query_exp_list maybe_space MEDIA_AND maybe_space media_query_exp {
  576. $$ = $1;
  577. $$->append(parser->sinkFloatingMediaQueryExp($5));
  578. }
  579. ;
  580. maybe_and_media_query_exp_list:
  581. /*empty*/ {
  582. $$ = parser->createFloatingMediaQueryExpList();
  583. }
  584. | MEDIA_AND maybe_space media_query_exp_list {
  585. $$ = $3;
  586. }
  587. ;
  588. maybe_media_restrictor:
  589. /*empty*/ {
  590. $$ = MediaQuery::None;
  591. }
  592. | MEDIA_ONLY {
  593. $$ = MediaQuery::Only;
  594. }
  595. | MEDIA_NOT {
  596. $$ = MediaQuery::Not;
  597. }
  598. ;
  599. media_query:
  600. media_query_exp_list {
  601. $$ = parser->createFloatingMediaQuery(parser->sinkFloatingMediaQueryExpList($1));
  602. }
  603. |
  604. maybe_media_restrictor maybe_space medium maybe_and_media_query_exp_list {
  605. $3.lower();
  606. $$ = parser->createFloatingMediaQuery($1, $3, parser->sinkFloatingMediaQueryExpList($4));
  607. }
  608. ;
  609. maybe_media_list:
  610. /* empty */ {
  611. $$ = parser->createMediaQuerySet();
  612. }
  613. | media_list
  614. ;
  615. media_list:
  616. media_query {
  617. $$ = parser->createMediaQuerySet();
  618. $$->addMediaQuery(parser->sinkFloatingMediaQuery($1));
  619. parser->updateLastMediaLine($$);
  620. }
  621. | media_list ',' maybe_space media_query {
  622. $$ = $1;
  623. if ($$) {
  624. $$->addMediaQuery(parser->sinkFloatingMediaQuery($4));
  625. parser->updateLastMediaLine($$);
  626. }
  627. }
  628. | media_list error {
  629. $$ = 0;
  630. }
  631. ;
  632. at_rule_body_start:
  633. /* empty */ {
  634. parser->markRuleBodyStart();
  635. }
  636. ;
  637. before_media_rule:
  638. /* empty */ {
  639. parser->markRuleHeaderStart(CSSRuleSourceData::MEDIA_RULE);
  640. }
  641. ;
  642. at_rule_header_end_maybe_space:
  643. maybe_space {
  644. parser->markRuleHeaderEnd();
  645. }
  646. ;
  647. media:
  648. before_media_rule MEDIA_SYM maybe_space media_list at_rule_header_end '{' at_rule_body_start maybe_space block_rule_list save_block {
  649. $$ = parser->createMediaRule($4, $9);
  650. }
  651. | before_media_rule MEDIA_SYM at_rule_header_end_maybe_space '{' at_rule_body_start maybe_space block_rule_list save_block {
  652. $$ = parser->createMediaRule(0, $7);
  653. }
  654. | before_media_rule MEDIA_SYM at_rule_header_end_maybe_space ';' {
  655. $$ = 0;
  656. parser->popRuleData();
  657. }
  658. ;
  659. medium:
  660. IDENT maybe_space {
  661. $$ = $1;
  662. }
  663. ;
  664. #if ENABLE_CSS3_CONDITIONAL_RULES
  665. supports:
  666. before_supports_rule SUPPORTS_SYM maybe_space supports_condition at_supports_rule_header_end '{' at_rule_body_start maybe_space block_rule_list save_block {
  667. $$ = parser->createSupportsRule($4, $9);
  668. }
  669. | before_supports_rule SUPPORTS_SYM supports_error {
  670. $$ = 0;
  671. parser->popRuleData();
  672. parser->popSupportsRuleData();
  673. }
  674. ;
  675. supports_error:
  676. error ';'
  677. | error invalid_block
  678. before_supports_rule:
  679. /* empty */ {
  680. parser->markRuleHeaderStart(CSSRuleSourceData::SUPPORTS_RULE);
  681. parser->markSupportsRuleHeaderStart();
  682. }
  683. ;
  684. at_supports_rule_header_end:
  685. /* empty */ {
  686. parser->markRuleHeaderEnd();
  687. parser->markSupportsRuleHeaderEnd();
  688. }
  689. ;
  690. supports_condition:
  691. supports_condition_in_parens
  692. | supports_negation
  693. | supports_conjunction
  694. | supports_disjunction
  695. ;
  696. supports_negation:
  697. SUPPORTS_NOT maybe_space supports_condition_in_parens {
  698. $$ = !$3;
  699. }
  700. ;
  701. supports_conjunction:
  702. supports_condition_in_parens SUPPORTS_AND maybe_space supports_condition_in_parens {
  703. $$ = $1 && $4;
  704. }
  705. | supports_conjunction SUPPORTS_AND maybe_space supports_condition_in_parens {
  706. $$ = $1 && $4;
  707. }
  708. ;
  709. supports_disjunction:
  710. supports_condition_in_parens SUPPORTS_OR maybe_space supports_condition_in_parens {
  711. $$ = $1 || $4;
  712. }
  713. | supports_disjunction SUPPORTS_OR maybe_space supports_condition_in_parens {
  714. $$ = $1 || $4;
  715. }
  716. ;
  717. supports_condition_in_parens:
  718. '(' maybe_space supports_condition ')' maybe_space {
  719. $$ = $3;
  720. }
  721. | supports_declaration_condition
  722. | '(' error ')'
  723. ;
  724. supports_declaration_condition:
  725. '(' maybe_space property ':' maybe_space expr prio ')' maybe_space {
  726. $$ = false;
  727. CSSParser* p = static_cast<CSSParser*>(parser);
  728. if ($3 && $6) {
  729. p->m_valueList = p->sinkFloatingValueList($6);
  730. int oldParsedProperties = p->m_parsedProperties.size();
  731. $$ = p->parseValue(static_cast<CSSPropertyID>($3), $7);
  732. // We just need to know if the declaration is supported as it is written. Rollback any additions.
  733. if ($$)
  734. p->rollbackLastProperties(p->m_parsedProperties.size() - oldParsedProperties);
  735. p->m_valueList = nullptr;
  736. }
  737. p->markPropertyEnd($7, false);
  738. }
  739. ;
  740. #endif
  741. before_keyframes_rule:
  742. /* empty */ {
  743. parser->markRuleHeaderStart(CSSRuleSourceData::KEYFRAMES_RULE);
  744. }
  745. ;
  746. keyframes:
  747. before_keyframes_rule WEBKIT_KEYFRAMES_SYM maybe_space keyframe_name at_rule_header_end_maybe_space '{' at_rule_body_start maybe_space keyframes_rule closing_brace {
  748. $$ = parser->createKeyframesRule($4, parser->sinkFloatingKeyframeVector($9));
  749. }
  750. ;
  751. keyframe_name:
  752. IDENT
  753. | STRING
  754. ;
  755. keyframes_rule:
  756. /* empty */ { $$ = parser->createFloatingKeyframeVector(); }
  757. | keyframes_rule keyframe_rule maybe_space {
  758. $$ = $1;
  759. if ($2)
  760. $$->append($2);
  761. }
  762. ;
  763. keyframe_rule:
  764. key_list maybe_space '{' maybe_space declaration_list closing_brace {
  765. $$ = parser->createKeyframe($1);
  766. }
  767. ;
  768. key_list:
  769. key {
  770. $$ = parser->createFloatingValueList();
  771. $$->addValue(parser->sinkFloatingValue($1));
  772. }
  773. | key_list maybe_space ',' maybe_space key {
  774. $$ = $1;
  775. if ($$)
  776. $$->addValue(parser->sinkFloatingValue($5));
  777. }
  778. ;
  779. key:
  780. maybe_unary_operator PERCENTAGE { $$.id = 0; $$.isInt = false; $$.fValue = $1 * $2; $$.unit = CSSPrimitiveValue::CSS_NUMBER; }
  781. | IDENT {
  782. $$.id = 0; $$.isInt = false; $$.unit = CSSPrimitiveValue::CSS_NUMBER;
  783. CSSParserString& str = $1;
  784. if (str.equalIgnoringCase("from"))
  785. $$.fValue = 0;
  786. else if (str.equalIgnoringCase("to"))
  787. $$.fValue = 100;
  788. else {
  789. $$.unit = 0;
  790. YYERROR;
  791. }
  792. }
  793. | error {
  794. $$.unit = 0;
  795. }
  796. ;
  797. before_page_rule:
  798. /* empty */ {
  799. parser->markRuleHeaderStart(CSSRuleSourceData::PAGE_RULE);
  800. }
  801. ;
  802. page:
  803. before_page_rule PAGE_SYM maybe_space page_selector at_rule_header_end_maybe_space
  804. '{' at_rule_body_start maybe_space_before_declaration declarations_and_margins closing_brace {
  805. if ($4)
  806. $$ = parser->createPageRule(parser->sinkFloatingSelector($4));
  807. else {
  808. // Clear properties in the invalid @page rule.
  809. parser->clearProperties();
  810. // Also clear margin at-rules here once we fully implement margin at-rules parsing.
  811. $$ = 0;
  812. parser->popRuleData();
  813. }
  814. }
  815. | before_page_rule PAGE_SYM error invalid_block {
  816. parser->popRuleData();
  817. $$ = 0;
  818. }
  819. | before_page_rule PAGE_SYM error ';' {
  820. parser->popRuleData();
  821. $$ = 0;
  822. }
  823. ;
  824. page_selector:
  825. IDENT {
  826. $$ = parser->createFloatingSelectorWithTagName(QualifiedName(nullAtom, $1, parser->m_defaultNamespace));
  827. $$->setForPage();
  828. }
  829. | IDENT pseudo_page {
  830. $$ = $2;
  831. if ($$) {
  832. $$->prependTagSelector(QualifiedName(nullAtom, $1, parser->m_defaultNamespace));
  833. $$->setForPage();
  834. }
  835. }
  836. | pseudo_page {
  837. $$ = $1;
  838. if ($$)
  839. $$->setForPage();
  840. }
  841. | /* empty */ {
  842. $$ = parser->createFloatingSelector();
  843. $$->setForPage();
  844. }
  845. ;
  846. declarations_and_margins:
  847. declaration_list
  848. | declarations_and_margins margin_box maybe_space declaration_list
  849. ;
  850. margin_box:
  851. margin_sym {
  852. parser->startDeclarationsForMarginBox();
  853. } maybe_space '{' maybe_space declaration_list closing_brace {
  854. $$ = parser->createMarginAtRule($1);
  855. }
  856. ;
  857. margin_sym :
  858. TOPLEFTCORNER_SYM {
  859. $$ = CSSSelector::TopLeftCornerMarginBox;
  860. }
  861. | TOPLEFT_SYM {
  862. $$ = CSSSelector::TopLeftMarginBox;
  863. }
  864. | TOPCENTER_SYM {
  865. $$ = CSSSelector::TopCenterMarginBox;
  866. }
  867. | TOPRIGHT_SYM {
  868. $$ = CSSSelector::TopRightMarginBox;
  869. }
  870. | TOPRIGHTCORNER_SYM {
  871. $$ = CSSSelector::TopRightCornerMarginBox;
  872. }
  873. | BOTTOMLEFTCORNER_SYM {
  874. $$ = CSSSelector::BottomLeftCornerMarginBox;
  875. }
  876. | BOTTOMLEFT_SYM {
  877. $$ = CSSSelector::BottomLeftMarginBox;
  878. }
  879. | BOTTOMCENTER_SYM {
  880. $$ = CSSSelector::BottomCenterMarginBox;
  881. }
  882. | BOTTOMRIGHT_SYM {
  883. $$ = CSSSelector::BottomRightMarginBox;
  884. }
  885. | BOTTOMRIGHTCORNER_SYM {
  886. $$ = CSSSelector::BottomRightCornerMarginBox;
  887. }
  888. | LEFTTOP_SYM {
  889. $$ = CSSSelector::LeftTopMarginBox;
  890. }
  891. | LEFTMIDDLE_SYM {
  892. $$ = CSSSelector::LeftMiddleMarginBox;
  893. }
  894. | LEFTBOTTOM_SYM {
  895. $$ = CSSSelector::LeftBottomMarginBox;
  896. }
  897. | RIGHTTOP_SYM {
  898. $$ = CSSSelector::RightTopMarginBox;
  899. }
  900. | RIGHTMIDDLE_SYM {
  901. $$ = CSSSelector::RightMiddleMarginBox;
  902. }
  903. | RIGHTBOTTOM_SYM {
  904. $$ = CSSSelector::RightBottomMarginBox;
  905. }
  906. ;
  907. before_font_face_rule:
  908. /* empty */ {
  909. parser->markRuleHeaderStart(CSSRuleSourceData::FONT_FACE_RULE);
  910. }
  911. ;
  912. font_face:
  913. before_font_face_rule FONT_FACE_SYM at_rule_header_end_maybe_space
  914. '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
  915. $$ = parser->createFontFaceRule();
  916. }
  917. | before_font_face_rule FONT_FACE_SYM error invalid_block {
  918. $$ = 0;
  919. parser->popRuleData();
  920. }
  921. | before_font_face_rule FONT_FACE_SYM error ';' {
  922. $$ = 0;
  923. parser->popRuleData();
  924. }
  925. ;
  926. #if ENABLE_SHADOW_DOM
  927. before_host_rule:
  928. /* empty */ {
  929. parser->markRuleHeaderStart(CSSRuleSourceData::HOST_RULE);
  930. }
  931. ;
  932. host:
  933. before_host_rule HOST_SYM at_rule_header_end_maybe_space
  934. '{' at_rule_body_start maybe_space block_rule_list save_block {
  935. $$ = parser->createHostRule($7);
  936. }
  937. | before_host_rule HOST_SYM at_rule_header_end_maybe_space ';' {
  938. $$ = 0;
  939. parser->popRuleData();
  940. }
  941. ;
  942. #endif
  943. #if ENABLE_CSS_DEVICE_ADAPTATION
  944. before_viewport_rule:
  945. /* empty */ {
  946. parser->markViewportRuleBodyStart();
  947. parser->markRuleHeaderStart(CSSRuleSourceData::VIEWPORT_RULE);
  948. }
  949. ;
  950. viewport:
  951. before_viewport_rule WEBKIT_VIEWPORT_RULE_SYM at_rule_header_end_maybe_space
  952. '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
  953. $$ = parser->createViewportRule();
  954. parser->markViewportRuleBodyEnd();
  955. }
  956. | before_viewport_rule WEBKIT_VIEWPORT_RULE_SYM error invalid_block {
  957. $$ = 0;
  958. parser->popRuleData();
  959. parser->markViewportRuleBodyEnd();
  960. }
  961. | before_viewport_rule WEBKIT_VIEWPORT_RULE_SYM error ';' {
  962. $$ = 0;
  963. parser->popRuleData();
  964. parser->markViewportRuleBodyEnd();
  965. }
  966. ;
  967. #endif
  968. region_selector:
  969. selector_list {
  970. if ($1) {
  971. parser->setReusableRegionSelectorVector($1);
  972. $$ = parser->reusableRegionSelectorVector();
  973. }
  974. else
  975. $$ = 0;
  976. }
  977. ;
  978. before_region_rule:
  979. /* empty */ {
  980. parser->markRuleHeaderStart(CSSRuleSourceData::REGION_RULE);
  981. }
  982. ;
  983. region:
  984. before_region_rule WEBKIT_REGION_RULE_SYM WHITESPACE region_selector at_rule_header_end '{' at_rule_body_start maybe_space region_block_rule_list save_block {
  985. if ($4)
  986. $$ = parser->createRegionRule($4, $9);
  987. else {
  988. $$ = 0;
  989. parser->popRuleData();
  990. }
  991. }
  992. ;
  993. #if ENABLE_CSS_SHADERS
  994. before_filter_rule:
  995. /* empty */ {
  996. parser->markRuleHeaderStart(CSSRuleSourceData::FILTER_RULE);
  997. parser->m_inFilterRule = true;
  998. }
  999. ;
  1000. filter:
  1001. before_filter_rule WEBKIT_FILTER_RULE_SYM WHITESPACE IDENT at_rule_header_end_maybe_space
  1002. '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
  1003. parser->m_inFilterRule = false;
  1004. $$ = parser->createFilterRule($4);
  1005. }
  1006. ;
  1007. #endif
  1008. combinator:
  1009. '+' maybe_space { $$ = CSSSelector::DirectAdjacent; }
  1010. | '~' maybe_space { $$ = CSSSelector::IndirectAdjacent; }
  1011. | '>' maybe_space { $$ = CSSSelector::Child; }
  1012. ;
  1013. maybe_unary_operator:
  1014. unary_operator { $$ = $1; }
  1015. | { $$ = 1; }
  1016. ;
  1017. unary_operator:
  1018. '-' { $$ = -1; }
  1019. | '+' { $$ = 1; }
  1020. ;
  1021. maybe_space_before_declaration:
  1022. maybe_space {
  1023. parser->markPropertyStart();
  1024. }
  1025. ;
  1026. before_selector_list:
  1027. /* empty */ {
  1028. parser->markRuleHeaderStart(CSSRuleSourceData::STYLE_RULE);
  1029. parser->markSelectorStart();
  1030. }
  1031. ;
  1032. at_rule_header_end:
  1033. /* empty */ {
  1034. parser->markRuleHeaderEnd();
  1035. }
  1036. ;
  1037. at_selector_end:
  1038. /* empty */ {
  1039. parser->markSelectorEnd();
  1040. }
  1041. ;
  1042. ruleset:
  1043. before_selector_list selector_list at_selector_end at_rule_header_end '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
  1044. $$ = parser->createStyleRule($2);
  1045. }
  1046. ;
  1047. before_selector_group_item:
  1048. /* empty */ {
  1049. parser->markSelectorStart();
  1050. }
  1051. selector_list:
  1052. selector %prec UNIMPORTANT_TOK {
  1053. if ($1) {
  1054. $$ = parser->reusableSelectorVector();
  1055. $$->shrink(0);
  1056. $$->append(parser->sinkFloatingSelector($1));
  1057. parser->updateLastSelectorLineAndPosition();
  1058. }
  1059. }
  1060. | selector_list at_selector_end ',' maybe_space before_selector_group_item selector %prec UNIMPORTANT_TOK {
  1061. if ($1 && $6) {
  1062. $$ = $1;
  1063. $$->append(parser->sinkFloatingSelector($6));
  1064. parser->updateLastSelectorLineAndPosition();
  1065. } else
  1066. $$ = 0;
  1067. }
  1068. | selector_list error {
  1069. $$ = 0;
  1070. }
  1071. ;
  1072. selector_with_trailing_whitespace:
  1073. selector WHITESPACE {
  1074. $$ = $1;
  1075. }
  1076. ;
  1077. selector:
  1078. simple_selector {
  1079. $$ = $1;
  1080. }
  1081. | selector_with_trailing_whitespace
  1082. {
  1083. $$ = $1;
  1084. }
  1085. | selector_with_trailing_whitespace simple_selector
  1086. {
  1087. $$ = $2;
  1088. if (!$1)
  1089. $$ = 0;
  1090. else if ($$)
  1091. $$->appendTagHistory(CSSSelector::Descendant, parser->sinkFloatingSelector($1));
  1092. }
  1093. | selector combinator simple_selector {
  1094. $$ = $3;
  1095. if (!$1)
  1096. $$ = 0;
  1097. else if ($$)
  1098. $$->appendTagHistory($2, parser->sinkFloatingSelector($1));
  1099. }
  1100. | selector error {
  1101. $$ = 0;
  1102. }
  1103. ;
  1104. namespace_selector:
  1105. /* empty */ '|' { $$.clear(); }
  1106. | '*' '|' { static LChar star = '*'; $$.init(&star, 1); }
  1107. | IDENT '|' { $$ = $1; }
  1108. ;
  1109. simple_selector:
  1110. element_name {
  1111. $$ = parser->createFloatingSelectorWithTagName(QualifiedName(nullAtom, $1, parser->m_defaultNamespace));
  1112. }
  1113. | element_name specifier_list {
  1114. $$ = $2;
  1115. if ($$)
  1116. $$ = parser->rewriteSpecifiersWithElementName(nullAtom, $1, $$);
  1117. }
  1118. | specifier_list {
  1119. $$ = $1;
  1120. if ($$)
  1121. $$ = parser->rewriteSpecifiersWithNamespaceIfNeeded($$);
  1122. }
  1123. | namespace_selector element_name {
  1124. $$ = parser->createFloatingSelectorWithTagName(parser->determineNameInNamespace($1, $2));
  1125. }
  1126. | namespace_selector element_name specifier_list {
  1127. $$ = $3;
  1128. if ($$)
  1129. $$ = parser->rewriteSpecifiersWithElementName($1, $2, $$);
  1130. }
  1131. | namespace_selector specifier_list {
  1132. $$ = $2;
  1133. if ($$)
  1134. $$ = parser->rewriteSpecifiersWithElementName($1, starAtom, $$);
  1135. }
  1136. ;
  1137. simple_selector_list:
  1138. simple_selector %prec UNIMPORTANT_TOK {
  1139. if ($1) {
  1140. $$ = parser->createFloatingSelectorVector();
  1141. $$->append(parser->sinkFloatingSelector($1));
  1142. } else
  1143. $$ = 0;
  1144. }
  1145. | simple_selector_list maybe_space ',' maybe_space simple_selector %prec UNIMPORTANT_TOK {
  1146. if ($1 && $5) {
  1147. $$ = $1;
  1148. $$->append(parser->sinkFloatingSelector($5));
  1149. } else
  1150. $$ = 0;
  1151. }
  1152. | simple_selector_list error {
  1153. $$ = 0;
  1154. }
  1155. ;
  1156. element_name:
  1157. IDENT {
  1158. CSSParserString& str = $1;
  1159. if (parser->m_context.isHTMLDocument)
  1160. str.lower();
  1161. $$ = str;
  1162. }
  1163. | '*' {
  1164. static LChar star = '*';
  1165. $$.init(&star, 1);
  1166. }
  1167. ;
  1168. specifier_list:
  1169. specifier {
  1170. $$ = $1;
  1171. }
  1172. | specifier_list specifier {
  1173. if (!$2)
  1174. $$ = 0;
  1175. else if ($1)
  1176. $$ = parser->rewriteSpecifiers($1, $2);
  1177. }
  1178. | specifier_list error {
  1179. $$ = 0;
  1180. }
  1181. ;
  1182. specifier:
  1183. IDSEL {
  1184. $$ = parser->createFloatingSelector();
  1185. $$->setMatch(CSSSelector::Id);
  1186. if (parser->m_context.mode == CSSQuirksMode)
  1187. $1.lower();
  1188. $$->setValue($1);
  1189. }
  1190. | HEX {
  1191. if ($1[0] >= '0' && $1[0] <= '9') {
  1192. $$ = 0;
  1193. } else {
  1194. $$ = parser->createFloatingSelector();
  1195. $$->setMatch(CSSSelector::Id);
  1196. if (parser->m_context.mode == CSSQuirksMode)
  1197. $1.lower();
  1198. $$->setValue($1);
  1199. }
  1200. }
  1201. | class
  1202. | attrib
  1203. | pseudo
  1204. ;
  1205. class:
  1206. '.' IDENT {
  1207. $$ = parser->createFloatingSelector();
  1208. $$->setMatch(CSSSelector::Class);
  1209. if (parser->m_context.mode == CSSQuirksMode)
  1210. $2.lower();
  1211. $$->setValue($2);
  1212. }
  1213. ;
  1214. attr_name:
  1215. IDENT maybe_space {
  1216. CSSParserString& str = $1;
  1217. if (parser->m_context.isHTMLDocument)
  1218. str.lower();
  1219. $$ = str;
  1220. }
  1221. ;
  1222. attrib:
  1223. '[' maybe_space attr_name ']' {
  1224. $$ = parser->createFloatingSelector();
  1225. $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom));
  1226. $$->setMatch(CSSSelector::Set);
  1227. }
  1228. | '[' maybe_space attr_name match maybe_space ident_or_string maybe_space ']' {
  1229. $$ = parser->createFloatingSelector();
  1230. $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom));
  1231. $$->setMatch((CSSSelector::Match)$4);
  1232. $$->setValue($6);
  1233. }
  1234. | '[' maybe_space namespace_selector attr_name ']' {
  1235. $$ = parser->createFloatingSelector();
  1236. $$->setAttribute(parser->determineNameInNamespace($3, $4));
  1237. $$->setMatch(CSSSelector::Set);
  1238. }
  1239. | '[' maybe_space namespace_selector attr_name match maybe_space ident_or_string maybe_space ']' {
  1240. $$ = parser->createFloatingSelector();
  1241. $$->setAttribute(parser->determineNameInNamespace($3, $4));
  1242. $$->setMatch((CSSSelector::Match)$5);
  1243. $$->setValue($7);
  1244. }
  1245. ;
  1246. match:
  1247. '=' {
  1248. $$ = CSSSelector::Exact;
  1249. }
  1250. | INCLUDES {
  1251. $$ = CSSSelector::List;
  1252. }
  1253. | DASHMATCH {
  1254. $$ = CSSSelector::Hyphen;
  1255. }
  1256. | BEGINSWITH {
  1257. $$ = CSSSelector::Begin;
  1258. }
  1259. | ENDSWITH {
  1260. $$ = CSSSelector::End;
  1261. }
  1262. | CONTAINS {
  1263. $$ = CSSSelector::Contain;
  1264. }
  1265. ;
  1266. ident_or_string:
  1267. IDENT
  1268. | STRING
  1269. ;
  1270. pseudo_page:
  1271. ':' IDENT {
  1272. $$ = parser->createFloatingSelector();
  1273. $$->setMatch(CSSSelector::PagePseudoClass);
  1274. $2.lower();
  1275. $$->setValue($2);
  1276. CSSSelector::PseudoType type = $$->pseudoType();
  1277. if (type == CSSSelector::PseudoUnknown)
  1278. $$ = 0;
  1279. }
  1280. pseudo:
  1281. ':' IDENT {
  1282. $$ = parser->createFloatingSelector();
  1283. $$->setMatch(CSSSelector::PseudoClass);
  1284. $2.lower();
  1285. $$->setValue($2);
  1286. CSSSelector::PseudoType type = $$->pseudoType();
  1287. if (type == CSSSelector::PseudoUnknown)
  1288. $$ = 0;
  1289. }
  1290. | ':' ':' IDENT {
  1291. $$ = parser->createFloatingSelector();
  1292. $$->setMatch(CSSSelector::PseudoElement);
  1293. $3.lower();
  1294. $$->setValue($3);
  1295. // FIXME: This call is needed to force selector to compute the pseudoType early enough.
  1296. CSSSelector::PseudoType type = $$->pseudoType();
  1297. if (type == CSSSelector::PseudoUnknown)
  1298. $$ = 0;
  1299. }
  1300. #if ENABLE_VIDEO_TRACK
  1301. // used by ::cue(:past/:future)
  1302. | ':' ':' CUEFUNCTION maybe_space simple_selector_list maybe_space ')' {
  1303. if ($5) {
  1304. $$ = parser->createFloatingSelector();
  1305. $$->setMatch(CSSSelector::PseudoClass);
  1306. $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($5));
  1307. $$->setValue($3);
  1308. CSSSelector::PseudoType type = $$->pseudoType();
  1309. if (type != CSSSelector::PseudoCue)
  1310. $$ = 0;
  1311. } else
  1312. $$ = 0;
  1313. }
  1314. #endif
  1315. // use by :-webkit-any.
  1316. // FIXME: should we support generic selectors here or just simple_selectors?
  1317. // Use simple_selector_list for now to match -moz-any.
  1318. // See http://lists.w3.org/Archives/Public/www-style/2010Sep/0566.html for some
  1319. // related discussion with respect to :not.
  1320. | ':' ANYFUNCTION maybe_space simple_selector_list maybe_space ')' {
  1321. if ($4) {
  1322. $$ = parser->createFloatingSelector();
  1323. $$->setMatch(CSSSelector::PseudoClass);
  1324. $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($4));
  1325. $2.lower();
  1326. $$->setValue($2);
  1327. CSSSelector::PseudoType type = $$->pseudoType();
  1328. if (type != CSSSelector::PseudoAny)
  1329. $$ = 0;
  1330. } else
  1331. $$ = 0;
  1332. }
  1333. // used by :nth-*(ax+b)
  1334. | ':' FUNCTION maybe_space NTH maybe_space ')' {
  1335. $$ = parser->createFloatingSelector();
  1336. $$->setMatch(CSSSelector::PseudoClass);
  1337. $$->setArgument($4);
  1338. $$->setValue($2);
  1339. CSSSelector::PseudoType type = $$->pseudoType();
  1340. if (type == CSSSelector::PseudoUnknown)
  1341. $$ = 0;
  1342. }
  1343. // used by :nth-*
  1344. | ':' FUNCTION maybe_space maybe_unary_operator INTEGER maybe_space ')' {
  1345. $$ = parser->createFloatingSelector();
  1346. $$->setMatch(CSSSelector::PseudoClass);
  1347. $$->setArgument(String::number($4 * $5));
  1348. $$->setValue($2);
  1349. CSSSelector::PseudoType type = $$->pseudoType();
  1350. if (type == CSSSelector::PseudoUnknown)
  1351. $$ = 0;
  1352. }
  1353. // used by :nth-*(odd/even) and :lang
  1354. | ':' FUNCTION maybe_space IDENT maybe_space ')' {
  1355. $$ = parser->createFloatingSelector();
  1356. $$->setMatch(CSSSelector::PseudoClass);
  1357. $$->setArgument($4);
  1358. $2.lower();
  1359. $$->setValue($2);
  1360. CSSSelector::PseudoType type = $$->pseudoType();
  1361. if (type == CSSSelector::PseudoUnknown)
  1362. $$ = 0;
  1363. else if (type == CSSSelector::PseudoNthChild ||
  1364. type == CSSSelector::PseudoNthOfType ||
  1365. type == CSSSelector::PseudoNthLastChild ||
  1366. type == CSSSelector::PseudoNthLastOfType) {
  1367. if (!isValidNthToken($4))
  1368. $$ = 0;
  1369. }
  1370. }
  1371. // used by :not
  1372. | ':' NOTFUNCTION maybe_space simple_selector maybe_space ')' {
  1373. if (!$4 || !$4->isSimple())
  1374. $$ = 0;
  1375. else {
  1376. $$ = parser->createFloatingSelector();
  1377. $$->setMatch(CSSSelector::PseudoClass);
  1378. Vector<OwnPtr<CSSParserSelector> > selectorVector;
  1379. selectorVector.append(parser->sinkFloatingSelector($4));
  1380. $$->adoptSelectorVector(selectorVector);
  1381. $2.lower();
  1382. $$->setValue($2);
  1383. }
  1384. }
  1385. ;
  1386. declaration_list:
  1387. /* empty */ { $$ = false; }
  1388. | declaration {
  1389. $$ = $1;
  1390. }
  1391. | decl_list declaration {
  1392. $$ = $1;
  1393. if ( $2 )
  1394. $$ = $2;
  1395. }
  1396. | decl_list {
  1397. $$ = $1;
  1398. }
  1399. | decl_list_recovery {
  1400. $$ = false;
  1401. }
  1402. | decl_list decl_list_recovery {
  1403. $$ = $1;
  1404. }
  1405. ;
  1406. decl_list:
  1407. declaration ';' maybe_space {
  1408. parser->markPropertyStart();
  1409. $$ = $1;
  1410. }
  1411. | decl_list_recovery ';' maybe_space {
  1412. parser->markPropertyStart();
  1413. $$ = false;
  1414. }
  1415. | decl_list declaration ';' maybe_space {
  1416. parser->markPropertyStart();
  1417. $$ = $1;
  1418. if ($2)
  1419. $$ = $2;
  1420. }
  1421. | decl_list decl_list_recovery ';' maybe_space {
  1422. parser->markPropertyStart();
  1423. $$ = $1;
  1424. }
  1425. ;
  1426. decl_list_recovery:
  1427. error error_location error_recovery {
  1428. parser->syntaxError($2, CSSParser::PropertyDeclarationError);
  1429. }
  1430. ;
  1431. declaration:
  1432. VAR_DEFINITION maybe_space ':' maybe_space expr prio {
  1433. #if ENABLE_CSS_VARIABLES
  1434. parser->storeVariableDeclaration($1, parser->sinkFloatingValueList($5), $6);
  1435. $$ = true;
  1436. parser->markPropertyEnd($6, true);
  1437. #else
  1438. $$ = false;
  1439. #endif
  1440. }
  1441. |
  1442. property ':' maybe_space expr prio {
  1443. $$ = false;
  1444. bool isPropertyParsed = false;
  1445. if ($1 && $4) {
  1446. parser->m_valueList = parser->sinkFloatingValueList($4);
  1447. int oldParsedProperties = parser->m_parsedProperties.size();
  1448. $$ = parser->parseValue(static_cast<CSSPropertyID>($1), $5);
  1449. if (!$$)
  1450. parser->rollbackLastProperties(parser->m_parsedProperties.size() - oldParsedProperties);
  1451. else
  1452. isPropertyParsed = true;
  1453. parser->m_valueList = nullptr;
  1454. }
  1455. parser->markPropertyEnd($5, isPropertyParsed);
  1456. }
  1457. |
  1458. property declaration_recovery {
  1459. $$ = false;
  1460. }
  1461. |
  1462. property ':' maybe_space expr prio declaration_recovery {
  1463. /* When we encounter something like p {color: red !important fail;} we should drop the declaration */
  1464. parser->markPropertyEnd(false, false);
  1465. $$ = false;
  1466. }
  1467. |
  1468. IMPORTANT_SYM maybe_space declaration_recovery {
  1469. /* Handle this case: div { text-align: center; !important } Just reduce away the stray !important. */
  1470. $$ = false;
  1471. }
  1472. |
  1473. property ':' maybe_space declaration_recovery {
  1474. /* if we come across rules with invalid values like this case: p { weight: *; }, just discard the rule */
  1475. parser->markPropertyEnd(false, false);
  1476. $$ = false;
  1477. }
  1478. ;
  1479. declaration_recovery:
  1480. error error_location error_recovery {
  1481. parser->syntaxError($2);
  1482. }
  1483. ;
  1484. property:
  1485. IDENT maybe_space {
  1486. $$ = cssPropertyID($1);
  1487. }
  1488. ;
  1489. prio:
  1490. IMPORTANT_SYM maybe_space { $$ = true; }
  1491. | /* empty */ { $$ = false; }
  1492. ;
  1493. expr:
  1494. term {
  1495. $$ = parser->createFloatingValueList();
  1496. $$->addValue(parser->sinkFloatingValue($1));
  1497. }
  1498. | expr operator term {
  1499. $$ = $1;
  1500. if ($$) {
  1501. if ($2) {
  1502. CSSParserValue v;
  1503. v.id = 0;
  1504. v.unit = CSSParserValue::Operator;
  1505. v.iValue = $2;
  1506. $$->addValue(v);
  1507. }
  1508. $$->addValue(parser->sinkFloatingValue($3));
  1509. }
  1510. }
  1511. | expr expr_recovery {
  1512. $$ = 0;
  1513. }
  1514. ;
  1515. expr_recovery:
  1516. error error_location error_recovery
  1517. ;
  1518. operator:
  1519. '/' maybe_space {
  1520. $$ = '/';
  1521. }
  1522. | ',' maybe_space {
  1523. $$ = ',';
  1524. }
  1525. | /* empty */ {
  1526. $$ = 0;
  1527. }
  1528. ;
  1529. term:
  1530. unary_term maybe_space { $$ = $1; }
  1531. | unary_operator unary_term maybe_space { $$ = $2; $$.fValue *= $1; }
  1532. | STRING maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_STRING; }
  1533. | IDENT maybe_space {
  1534. $$.id = cssValueKeywordID($1);
  1535. $$.unit = CSSPrimitiveValue::CSS_IDENT;
  1536. $$.string = $1;
  1537. }
  1538. /* We might need to actually parse the number from a dimension, but we can't just put something that uses $$.string into unary_term. */
  1539. | DIMEN maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_DIMENSION; }
  1540. | unary_operator DIMEN maybe_space { $$.id = 0; $$.string = $2; $$.unit = CSSPrimitiveValue::CSS_DIMENSION; }
  1541. | URI maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_URI; }
  1542. | UNICODERANGE maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_UNICODE_RANGE; }
  1543. | HEX maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_PARSER_HEXCOLOR; }
  1544. | '#' maybe_space { $$.id = 0; $$.string = CSSParserString(); $$.unit = CSSPrimitiveValue::CSS_PARSER_HEXCOLOR; } /* Handle error case: "color: #;" */
  1545. | VARFUNCTION maybe_space IDENT closing_parenthesis maybe_space {
  1546. #if ENABLE_CSS_VARIABLES
  1547. $$.id = 0;
  1548. $$.string = $3;
  1549. $$.unit = CSSPrimitiveValue::CSS_VARIABLE_NAME;
  1550. #endif
  1551. }
  1552. /* FIXME: according to the specs a function can have a unary_operator in front. I know no case where this makes sense */
  1553. | function maybe_space {
  1554. $$ = $1;
  1555. }
  1556. | calc_function maybe_space {
  1557. $$ = $1;
  1558. }
  1559. | min_or_max_function maybe_space {
  1560. $$ = $1;
  1561. }
  1562. | '%' maybe_space { /* Handle width: %; */
  1563. $$.id = 0; $$.unit = 0;
  1564. }
  1565. ;
  1566. unary_term:
  1567. INTEGER { $$.id = 0; $$.isInt = true; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_NUMBER; }
  1568. | FLOATTOKEN { $$.id = 0; $$.isInt = false; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_NUMBER; }
  1569. | PERCENTAGE { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PERCENTAGE; }
  1570. | PXS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PX; }
  1571. | CMS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_CM; }
  1572. | MMS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_MM; }
  1573. | INS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_IN; }
  1574. | PTS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PT; }
  1575. | PCS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PC; }
  1576. | DEGS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DEG; }
  1577. | RADS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_RAD; }
  1578. | GRADS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_GRAD; }
  1579. | TURNS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_TURN; }
  1580. | MSECS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_MS; }
  1581. | SECS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_S; }
  1582. | HERTZ { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_HZ; }
  1583. | KHERTZ { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_KHZ; }
  1584. | EMS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_EMS; }
  1585. | QEMS { $$.id = 0; $$.fValue = $1; $$.unit = CSSParserValue::Q_EMS; }
  1586. | EXS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_EXS; }
  1587. | REMS {
  1588. $$.id = 0;
  1589. $$.fValue = $1;
  1590. $$.unit = CSSPrimitiveValue::CSS_REMS;
  1591. if (parser->m_styleSheet)
  1592. parser->m_styleSheet->parserSetUsesRemUnits(true);
  1593. }
  1594. | CHS { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_CHS; }
  1595. | VW { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VW; }
  1596. | VH { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VH; }
  1597. | VMIN { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VMIN; }
  1598. | VMAX { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_VMAX; }
  1599. | DPPX { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DPPX; }
  1600. | DPI { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DPI; }
  1601. | DPCM { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DPCM; }
  1602. ;
  1603. function:
  1604. FUNCTION maybe_space expr closing_parenthesis {
  1605. CSSParserFunction* f = parser->createFloatingFunction();
  1606. f->name = $1;
  1607. f->args = parser->sinkFloatingValueList($3);
  1608. $$.id = 0;
  1609. $$.unit = CSSParserValue::Function;
  1610. $$.function = f;
  1611. } |
  1612. FUNCTION maybe_space closing_parenthesis {
  1613. CSSParserFunction* f = parser->createFloatingFunction();
  1614. f->name = $1;
  1615. CSSParserValueList* valueList = parser->createFloatingValueList();
  1616. f->args = parser->sinkFloatingValueList(valueList);
  1617. $$.id = 0;
  1618. $$.unit = CSSParserValue::Function;
  1619. $$.function = f;
  1620. } |
  1621. FUNCTION maybe_space expr_recovery closing_parenthesis {
  1622. CSSParserFunction* f = parser->createFloatingFunction();
  1623. f->name = $1;
  1624. f->args = nullptr;
  1625. $$.id = 0;
  1626. $$.unit = CSSParserValue::Function;
  1627. $$.function = f;
  1628. }
  1629. ;
  1630. calc_func_term:
  1631. unary_term { $$ = $1; }
  1632. | VARFUNCTION maybe_space IDENT closing_parenthesis {
  1633. #if ENABLE_CSS_VARIABLES
  1634. $$.id = 0;
  1635. $$.string = $3;
  1636. $$.unit = CSSPrimitiveValue::CSS_VARIABLE_NAME;
  1637. #endif
  1638. }
  1639. | unary_operator unary_term { $$ = $2; $$.fValue *= $1; }
  1640. ;
  1641. calc_func_operator:
  1642. WHITESPACE '+' WHITESPACE {
  1643. $$ = '+';
  1644. }
  1645. | WHITESPACE '-' WHITESPACE {
  1646. $$ = '-';
  1647. }
  1648. | calc_maybe_space '*' maybe_space {
  1649. $$ = '*';
  1650. }
  1651. | calc_maybe_space '/' maybe_space {
  1652. $$ = '/';
  1653. }
  1654. ;
  1655. calc_maybe_space:
  1656. /* empty */
  1657. | WHITESPACE
  1658. ;
  1659. calc_func_paren_expr:
  1660. '(' maybe_space calc_func_expr calc_maybe_space closing_parenthesis {
  1661. if ($3) {
  1662. $$ = $3;
  1663. CSSParserValue v;
  1664. v.id = 0;
  1665. v.unit = CSSParserValue::Operator;
  1666. v.iValue = '(';
  1667. $$->insertValueAt(0, v);
  1668. v.iValue = ')';
  1669. $$->addValue(v);
  1670. } else
  1671. $$ = 0;
  1672. }
  1673. ;
  1674. calc_func_expr:
  1675. calc_func_term {
  1676. $$ = parser->createFloatingValueList();
  1677. $$->addValue(parser->sinkFloatingValue($1));
  1678. }
  1679. | calc_func_expr calc_func_operator calc_func_term {
  1680. if ($1 && $2) {
  1681. $$ = $1;
  1682. CSSParserValue v;
  1683. v.id = 0;
  1684. v.unit = CSSParserValue::Operator;
  1685. v.iValue = $2;
  1686. $$->addValue(v);
  1687. $$->addValue(parser->sinkFloatingValue($3));
  1688. } else
  1689. $$ = 0;
  1690. }
  1691. | calc_func_expr calc_func_operator calc_func_paren_expr {
  1692. if ($1 && $2 && $3) {
  1693. $$ = $1;
  1694. CSSParserValue v;
  1695. v.id = 0;
  1696. v.unit = CSSParserValue::Operator;
  1697. v.iValue = $2;
  1698. $$->addValue(v);
  1699. $$->extend(*($3));
  1700. } else
  1701. $$ = 0;
  1702. }
  1703. | calc_func_paren_expr
  1704. | calc_func_expr error {
  1705. $$ = 0;
  1706. }
  1707. ;
  1708. calc_func_expr_list:
  1709. calc_func_expr calc_maybe_space {
  1710. $$ = $1;
  1711. }
  1712. | calc_func_expr_list ',' maybe_space calc_func_expr calc_maybe_space {
  1713. if ($1 && $4) {
  1714. $$ = $1;
  1715. CSSParserValue v;
  1716. v.id = 0;
  1717. v.unit = CSSParserValue::Operator;
  1718. v.iValue = ',';
  1719. $$->addValue(v);
  1720. $$->extend(*($4));
  1721. } else
  1722. $$ = 0;
  1723. }
  1724. ;
  1725. calc_function:
  1726. CALCFUNCTION maybe_space calc_func_expr calc_maybe_space closing_parenthesis {
  1727. CSSParserFunction* f = parser->createFloatingFunction();
  1728. f->name = $1;
  1729. f->args = parser->sinkFloatingValueList($3);
  1730. $$.id = 0;
  1731. $$.unit = CSSParserValue::Function;
  1732. $$.function = f;
  1733. }
  1734. | CALCFUNCTION maybe_space expr_recovery closing_parenthesis {
  1735. YYERROR;
  1736. }
  1737. ;
  1738. min_or_max:
  1739. MINFUNCTION {
  1740. $$ = $1;
  1741. }
  1742. | MAXFUNCTION {
  1743. $$ = $1;
  1744. }
  1745. ;
  1746. min_or_max_function:
  1747. min_or_max maybe_space calc_func_expr_list closing_parenthesis {
  1748. CSSParserFunction* f = parser->createFloatingFunction();
  1749. f->name = $1;
  1750. f->args = parser->sinkFloatingValueList($3);
  1751. $$.id = 0;
  1752. $$.unit = CSSParserValue::Function;
  1753. $$.function = f;
  1754. }
  1755. | min_or_max maybe_space expr_recovery closing_parenthesis {
  1756. YYERROR;
  1757. }
  1758. ;
  1759. /* error handling rules */
  1760. save_block:
  1761. closing_brace {
  1762. $$ = 0;
  1763. }
  1764. | error closing_brace {
  1765. $$ = 0;
  1766. }
  1767. ;
  1768. invalid_at:
  1769. ATKEYWORD error invalid_block {
  1770. $$ = 0;
  1771. }
  1772. | ATKEYWORD error ';' {
  1773. $$ = 0;
  1774. }
  1775. ;
  1776. invalid_rule:
  1777. error invalid_block {
  1778. $$ = 0;
  1779. }
  1780. /*
  1781. Seems like the two rules below are trying too much and violating
  1782. http://www.hixie.ch/tests/evil/mixed/csserrorhandling.html
  1783. | error ';' {
  1784. $$ = 0;
  1785. }
  1786. | error '}' {
  1787. $$ = 0;
  1788. }
  1789. */
  1790. ;
  1791. invalid_block:
  1792. '{' error invalid_block_list error closing_brace {
  1793. parser->invalidBlockHit();
  1794. }
  1795. | '{' error closing_brace {
  1796. parser->invalidBlockHit();
  1797. }
  1798. ;
  1799. invalid_block_list:
  1800. invalid_block
  1801. | invalid_block_list error invalid_block
  1802. ;
  1803. error_location: {
  1804. $$ = parser->currentLocation();
  1805. }
  1806. ;
  1807. error_recovery:
  1808. /* empty */
  1809. | error_recovery invalid_block
  1810. | error_recovery error
  1811. ;
  1812. %%