Skip to content

Commit aada71e

Browse files
committed
Optimize parsing of interpolation values
1 parent ea5b716 commit aada71e

File tree

2 files changed

+14
-35
lines changed

2 files changed

+14
-35
lines changed

src/parser.cpp

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@ namespace Sass {
3737
return p;
3838
}
3939

40-
Parser Parser::from_c_str(const char* beg, const char* end, Context& ctx, Backtraces traces, SourceSpan pstate, const char* source, bool allow_parent)
41-
{
42-
pstate.offset.column = 0;
43-
pstate.offset.line = 0;
44-
Parser p(ctx, pstate, traces, allow_parent);
45-
p.source = source ? source : beg;
46-
p.position = beg ? beg : p.source;
47-
p.end = end ? end : p.position + strlen(p.position);
48-
Block_Obj root = SASS_MEMORY_NEW(Block, pstate);
49-
p.block_stack.push_back(root);
50-
root->is_root(true);
51-
return p;
52-
}
53-
5440
void Parser::advanceToNextToken() {
5541
lex < css_comments >(false);
5642
// advance to position
@@ -72,18 +58,6 @@ namespace Sass {
7258
&& ! peek_css<exactly<'{'>>(start);
7359
}
7460

75-
Parser Parser::from_token(Token t, Context& ctx, Backtraces traces, SourceSpan pstate, const char* source)
76-
{
77-
Parser p(ctx, pstate, traces);
78-
p.source = source ? source : t.begin;
79-
p.position = t.begin ? t.begin : p.source;
80-
p.end = t.end ? t.end : p.position + strlen(p.position);
81-
Block_Obj root = SASS_MEMORY_NEW(Block, pstate);
82-
p.block_stack.push_back(root);
83-
root->is_root(true);
84-
return p;
85-
}
86-
8761
/* main entry point to parse root block */
8862
Block_Obj Parser::parse()
8963
{
@@ -584,8 +558,9 @@ namespace Sass {
584558
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
585559
}
586560
// pass inner expression to the parser to resolve nested interpolations
587-
pstate.add(p, p+2);
588-
ExpressionObj interpolant = Parser::from_c_str(p+2, j, ctx, traces, pstate).parse_list();
561+
LocalOption<const char*> partEnd(end, j);
562+
LocalOption<const char*> partBeg(position, p + 2);
563+
ExpressionObj interpolant = parse_list();
589564
// set status on the list expression
590565
interpolant->is_interpolant(true);
591566
// schema->has_interpolants(true);
@@ -1583,7 +1558,9 @@ namespace Sass {
15831558
const char* j = skip_over_scopes< exactly<hash_lbrace>, exactly<rbrace> >(p + 2, chunk.end); // find the closing brace
15841559
if (j) { --j;
15851560
// parse the interpolant and accumulate it
1586-
ExpressionObj interp_node = Parser::from_token(Token(p+2, j), ctx, traces, pstate, source).parse_list();
1561+
LocalOption<const char*> partEnd(end, j);
1562+
LocalOption<const char*> partBeg(position, p + 2);
1563+
ExpressionObj interp_node = parse_list();
15871564
interp_node->is_interpolant(true);
15881565
schema->append(interp_node);
15891566
i = j;
@@ -1706,7 +1683,9 @@ namespace Sass {
17061683
const char* j = skip_over_scopes< exactly<hash_lbrace>, exactly<rbrace> >(p+2, str.end); // find the closing brace
17071684
if (j) {
17081685
// parse the interpolant and accumulate it
1709-
ExpressionObj interp_node = Parser::from_token(Token(p+2, j), ctx, traces, pstate, source).parse_list();
1686+
LocalOption<const char*> partEnd(end, j);
1687+
LocalOption<const char*> partBeg(position, p + 2);
1688+
ExpressionObj interp_node = parse_list();
17101689
interp_node->is_interpolant(true);
17111690
schema->append(interp_node);
17121691
i = j;
@@ -1884,7 +1863,9 @@ namespace Sass {
18841863
const char* j = skip_over_scopes< exactly<hash_lbrace>, exactly<rbrace> >(p+2, id.end); // find the closing brace
18851864
if (j) {
18861865
// parse the interpolant and accumulate it
1887-
ExpressionObj interp_node = Parser::from_token(Token(p+2, j), ctx, traces, pstate, source).parse_list(DELAYED);
1866+
LocalOption<const char*> partEnd(end, j);
1867+
LocalOption<const char*> partBeg(position, p + 2);
1868+
ExpressionObj interp_node = parse_list(DELAYED);
18881869
interp_node->is_interpolant(true);
18891870
schema->append(interp_node);
18901871
// schema->has_interpolants(true);
@@ -2072,7 +2053,7 @@ namespace Sass {
20722053
css_error("Invalid CSS", " after ", ": expected identifier, was ");
20732054
}
20742055
// return object
2075-
return token;
2056+
return lexed;
20762057
}
20772058
// helper to parse identifier
20782059
Token Parser::lex_identifier()
@@ -2082,7 +2063,7 @@ namespace Sass {
20822063
css_error("Invalid CSS", " after ", ": expected identifier, was ");
20832064
}
20842065
// return object
2085-
return token;
2066+
return lexed;
20862067
}
20872068

20882069
EachRuleObj Parser::parse_each_directive()

src/parser.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ namespace Sass {
6565

6666
// static Parser from_string(const sass::string& src, Context& ctx, SourceSpan pstate = SourceSpan("[STRING]"));
6767
static Parser from_c_str(const char* src, Context& ctx, Backtraces, SourceSpan pstate = SourceSpan("[CSTRING]"), const char* source = nullptr, bool allow_parent = true);
68-
static Parser from_c_str(const char* beg, const char* end, Context& ctx, Backtraces, SourceSpan pstate = SourceSpan("[CSTRING]"), const char* source = nullptr, bool allow_parent = true);
69-
static Parser from_token(Token t, Context& ctx, Backtraces, SourceSpan pstate = SourceSpan("[TOKEN]"), const char* source = nullptr);
7068
// special static parsers to convert strings into certain selectors
7169
static SelectorListObj parse_selector(const char* src, Context& ctx, Backtraces, SourceSpan pstate = SourceSpan("[SELECTOR]"), const char* source = nullptr, bool allow_parent = true);
7270

0 commit comments

Comments
 (0)