Skip to content

Commit

Permalink
Add unicode sequence parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Aug 22, 2015
1 parent 0ae11a4 commit fa02bad
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "sass2scss.h"
#include "prelexer.hpp"
#include "emitter.hpp"
#include "debugger.hpp"

namespace Sass {
using namespace Constants;
Expand Down
34 changes: 34 additions & 0 deletions src/prelexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace Sass {
const char* identifier_alpha(const char* src)
{
return alternatives<
unicode_seq,
alpha,
unicode,
exactly<'-'>,
Expand All @@ -90,6 +91,7 @@ namespace Sass {
const char* identifier_alnum(const char* src)
{
return alternatives<
unicode_seq,
alnum,
unicode,
exactly<'-'>,
Expand Down Expand Up @@ -153,6 +155,7 @@ namespace Sass {
re_linebreak
>,
escape_seq,
unicode_seq,
// skip interpolants
interpolant,
// skip non delimiters
Expand All @@ -176,6 +179,7 @@ namespace Sass {
re_linebreak
>,
escape_seq,
unicode_seq,
// skip interpolants
interpolant,
// skip non delimiters
Expand Down Expand Up @@ -832,6 +836,20 @@ namespace Sass {
return (p == 0) ? t.end : 0;
}

const char* unicode_seq(const char* src) {
return sequence <
alternatives <
exactly< 'U' >,
exactly< 'u' >
>,
exactly< '+' >,
padded_token <
6, xdigit,
exactly < '?' >
>
>(src);
}

const char* static_component(const char* src) {
return alternatives< identifier,
static_string,
Expand Down Expand Up @@ -926,5 +944,21 @@ namespace Sass {
return sequence< number, optional_spaces, exactly<'/'>, optional_spaces, number >(src);
}

template <size_t size, prelexer mx, prelexer pad>
const char* padded_token(const char* src)
{
size_t got = 0;
const char* pos = src;
while (got < size) {
if (!mx(pos)) break;
++ pos; ++ got;
}
while (got < size) {
if (!pad(pos)) break;
++ pos; ++ got;
}
return got ? pos : 0;
}

}
}
5 changes: 5 additions & 0 deletions src/prelexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ namespace Sass {
const char* kwd_charset_directive(const char* src);
const char* kwd_extend(const char* src);

const char* unicode_seq(const char* src);

const char* kwd_if_directive(const char* src);
const char* kwd_else_directive(const char* src);
const char* elseif_directive(const char* src);
Expand Down Expand Up @@ -388,6 +390,9 @@ namespace Sass {
return counter;
}

template <size_t size, prelexer mx, prelexer pad>
const char* padded_token(const char* src);

}
}

Expand Down

0 comments on commit fa02bad

Please sign in to comment.