Skip to content

Commit

Permalink
Improve comment parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Mar 8, 2015
1 parent f65aa5f commit b5235ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
23 changes: 19 additions & 4 deletions parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ namespace Sass {
Import* imp = new (ctx.mem) Import(pstate);
bool first = true;
do {
while (lex< block_comment >());
if (lex< quoted_string >()) {
string import_path(lexed);

Expand Down Expand Up @@ -279,21 +280,26 @@ namespace Sass {
// if there's anything there at all
if (!peek< exactly<')'> >()) {
do (*params) << parse_parameter();
while (lex< exactly<','> >());
while (lex< alternatives < spaces,block_comment, exactly<','> > >());
}
while (lex< alternatives < spaces, block_comment > >());
if (!peek< exactly<')'> >()) cerr << "BALAB [" << position << "]\n";
if (!lex< exactly<')'> >()) error("expected a variable name (e.g. $x) or ')' for the parameter list for " + name, pstate);
}
return params;
}

Parameter* Parser::parse_parameter()
{
while (lex< alternatives < spaces, block_comment > >());
lex< variable >();
string name(Util::normalize_underscores(lexed));
ParserState pos = pstate;
Expression* val = 0;
bool is_rest = false;
while (lex< alternatives < spaces, block_comment > >());
if (lex< exactly<':'> >()) { // there's a default value
while (lex< block_comment >());
val = parse_space_list();
val->is_delayed(false);
}
Expand Down Expand Up @@ -328,8 +334,10 @@ namespace Sass {
// if there's anything there at all
if (!peek< exactly<')'> >()) {
do (*args) << parse_argument();
while (lex< exactly<','> >());
while (lex< alternatives < block_comment, exactly<','> > >());
}
while (lex< block_comment >());
if (!peek< exactly<')'> >()) cerr << "BALAB [" << position << "]\n";
if (!lex< exactly<')'> >()) error("expected a variable name (e.g. $x) or ')' for the parameter list for " + name, pstate);
}

Expand All @@ -339,10 +347,12 @@ namespace Sass {
Argument* Parser::parse_argument()
{
Argument* arg;
if (peek< sequence < variable, optional_spaces_and_comments, exactly<':'> > >()) {
while (lex< alternatives < spaces, block_comment > >());
if (peek< sequence < variable, zero_plus < alternatives < spaces, line_comment, block_comment > >, exactly<':'> > >()) {
lex< variable >();
string name(Util::normalize_underscores(lexed));
ParserState p = pstate;
while (lex< alternatives < spaces, block_comment > >());
lex< exactly<':'> >();
Expression* val = parse_space_list();
val->is_delayed(false);
Expand Down Expand Up @@ -728,7 +738,7 @@ namespace Sass {
bool semicolon = false;
Selector_Lookahead lookahead_result;
Block* block = new (ctx.mem) Block(pstate);
// lex< zero_plus < alternatives < space, line_comment > > >();
lex< zero_plus < alternatives < space, line_comment > > >();
// JMA - ensure that a block containing only block_comments is parsed
while (lex< block_comment >()) {
bool is_important = lexed.begin[2] == '!';
Expand Down Expand Up @@ -1128,6 +1138,7 @@ namespace Sass {
peek< exactly<'%'> >(position)))
{ return fact1; }

while (lex< block_comment >());
vector<Expression*> operands;
vector<Binary_Expression::Type> operators;
while (lex< exactly<'*'> >() || lex< exactly<'/'> >() || lex< exactly<'%'> >()) {
Expand Down Expand Up @@ -1194,6 +1205,10 @@ namespace Sass {

Expression* Parser::parse_value()
{

// ToDo: Move where
while (lex< block_comment >());

if (lex< uri_prefix >()) {
Arguments* args = new (ctx.mem) Arguments(pstate);
Function_Call* result = new (ctx.mem) Function_Call(pstate, "url", args);
Expand Down
6 changes: 3 additions & 3 deletions prelexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace Sass {
}
// Match either comment.
const char* comment(const char* src) {
return alternatives<block_comment, line_comment>(src);
return line_comment(src);
}

const char* wspaces(const char* src) {
Expand Down Expand Up @@ -100,10 +100,10 @@ namespace Sass {
const char* optional_spaces(const char* src) { return optional<spaces>(src); }
// const char* optional_comment(const char* src) { return optional<comment>(src); }
const char* optional_spaces_and_comments(const char* src) {
return zero_plus< alternatives<spaces, comment> >(src);
return zero_plus< alternatives<spaces, line_comment> >(src);
}
const char* spaces_and_comments(const char* src) {
return one_plus< alternatives<spaces, comment> >(src);
return one_plus< alternatives<spaces, line_comment> >(src);
}
const char* no_spaces(const char* src) {
return negate< spaces >(src);
Expand Down

0 comments on commit b5235ec

Please sign in to comment.