mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Move property value parsing from longhand/shorthand ID into separate methods.
This commit is contained in:
parent
54f1325a49
commit
42813bc813
1 changed files with 30 additions and 22 deletions
|
@ -624,6 +624,20 @@ impl LonghandId {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_value<'i, 't>(&self, context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<PropertyDeclaration, ParseError<'i>> {
|
||||
match *self {
|
||||
% for property in data.longhands:
|
||||
LonghandId::${property.camel_case} => {
|
||||
% if not property.derived_from:
|
||||
longhands::${property.ident}::parse_declared(context, input)
|
||||
% else:
|
||||
Err(PropertyDeclarationParseError::UnknownProperty.into())
|
||||
% endif
|
||||
}
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
|
||||
/// If this is a logical property, return the corresponding physical one in the given writing mode.
|
||||
/// Otherwise, return unchanged.
|
||||
|
@ -844,6 +858,18 @@ impl ShorthandId {
|
|||
% endfor
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_into<'i, 't>(&self, declarations: &mut SourcePropertyDeclaration,
|
||||
context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<(), ParseError<'i>> {
|
||||
match *self {
|
||||
% for shorthand in data.shorthands:
|
||||
ShorthandId::${shorthand.camel_case} => {
|
||||
shorthands::${shorthand.ident}::parse_into(declarations, context, input)
|
||||
}
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Servo's representation of a declared value for a given `T`, which is the
|
||||
|
@ -1526,19 +1552,8 @@ impl PropertyDeclaration {
|
|||
}).or_else(|_| {
|
||||
input.look_for_var_functions();
|
||||
let start = input.position();
|
||||
input.parse_entirely(|input| {
|
||||
match id {
|
||||
% for property in data.longhands:
|
||||
LonghandId::${property.camel_case} => {
|
||||
% if not property.derived_from:
|
||||
longhands::${property.ident}::parse_declared(context, input)
|
||||
% else:
|
||||
Err(PropertyDeclarationParseError::UnknownProperty)
|
||||
% endif
|
||||
}
|
||||
% endfor
|
||||
}
|
||||
}).or_else(|_| {
|
||||
input.parse_entirely(|input| id.parse_value(context, input))
|
||||
.or_else(|_| {
|
||||
while let Ok(_) = input.next() {} // Look for var() after the error.
|
||||
if input.seen_var_functions() {
|
||||
input.reset(start);
|
||||
|
@ -1573,15 +1588,8 @@ impl PropertyDeclaration {
|
|||
} else {
|
||||
input.look_for_var_functions();
|
||||
let start = input.position();
|
||||
input.parse_entirely(|input| {
|
||||
match id {
|
||||
% for shorthand in data.shorthands:
|
||||
ShorthandId::${shorthand.camel_case} => {
|
||||
shorthands::${shorthand.ident}::parse_into(declarations, context, input)
|
||||
}
|
||||
% endfor
|
||||
}
|
||||
}).or_else(|_| {
|
||||
input.parse_entirely(|input| id.parse_into(declarations, context, input))
|
||||
.or_else(|_| {
|
||||
while let Ok(_) = input.next() {} // Look for var() after the error.
|
||||
if input.seen_var_functions() {
|
||||
input.reset(start);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue