Skip to content

Commit 2be979c

Browse files
committed
Merge pull request #1464 from mgreter/feature/unicode-sequence-parser
Add unicode sequence parsing
2 parents d67f8da + 4ccdb25 commit 2be979c

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

src/context.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "sass2scss.h"
3333
#include "prelexer.hpp"
3434
#include "emitter.hpp"
35-
#include "debugger.hpp"
3635

3736
namespace Sass {
3837
using namespace Constants;

src/prelexer.cpp

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,23 @@ namespace Sass {
7070
{
7171
return sequence<
7272
exactly<'\\'>,
73-
any_char
73+
alternatives <
74+
minmax_range<
75+
3, 3, xdigit
76+
>,
77+
any_char
78+
>,
79+
optional <
80+
exactly <' '>
81+
>
7482
>(src);
7583
}
7684

7785
// Match identifier start
7886
const char* identifier_alpha(const char* src)
7987
{
8088
return alternatives<
89+
unicode_seq,
8190
alpha,
8291
unicode,
8392
exactly<'-'>,
@@ -90,6 +99,7 @@ namespace Sass {
9099
const char* identifier_alnum(const char* src)
91100
{
92101
return alternatives<
102+
unicode_seq,
93103
alnum,
94104
unicode,
95105
exactly<'-'>,
@@ -173,6 +183,7 @@ namespace Sass {
173183
re_linebreak
174184
>,
175185
escape_seq,
186+
unicode_seq,
176187
// skip interpolants
177188
interpolant,
178189
// skip non delimiters
@@ -196,6 +207,7 @@ namespace Sass {
196207
re_linebreak
197208
>,
198209
escape_seq,
210+
unicode_seq,
199211
// skip interpolants
200212
interpolant,
201213
// skip non delimiters
@@ -880,6 +892,20 @@ namespace Sass {
880892
return (p == 0) ? t.end : 0;
881893
}
882894

895+
const char* unicode_seq(const char* src) {
896+
return sequence <
897+
alternatives <
898+
exactly< 'U' >,
899+
exactly< 'u' >
900+
>,
901+
exactly< '+' >,
902+
padded_token <
903+
6, xdigit,
904+
exactly < '?' >
905+
>
906+
>(src);
907+
}
908+
883909
const char* static_component(const char* src) {
884910
return alternatives< identifier,
885911
static_string,
@@ -974,5 +1000,35 @@ namespace Sass {
9741000
return sequence< number, optional_spaces, exactly<'/'>, optional_spaces, number >(src);
9751001
}
9761002

1003+
template <size_t size, prelexer mx, prelexer pad>
1004+
const char* padded_token(const char* src)
1005+
{
1006+
size_t got = 0;
1007+
const char* pos = src;
1008+
while (got < size) {
1009+
if (!mx(pos)) break;
1010+
++ pos; ++ got;
1011+
}
1012+
while (got < size) {
1013+
if (!pad(pos)) break;
1014+
++ pos; ++ got;
1015+
}
1016+
return got ? pos : 0;
1017+
}
1018+
1019+
template <size_t min, size_t max, prelexer mx>
1020+
const char* minmax_range(const char* src)
1021+
{
1022+
size_t got = 0;
1023+
const char* pos = src;
1024+
while (got < max) {
1025+
if (!mx(pos)) break;
1026+
++ pos; ++ got;
1027+
}
1028+
if (got < min) return 0;
1029+
if (got > min) return 0;
1030+
return pos;
1031+
}
1032+
9771033
}
9781034
}

src/prelexer.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ namespace Sass {
227227
const char* kwd_charset_directive(const char* src);
228228
const char* kwd_extend(const char* src);
229229

230+
const char* unicode_seq(const char* src);
231+
230232
const char* kwd_if_directive(const char* src);
231233
const char* kwd_else_directive(const char* src);
232234
const char* elseif_directive(const char* src);
@@ -388,6 +390,12 @@ namespace Sass {
388390
return counter;
389391
}
390392

393+
template <size_t size, prelexer mx, prelexer pad>
394+
const char* padded_token(const char* src);
395+
396+
template <size_t min, size_t max, prelexer mx>
397+
const char* minmax_range(const char* src);
398+
391399
}
392400
}
393401

src/util.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ namespace Sass {
363363
// ToDo: Maybe we could do this without creating a substring
364364
uint32_t cp = strtol(s.substr (i + 1, len - 1).c_str(), nullptr, 16);
365365

366+
if (s[i + len] == ' ') ++ len;
367+
366368
// assert invalid code points
367369
if (cp == 0) cp = 0xFFFD;
368370
// replace bell character

0 commit comments

Comments
 (0)