@@ -1804,71 +1804,63 @@ namespace Sass {
1804
1804
return schema.detach ();
1805
1805
}
1806
1806
1807
- String_Schema_Obj Parser::parse_css_variable_value (bool top_level )
1807
+ String_Schema_Obj Parser::parse_css_variable_value ()
1808
1808
{
1809
1809
String_Schema_Obj schema = SASS_MEMORY_NEW (String_Schema, pstate);
1810
- String_Schema_Obj tok;
1811
- if (!(tok = parse_css_variable_value_token (top_level))) {
1812
- return {};
1813
- }
1814
-
1815
- schema->concat (tok);
1816
- while ((tok = parse_css_variable_value_token (top_level))) {
1817
- schema->concat (tok);
1818
- }
1819
-
1820
- return schema.detach ();
1821
- }
1822
-
1823
- String_Schema_Obj Parser::parse_css_variable_value_token (bool top_level)
1824
- {
1825
- String_Schema_Obj schema = SASS_MEMORY_NEW (String_Schema, pstate);
1826
- if (
1827
- (top_level && lex< css_variable_top_level_value >(false )) ||
1828
- (!top_level && lex< css_variable_value >(false ))
1829
- ) {
1830
- Token str (lexed);
1831
- schema->append (SASS_MEMORY_NEW (String_Constant, pstate, str));
1832
- }
1833
- else if (Expression_Obj tok = lex_interpolation ()) {
1834
- if (String_Schema* s = Cast<String_Schema>(tok)) {
1835
- schema->concat (s);
1836
- } else {
1837
- schema->append (tok);
1838
- }
1839
- }
1840
- else if (lex< quoted_string >()) {
1841
- Expression_Obj tok = parse_string ();
1842
- if (String_Schema* s = Cast<String_Schema>(tok)) {
1843
- schema->concat (s);
1844
- } else {
1845
- schema->append (tok);
1846
- }
1847
- }
1848
- else {
1849
- if (peek< alternatives< exactly<' (' >, exactly<' [' >, exactly<' {' > > >()) {
1850
- if (lex< exactly<' (' > >()) {
1851
- schema->append (SASS_MEMORY_NEW (String_Constant, pstate, std::string (" (" )));
1852
- if (String_Schema_Obj tok = parse_css_variable_value (false )) schema->concat (tok);
1853
- if (!lex< exactly<' )' > >()) css_error (" Invalid CSS" , " after " , " : expected \" )\" , was " );
1854
- schema->append (SASS_MEMORY_NEW (String_Constant, pstate, std::string (" )" )));
1810
+ std::vector<char > brackets;
1811
+ while (true ) {
1812
+ if (
1813
+ (brackets.empty () && lex< css_variable_top_level_value >(false )) ||
1814
+ (!brackets.empty () && lex< css_variable_value >(false ))
1815
+ ) {
1816
+ Token str (lexed);
1817
+ schema->append (SASS_MEMORY_NEW (String_Constant, pstate, str));
1818
+ } else if (Expression_Obj tok = lex_interpolation ()) {
1819
+ if (String_Schema* s = Cast<String_Schema>(tok)) {
1820
+ if (s->empty ()) break ;
1821
+ schema->concat (s);
1822
+ } else {
1823
+ schema->append (tok);
1855
1824
}
1856
- else if (lex< exactly<' [' > >()) {
1857
- schema->append (SASS_MEMORY_NEW (String_Constant, pstate, std::string (" [" )));
1858
- if (String_Schema_Obj tok = parse_css_variable_value (false )) schema->concat (tok);
1859
- if (!lex< exactly<' ]' > >()) css_error (" Invalid CSS" , " after " , " : expected \" ]\" , was " );
1860
- schema->append (SASS_MEMORY_NEW (String_Constant, pstate, std::string (" ]" )));
1825
+ } else if (lex< quoted_string >()) {
1826
+ Expression_Obj tok = parse_string ();
1827
+ if (tok.isNull ()) break ;
1828
+ if (String_Schema* s = Cast<String_Schema>(tok)) {
1829
+ if (s->empty ()) break ;
1830
+ schema->concat (s);
1831
+ } else {
1832
+ schema->append (tok);
1861
1833
}
1862
- else if (lex< exactly<' {' > >()) {
1863
- schema->append (SASS_MEMORY_NEW (String_Constant, pstate, std::string (" {" )));
1864
- if (String_Schema_Obj tok = parse_css_variable_value (false )) schema->concat (tok);
1865
- if (!lex< exactly<' }' > >()) css_error (" Invalid CSS" , " after " , " : expected \" }\" , was " );
1866
- schema->append (SASS_MEMORY_NEW (String_Constant, pstate, std::string (" }" )));
1834
+ } else if (lex< alternatives< exactly<' (' >, exactly<' [' >, exactly<' {' > > >()) {
1835
+ const char opening_bracket = *(position - 1 );
1836
+ brackets.push_back (opening_bracket);
1837
+ schema->append (SASS_MEMORY_NEW (String_Constant, pstate, std::string (1 , opening_bracket)));
1838
+ } else if (const char *match = peek< alternatives< exactly<' )' >, exactly<' ]' >, exactly<' }' > > >()) {
1839
+ if (brackets.empty ()) break ;
1840
+ const char closing_bracket = *(match - 1 );
1841
+ if (brackets.back () != Util::opening_bracket_for (closing_bracket)) {
1842
+ std::string message = " : expected \" " ;
1843
+ message += Util::closing_bracket_for (brackets.back ());
1844
+ message += " \" , was " ;
1845
+ css_error (" Invalid CSS" , " after " , message);
1867
1846
}
1847
+ lex< alternatives< exactly<' )' >, exactly<' ]' >, exactly<' }' > > >();
1848
+ schema->append (SASS_MEMORY_NEW (String_Constant, pstate, std::string (1 , closing_bracket)));
1849
+ brackets.pop_back ();
1850
+ } else {
1851
+ break ;
1868
1852
}
1869
1853
}
1870
1854
1871
- return schema->length () > 0 ? schema.detach () : NULL ;
1855
+ if (!brackets.empty ()) {
1856
+ std::string message = " : expected \" " ;
1857
+ message += Util::closing_bracket_for (brackets.back ());
1858
+ message += " \" , was " ;
1859
+ css_error (" Invalid CSS" , " after " , message);
1860
+ }
1861
+
1862
+ if (schema->empty ()) return {};
1863
+ return schema.detach ();
1872
1864
}
1873
1865
1874
1866
Value_Obj Parser::parse_static_value ()
0 commit comments