Skip to content

Commit 0972512

Browse files
committed
Improve number unit identifier parsing
1 parent 6d5b6b2 commit 0972512

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/prelexer.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,42 @@ namespace Sass {
119119
>(src);
120120
}
121121

122+
const char* strict_identifier_alpha(const char* src)
123+
{
124+
return alternatives <
125+
alpha,
126+
unicode,
127+
escape_seq,
128+
exactly<'_'>
129+
>(src);
130+
}
131+
132+
const char* strict_identifier_alnum(const char* src)
133+
{
134+
return alternatives <
135+
alnum,
136+
unicode,
137+
escape_seq,
138+
exactly<'_'>
139+
>(src);
140+
}
141+
142+
// Match CSS unit identifier.
143+
const char* unit_identifier(const char* src)
144+
{
145+
return sequence <
146+
optional < exactly <'-'> >,
147+
strict_identifier_alpha,
148+
zero_plus < alternatives<
149+
strict_identifier_alnum,
150+
sequence <
151+
one_plus < exactly<'-'> >,
152+
strict_identifier_alpha
153+
>
154+
> >
155+
>(src);
156+
}
157+
122158
const char* identifier_alnums(const char* src)
123159
{
124160
return one_plus< identifier_alnum >(src);
@@ -528,7 +564,7 @@ namespace Sass {
528564
return sequence< number, exactly<em_kwd> >(src);
529565
} */
530566
const char* dimension(const char* src) {
531-
return sequence<number, one_plus< alpha > >(src);
567+
return sequence<number, unit_identifier >(src);
532568
}
533569
const char* hex(const char* src) {
534570
const char* p = sequence< exactly<'#'>, one_plus<xdigit> >(src);

src/prelexer.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ namespace Sass {
195195
const char* identifier(const char* src);
196196
const char* identifier_alpha(const char* src);
197197
const char* identifier_alnum(const char* src);
198-
const char* identifier_alnums(const char* src);
198+
const char* strict_identifier_alpha(const char* src);
199+
const char* strict_identifier_alnum(const char* src);
200+
// Match a CSS unit identifier.
201+
const char* unit_identifier(const char* src);
202+
// const char* strict_identifier_alnums(const char* src);
199203
// Match reference selector.
200204
const char* re_reference_combinator(const char* src);
201205
const char* static_reference_combinator(const char* src);

0 commit comments

Comments
 (0)