📄 cssgrammar.y
字号:
CSSParser* p = static_cast<CSSParser*>(parser); Document* doc = p->document(); if (doc && doc->isHTMLDocument()) str.lower(); $$ = str; } ;attrib: '[' maybe_space attr_name ']' { $$ = static_cast<CSSParser*>(parser)->createFloatingSelector(); $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom)); $$->m_match = CSSSelector::Set; } | '[' maybe_space attr_name match maybe_space ident_or_string maybe_space ']' { $$ = static_cast<CSSParser*>(parser)->createFloatingSelector(); $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom)); $$->m_match = (CSSSelector::Match)$4; $$->m_value = $6; } | '[' maybe_space namespace_selector attr_name ']' { AtomicString namespacePrefix = $3; CSSParser* p = static_cast<CSSParser*>(parser); $$ = p->createFloatingSelector(); $$->setAttribute(QualifiedName(namespacePrefix, $4, p->m_styleSheet->determineNamespace(namespacePrefix))); $$->m_match = CSSSelector::Set; } | '[' maybe_space namespace_selector attr_name match maybe_space ident_or_string maybe_space ']' { AtomicString namespacePrefix = $3; CSSParser* p = static_cast<CSSParser*>(parser); $$ = p->createFloatingSelector(); $$->setAttribute(QualifiedName(namespacePrefix, $4, p->m_styleSheet->determineNamespace(namespacePrefix))); $$->m_match = (CSSSelector::Match)$5; $$->m_value = $7; } ;match: '=' { $$ = CSSSelector::Exact; } | INCLUDES { $$ = CSSSelector::List; } | DASHMATCH { $$ = CSSSelector::Hyphen; } | BEGINSWITH { $$ = CSSSelector::Begin; } | ENDSWITH { $$ = CSSSelector::End; } | CONTAINS { $$ = CSSSelector::Contain; } ;ident_or_string: IDENT | STRING ;pseudo: ':' IDENT { $$ = static_cast<CSSParser*>(parser)->createFloatingSelector(); $$->m_match = CSSSelector::PseudoClass; $2.lower(); $$->m_value = $2; CSSSelector::PseudoType type = $$->pseudoType(); if (type == CSSSelector::PseudoUnknown) $$ = 0; else if (type == CSSSelector::PseudoEmpty || type == CSSSelector::PseudoFirstChild || type == CSSSelector::PseudoFirstOfType || type == CSSSelector::PseudoLastChild || type == CSSSelector::PseudoLastOfType || type == CSSSelector::PseudoOnlyChild || type == CSSSelector::PseudoOnlyOfType) { CSSParser* p = static_cast<CSSParser*>(parser); Document* doc = p->document(); if (doc) doc->setUsesSiblingRules(true); } else if (type == CSSSelector::PseudoFirstLine) { CSSParser* p = static_cast<CSSParser*>(parser); if (Document* doc = p->document()) doc->setUsesFirstLineRules(true); } else if (type == CSSSelector::PseudoBefore || type == CSSSelector::PseudoAfter) { CSSParser* p = static_cast<CSSParser*>(parser); if (Document* doc = p->document()) doc->setUsesBeforeAfterRules(true); } } | ':' ':' IDENT { $$ = static_cast<CSSParser*>(parser)->createFloatingSelector(); $$->m_match = CSSSelector::PseudoElement; $3.lower(); $$->m_value = $3; CSSSelector::PseudoType type = $$->pseudoType(); if (type == CSSSelector::PseudoUnknown) $$ = 0; else if (type == CSSSelector::PseudoFirstLine) { CSSParser* p = static_cast<CSSParser*>(parser); if (Document* doc = p->document()) doc->setUsesFirstLineRules(true); } else if (type == CSSSelector::PseudoBefore || type == CSSSelector::PseudoAfter) { CSSParser* p = static_cast<CSSParser*>(parser); if (Document* doc = p->document()) doc->setUsesBeforeAfterRules(true); } } // used by :nth-*(ax+b) | ':' FUNCTION NTH ')' { CSSParser *p = static_cast<CSSParser*>(parser); $$ = p->createFloatingSelector(); $$->m_match = CSSSelector::PseudoClass; $$->setArgument($3); $$->m_value = $2; CSSSelector::PseudoType type = $$->pseudoType(); if (type == CSSSelector::PseudoUnknown) $$ = 0; else if (type == CSSSelector::PseudoNthChild || type == CSSSelector::PseudoNthOfType || type == CSSSelector::PseudoNthLastChild || type == CSSSelector::PseudoNthLastOfType) { if (p->document()) p->document()->setUsesSiblingRules(true); } } // used by :nth-* | ':' FUNCTION INTEGER ')' { CSSParser *p = static_cast<CSSParser*>(parser); $$ = p->createFloatingSelector(); $$->m_match = CSSSelector::PseudoClass; $$->setArgument(String::number($3)); $$->m_value = $2; CSSSelector::PseudoType type = $$->pseudoType(); if (type == CSSSelector::PseudoUnknown) $$ = 0; else if (type == CSSSelector::PseudoNthChild || type == CSSSelector::PseudoNthOfType || type == CSSSelector::PseudoNthLastChild || type == CSSSelector::PseudoNthLastOfType) { if (p->document()) p->document()->setUsesSiblingRules(true); } } // used by :nth-*(odd/even) and :lang | ':' FUNCTION IDENT ')' { CSSParser *p = static_cast<CSSParser*>(parser); $$ = p->createFloatingSelector(); $$->m_match = CSSSelector::PseudoClass; $$->setArgument($3); $2.lower(); $$->m_value = $2; CSSSelector::PseudoType type = $$->pseudoType(); if (type == CSSSelector::PseudoUnknown) $$ = 0; else if (type == CSSSelector::PseudoNthChild || type == CSSSelector::PseudoNthOfType || type == CSSSelector::PseudoNthLastChild || type == CSSSelector::PseudoNthLastOfType) { if (p->document()) p->document()->setUsesSiblingRules(true); } } // used by :not | ':' NOTFUNCTION maybe_space simple_selector maybe_space ')' { if (!$4 || $4->simpleSelector() || $4->tagHistory()) $$ = 0; else { CSSParser* p = static_cast<CSSParser*>(parser); $$ = p->createFloatingSelector(); $$->m_match = CSSSelector::PseudoClass; $$->setSimpleSelector(p->sinkFloatingSelector($4)); $2.lower(); $$->m_value = $2; } } ;declaration_list: declaration { $$ = $1; } | decl_list declaration { $$ = $1; if ( $2 ) $$ = $2; } | decl_list { $$ = $1; } | error invalid_block_list error { $$ = false; } | error { $$ = false; } | decl_list error { $$ = $1; } | decl_list invalid_block_list { $$ = $1; } ;decl_list: declaration ';' maybe_space { $$ = $1; } | declaration invalid_block_list ';' maybe_space { $$ = false; } | error ';' maybe_space { $$ = false; } | error invalid_block_list error ';' maybe_space { $$ = false; } | decl_list declaration ';' maybe_space { $$ = $1; if ($2) $$ = $2; } | decl_list error ';' maybe_space { $$ = $1; } | decl_list error invalid_block_list error ';' maybe_space { $$ = $1; } ;declaration: property ':' maybe_space expr prio { $$ = false; CSSParser* p = static_cast<CSSParser*>(parser); if ($1 && $4) { p->m_valueList = p->sinkFloatingValueList($4); int oldParsedProperties = p->m_numParsedProperties; $$ = p->parseValue($1, $5); if (!$$) p->rollbackLastProperties(p->m_numParsedProperties - oldParsedProperties); delete p->m_valueList; p->m_valueList = 0; } } | variable_reference maybe_space { CSSParser* p = static_cast<CSSParser*>(parser); p->m_valueList = new CSSParserValueList; p->m_valueList->addValue(p->sinkFloatingValue($1)); int oldParsedProperties = p->m_numParsedProperties; $$ = p->parseValue(CSSPropertyWebkitVariableDeclarationBlock, false); if (!$$) p->rollbackLastProperties(p->m_numParsedProperties - oldParsedProperties); delete p->m_valueList; p->m_valueList = 0; } | property error { $$ = false; } | property ':' maybe_space error expr prio { /* The default movable type template has letter-spacing: .none; Handle this by looking for error tokens at the start of an expr, recover the expr and then treat as an error, cleaning up and deleting the shifted expr. */ $$ = false; } | property ':' maybe_space expr prio error { /* When we encounter something like p {color: red !important fail;} we should drop the declaration */ $$ = false; } | IMPORTANT_SYM maybe_space { /* Handle this case: div { text-align: center; !important } Just reduce away the stray !important. */ $$ = false; } | property ':' maybe_space { /* div { font-family: } Just reduce away this property with no value. */ $$ = false; } | property ':' maybe_space error { /* if we come across rules with invalid values like this case: p { weight: *; }, just discard the rule */ $$ = false; } | property invalid_block { /* if we come across: div { color{;color:maroon} }, ignore everything within curly brackets */ $$ = false; } ;property: IDENT maybe_space { $$ = cssPropertyID($1); } ;prio: IMPORTANT_SYM maybe_space { $$ = true; } | /* empty */ { $$ = false; } ;expr: term { CSSParser* p = static_cast<CSSParser*>(parser); $$ = p->createFloatingValueList(); $$->addValue(p->sinkFloatingValue($1)); } | expr operator term { CSSParser* p = static_cast<CSSParser*>(parser); $$ = $1; if ($$) { if ($2) { CSSParserValue v; v.id = 0; v.unit = CSSParserValue::Operator; v.iValue = $2; $$->addValue(v); } $$->addValue(p->sinkFloatingValue($3)); } } | expr error { $$ = 0; } ;operator: '/' maybe_space { $$ = '/'; } | ',' maybe_space { $$ = ','; } | /* empty */ { $$ = 0; } ;term: unary_term { $$ = $1; } | unary_operator unary_term { $$ = $2; $$.fValue *= $1; } | STRING maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_STRING; } | IDENT maybe_space { $$.id = cssValueKeywordID($1); $$.unit = CSSPrimitiveValue::CSS_IDENT; $$.string = $1; } /* We might need to actually parse the number from a dimension, but we can't just put something that uses $$.string into unary_term. */ | DIMEN maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_DIMENSION; } | unary_operator DIMEN maybe_space { $$.id = 0; $$.string = $2; $$.unit = CSSPrimitiveValue::CSS_DIMENSION; } | URI maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_URI; } | UNICODERANGE maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_UNICODE_RANGE; } | hexcolor { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_PARSER_HEXCOLOR; } | '#' maybe_space { $$.id = 0; $$.string = CSSParserString(); $$.unit = CSSPrimitiveValue::CSS_PARSER_HEXCOLOR; } /* Handle error case: "color: #;" */ /* FIXME: according to the specs a function can have a unary_operator in front. I know no case where this makes sense */ | function { $$ = $1; } | variable_reference maybe_space { $$ = $1; } | '%' maybe_space {} /* Handle width: %; */ ;unary_term: INTEGER maybe_space { $$.id = 0; $$.isInt = true; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_NUMBER; } | FLOATTOKEN maybe_space { $$.id = 0; $$.isInt = false; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_NUMBER; } | PERCENTAGE maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PERCENTAGE; } | PXS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PX; } | CMS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_CM; } | MMS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_MM; } | INS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_IN; } | PTS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PT; } | PCS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_PC; } | DEGS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_DEG; } | RADS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_RAD; } | GRADS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_GRAD; } | TURNS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_TURN; } | MSECS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_MS; } | SECS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_S; } | HERZ maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_HZ; } | KHERZ maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_KHZ; } | EMS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_EMS; } | QEMS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSParserValue::Q_EMS; } | EXS maybe_space { $$.id = 0; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_EXS; } ;variable_reference: VARCALL { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_PARSER_VARIABLE_FUNCTION_SYNTAX; } ;function: FUNCTION maybe_space expr ')' maybe_space { CSSParser* p = static_cast<CSSParser*>(parser); CSSParserFunction* f = p->createFloatingFunction(); f->name = $1; f->args = p->sinkFloatingValueList($3); $$.id = 0; $$.unit = CSSParserValue::Function; $$.function = f; } | FUNCTION maybe_space error { CSSParser* p = static_cast<CSSParser*>(parser); CSSParserFunction* f = p->createFloatingFunction(); f->name = $1; f->args = 0; $$.id = 0; $$.unit = CSSParserValue::Function; $$.function = f; } ;/* * There is a constraint on the color that it must * have either 3 or 6 hex-digits (i.e., [0-9a-fA-F]) * after the "#"; e.g., "#000" is OK, but "#abcd" is not. */hexcolor: HEX maybe_space { $$ = $1; } | IDSEL maybe_space { $$ = $1; } ;/* error handling rules */save_block: closing_brace { $$ = 0; } | error closing_brace { $$ = 0; } ;invalid_at: ATKEYWORD error invalid_block { $$ = 0; } | ATKEYWORD error ';' { $$ = 0; } ;invalid_at_list: invalid_at maybe_sgml | invalid_at_list invalid_at maybe_sgml ;invalid_import: import { $$ = 0; } ;invalid_media: media { $$ = 0; } ;invalid_rule: error invalid_block { $$ = 0; }/* Seems like the two rules below are trying too much and violating http://www.hixie.ch/tests/evil/mixed/csserrorhandling.html | error ';' { $$ = 0; } | error '}' { $$ = 0; }*/ ;invalid_block: '{' error invalid_block_list error closing_brace | '{' error closing_brace ;invalid_block_list: invalid_block | invalid_block_list error invalid_block;%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -