Skip to content

Commit

Permalink
Implement number prefix parsing (/[\+\-]+/)
Browse files Browse the repository at this point in the history
Fixes #535
  • Loading branch information
mgreter committed Mar 9, 2015
1 parent c64f228 commit 5606d26
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
4 changes: 0 additions & 4 deletions extend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "backtrace.hpp"
#include "paths.hpp"
#include "parser.hpp"
#include "debugger.hpp"
#include "node.hpp"
#include "sass_util.hpp"
#include "debug.hpp"
Expand Down Expand Up @@ -1580,7 +1579,6 @@ namespace Sass {
// out and aren't operated on.
Complex_Selector* pNewSelector = pExtComplexSelector->cloneFully(ctx);
Complex_Selector* pNewInnerMost = new (ctx.mem) Complex_Selector(pSelector->pstate(), Complex_Selector::ANCESTOR_OF, pUnifiedSelector, NULL);
// pNewInnerMost->media_block(pSelector->media_block());
Complex_Selector::Combinator combinator = pNewSelector->clear_innermost();
pNewSelector->set_innermost(pNewInnerMost, combinator);

Expand Down Expand Up @@ -1753,11 +1751,9 @@ namespace Sass {
pComplexSelector->tail()->has_line_feed(pComplexSelector->has_line_feed());

Node complexSelector = complexSelectorToNode(pComplexSelector, ctx);
// debug_ast(pComplexSelector->parent());
DEBUG_PRINTLN(EXTEND_COMPLEX, "EXTEND COMPLEX: " << complexSelector)

Node extendedNotExpanded = Node::createCollection();
// extendedNotExpanded.media_block = pComplexSelector->media_block();

for (NodeDeque::iterator complexSelIter = complexSelector.collection()->begin(), complexSelIterEnd = complexSelector.collection()->end(); complexSelIter != complexSelIterEnd; ++complexSelIter) {
Node& sseqOrOp = *complexSelIter;
Expand Down
24 changes: 20 additions & 4 deletions parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ namespace Sass {
property_segment = new (ctx.mem) String_Quoted(pstate, lexed);
}
Propset* propset = new (ctx.mem) Propset(pstate, property_segment);
// debug_ast(property_segment);
lex< exactly<':'> >();
if (!peek< exactly<'{'> >()) error("expected a '{' after namespaced property", pstate);
Expand Down Expand Up @@ -941,6 +940,22 @@ namespace Sass {
}
}

// parse +/- and return false if negative
bool Parser::parse_number_prefix()
{
bool positive = true;
while(true) {
if (lex < block_comment >()) continue;
if (lex < number_prefix >()) continue;
if (lex < exactly < '-' > >()) {
positive = !positive;
continue;
}
break;
}
return positive;
}

Expression* Parser::parse_map()
{
To_String to_string(&ctx);
Expand Down Expand Up @@ -1203,17 +1218,18 @@ namespace Sass {
else if (lex< sequence< not_op, spaces_and_comments > >()) {
return new (ctx.mem) Unary_Expression(pstate, Unary_Expression::NOT, parse_factor());
}
else if (peek < sequence < one_plus < alternatives < spaces_and_comments, exactly<'-'>, exactly<'+'> > >, number > >()) {
if (parse_number_prefix()) return parse_value(); // prefix is positive
return new (ctx.mem) Unary_Expression(pstate, Unary_Expression::MINUS, parse_value());
}
else {
return parse_value();
}
}

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
1 change: 1 addition & 0 deletions parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ namespace Sass {
Simple_Selector* parse_pseudo_selector();
Attribute_Selector* parse_attribute_selector();
Block* parse_block();
bool parse_number_prefix();
Declaration* parse_declaration();
Expression* parse_map_value();
Expression* parse_map();
Expand Down
12 changes: 12 additions & 0 deletions prelexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ namespace Sass {
return sequence< exactly<'-'>, exactly<'-'>, identifier >(src);
}

// Match number prefix ([\+\-]+)
const char* number_prefix(const char* src) {
return alternatives <
exactly < '+' >,
sequence <
exactly < '-' >,
optional_spaces_and_comments,
exactly< '-' >
>
>(src);
}

// Match interpolant schemas
const char* identifier_schema(const char* src) {
// follows this pattern: (x*ix*)+ ... well, not quite
Expand Down
2 changes: 2 additions & 0 deletions prelexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ namespace Sass {
const char* quoted_string(const char* src);
// Match interpolants.
const char* interpolant(const char* src);
// Match number prefix ([\+\-]+)
const char* number_prefix(const char* src);

// Whitespace handling.
const char* optional_spaces(const char* src);
Expand Down

0 comments on commit 5606d26

Please sign in to comment.