Skip to content

Commit

Permalink
Implement trailing commas in parameters and arguments
Browse files Browse the repository at this point in the history
Trailing commas in parameters and arguments was introduced in 3.5.

Fixes sass#2070
Spec sass/sass-spec#1090
  • Loading branch information
xzyfer committed Mar 9, 2017
1 parent 5cfdd12 commit 3d73948
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,22 +385,27 @@ namespace Sass {

Parameters_Obj Parser::parse_parameters()
{
std::string name(lexed);
Position position = after_token;
Parameters_Obj params = SASS_MEMORY_NEW(Parameters, pstate);
if (lex_css< exactly<'('> >()) {
// if there's anything there at all
if (!peek_css< exactly<')'> >()) {
do params->append(parse_parameter());
while (lex_css< exactly<','> >());
do {
if (peek< exactly<')'> >()) break;
params->append(parse_parameter());
} while (lex_css< exactly<','> >());
}
if (!lex_css< exactly<')'> >()) {
css_error("Invalid CSS", " after ", ": expected \")\", was ");
}
if (!lex_css< exactly<')'> >()) error("expected a variable name (e.g. $x) or ')' for the parameter list for " + name, position);
}
return params;
}

Parameter_Obj Parser::parse_parameter()
{
if (peek< alternatives< exactly<','>, exactly< '{' >, exactly<';'> > >()) {
css_error("Invalid CSS", " after ", ": expected variable (e.g. $foo), was ");
}
while (lex< alternatives < spaces, block_comment > >());
lex < variable >();
std::string name(Util::normalize_underscores(lexed));
Expand All @@ -420,22 +425,27 @@ namespace Sass {

Arguments_Obj Parser::parse_arguments()
{
std::string name(lexed);
Position position = after_token;
Arguments_Obj args = SASS_MEMORY_NEW(Arguments, pstate);
if (lex_css< exactly<'('> >()) {
// if there's anything there at all
if (!peek_css< exactly<')'> >()) {
do args->append(parse_argument());
while (lex_css< exactly<','> >());
do {
if (peek< exactly<')'> >()) break;
args->append(parse_argument());
} while (lex_css< exactly<','> >());
}
if (!lex_css< exactly<')'> >()) {
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
}
if (!lex_css< exactly<')'> >()) error("expected a variable name (e.g. $x) or ')' for the parameter list for " + name, position);
}
return args;
}

Argument_Obj Parser::parse_argument()
{
if (peek< alternatives< exactly<','>, exactly< '{' >, exactly<';'> > >()) {
css_error("Invalid CSS", " after ", ": expected \")\", was ");
}
if (peek_css< sequence < exactly< hash_lbrace >, exactly< rbrace > > >()) {
position += 2;
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
Expand Down

0 comments on commit 3d73948

Please sign in to comment.