Commit 008fdc67 by Aaron Leung

Improving argument parsing to match the new restrictions in canonical Sass.

parent b0fc4958
...@@ -133,7 +133,7 @@ namespace Sass { ...@@ -133,7 +133,7 @@ namespace Sass {
Node parse_parameter(); Node parse_parameter();
Node parse_mixin_call(); Node parse_mixin_call();
Node parse_arguments(); Node parse_arguments();
Node parse_argument(); Node parse_argument(Node::Type);
Node parse_assignment(); Node parse_assignment();
Node parse_propset(); Node parse_propset();
Node parse_ruleset(Selector_Lookahead lookahead, Node::Type inside_of = Node::none); Node parse_ruleset(Selector_Lookahead lookahead, Node::Type inside_of = Node::none);
......
...@@ -192,15 +192,18 @@ namespace Sass { ...@@ -192,15 +192,18 @@ namespace Sass {
{ {
Token name(lexed); Token name(lexed);
Node args(context.new_Node(Node::arguments, path, line, 0)); Node args(context.new_Node(Node::arguments, path, line, 0));
Node::Type arg_type = Node::none;
if (lex< exactly<'('> >()) { if (lex< exactly<'('> >()) {
if (!peek< exactly<')'> >(position)) { if (!peek< exactly<')'> >(position)) {
Node arg(parse_argument()); Node arg(parse_argument(Node::none));
arg.should_eval() = true; arg.should_eval() = true;
args << arg; args << arg;
if (arg.type() == Node::assignment) arg_type = Node::assignment;
while (lex< exactly<','> >()) { while (lex< exactly<','> >()) {
Node arg(parse_argument()); Node arg(parse_argument(arg_type));
arg.should_eval() = true; arg.should_eval() = true;
args << arg; args << arg;
if (arg.type() == Node::assignment) arg_type = Node::assignment;
} }
} }
if (!lex< exactly<')'> >()) throw_syntax_error("improperly terminated argument list for " + name.to_string()); if (!lex< exactly<')'> >()) throw_syntax_error("improperly terminated argument list for " + name.to_string());
...@@ -208,8 +211,10 @@ namespace Sass { ...@@ -208,8 +211,10 @@ namespace Sass {
return args; return args;
} }
Node Document::parse_argument() Node Document::parse_argument(Node::Type arg_type)
{ {
// if arg_type is assignment, only accept keyword args from here onwards
if (arg_type == Node::assignment) {
if (peek< sequence < variable, spaces_and_comments, exactly<':'> > >()) { if (peek< sequence < variable, spaces_and_comments, exactly<':'> > >()) {
lex< variable >(); lex< variable >();
Node var(context.new_Node(Node::variable, path, line, lexed)); Node var(context.new_Node(Node::variable, path, line, lexed));
...@@ -220,8 +225,33 @@ namespace Sass { ...@@ -220,8 +225,33 @@ namespace Sass {
return assn; return assn;
} }
else { else {
return parse_space_list(); throw_syntax_error("ordinal arguments must precede keyword arguments");
}
} }
// otherwise accept either, and let the caller set the arg_type flag
if (arg_type == Node::none &&
peek< sequence < variable, spaces_and_comments, exactly<':'> > >()) {
lex< variable >();
Node var(context.new_Node(Node::variable, path, line, lexed));
lex< exactly<':'> >();
Node val(parse_space_list());
Node assn(context.new_Node(Node::assignment, path, line, 2));
assn << var << val;
return assn;
}
return parse_space_list();
// if (peek< sequence < variable, spaces_and_comments, exactly<':'> > >()) {
// lex< variable >();
// Node var(context.new_Node(Node::variable, path, line, lexed));
// lex< exactly<':'> >();
// Node val(parse_space_list());
// Node assn(context.new_Node(Node::assignment, path, line, 2));
// assn << var << val;
// return assn;
// }
// else {
// return parse_space_list();
// }
} }
Node Document::parse_assignment() Node Document::parse_assignment()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment