Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
0475008a
Commit
0475008a
authored
Feb 28, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Need more utility functions.
parent
77829b74
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
1 deletions
+89
-1
prelexer.cpp
src/prelexer.cpp
+27
-1
prelexer.hpp
src/prelexer.hpp
+49
-0
unit-test-prelexer.cpp
src/unit-test-prelexer.cpp
+13
-0
No files found.
src/prelexer.cpp
View file @
0475008a
...
...
@@ -27,7 +27,7 @@ namespace Sass {
char
*
xdigits
(
char
*
src
)
{
return
one_plus
<
xdigit
>
(
src
);
}
char
*
alnums
(
char
*
src
)
{
return
one_plus
<
alnum
>
(
src
);
}
char
*
puncts
(
char
*
src
)
{
return
one_plus
<
punct
>
(
src
);
}
// Match a line comment.
extern
const
char
slash_slash
[]
=
"//"
;
char
*
line_comment
(
char
*
src
)
{
return
to_endl
<
slash_slash
>
(
src
);
}
...
...
@@ -37,6 +37,10 @@ namespace Sass {
char
*
block_comment
(
char
*
src
)
{
return
delimited_by
<
slash_star
,
star_slash
,
false
>
(
src
);
}
// Match either comment.
char
*
comment
(
char
*
src
)
{
return
alternatives
<
block_comment
,
line_comment
>
(
src
);
}
// Match double- and single-quoted strings.
char
*
double_quoted_string
(
char
*
src
)
{
return
delimited_by
<
'"'
,
'"'
,
true
>
(
src
);
...
...
@@ -54,6 +58,13 @@ namespace Sass {
return
delimited_by
<
hash_lbrace
,
rbrace
,
false
>
(
src
);
}
// Whitespace handling.
char
*
optional_spaces
(
char
*
src
)
{
return
optional
<
spaces
>
(
src
);
}
char
*
optional_comment
(
char
*
src
)
{
return
optional
<
comment
>
(
src
);
}
char
*
spaces_and_comments
(
char
*
src
)
{
return
zero_plus
<
alternatives
<
spaces
,
comment
>
>
(
src
);
}
// Match CSS identifiers.
char
*
identifier
(
char
*
src
)
{
return
sequence
<
optional
<
exactly
<
'-'
>
>
,
...
...
@@ -121,5 +132,19 @@ namespace Sass {
char
*
prefix_match
(
char
*
src
)
{
return
exactly
<
caret_equal
>
(
src
);
}
char
*
suffix_match
(
char
*
src
)
{
return
exactly
<
dollar_equal
>
(
src
);
}
char
*
substring_match
(
char
*
src
)
{
return
exactly
<
star_equal
>
(
src
);
}
// Match CSS combinators.
char
*
adjacent_to
(
char
*
src
)
{
return
sequence
<
optional_spaces
,
exactly
<
'+'
>
>
(
src
);
}
char
*
precedes
(
char
*
src
)
{
return
sequence
<
optional_spaces
,
exactly
<
'~'
>
>
(
src
);
}
char
*
parent_of
(
char
*
src
)
{
return
sequence
<
optional_spaces
,
exactly
<
'>'
>
>
(
src
);
}
char
*
ancestor_of
(
char
*
src
)
{
return
spaces
(
src
);
}
}
}
\ No newline at end of file
src/prelexer.hpp
View file @
0475008a
...
...
@@ -201,6 +201,8 @@ namespace Sass {
char
*
line_comment
(
char
*
src
);
// Match a block comment.
char
*
block_comment
(
char
*
src
);
// Match either.
char
*
comment
(
char
*
src
);
// Match double- and single-quoted strings.
char
*
double_quoted_string
(
char
*
src
);
char
*
single_quoted_string
(
char
*
src
);
...
...
@@ -208,6 +210,11 @@ namespace Sass {
// Match interpolants.
char
*
interpolant
(
char
*
src
);
// Whitespace handling.
char
*
optional_spaces
(
char
*
src
);
char
*
optional_comment
(
char
*
src
);
char
*
spaces_and_comments
(
char
*
src
);
// Match a CSS identifier.
char
*
identifier
(
char
*
src
);
// Match CSS '@' keywords.
...
...
@@ -232,5 +239,47 @@ namespace Sass {
char
*
prefix_match
(
char
*
src
);
char
*
suffix_match
(
char
*
src
);
char
*
substring_match
(
char
*
src
);
// Match CSS combinators.
char
*
adjacent_to
(
char
*
src
);
char
*
precedes
(
char
*
src
);
char
*
parent_of
(
char
*
src
);
char
*
ancestor_of
(
char
*
src
);
// Utility functions for finding and counting characters in a string.
template
<
char
c
>
char
*
find_first
(
char
*
src
)
{
while
(
*
src
&&
*
src
!=
c
)
++
src
;
return
*
src
?
src
:
0
;
}
template
<
prelexer
mx
>
char
*
find_first
(
char
*
src
)
{
while
(
*
src
&&
!
mx
(
src
))
++
src
;
return
*
src
?
src
:
0
;
}
template
<
char
c
>
unsigned
int
count_interval
(
char
*
beg
,
char
*
end
)
{
unsigned
int
counter
=
0
;
while
(
beg
<
end
&&
*
beg
)
{
if
(
*
beg
==
c
)
++
counter
;
++
beg
;
}
return
counter
;
}
template
<
prelexer
mx
>
unsigned
int
count_interval
(
char
*
beg
,
char
*
end
)
{
unsigned
int
counter
=
0
;
while
(
beg
<
end
&&
*
beg
)
{
char
*
p
;
if
(
p
=
mx
(
beg
))
{
++
counter
;
beg
=
p
;
}
else
{
++
beg
;
}
}
return
counter
;
}
}
}
src/unit-test-prelexer.cpp
View file @
0475008a
#include <cstdio>
#include <iostream>
#include "prelexer.hpp"
using
namespace
Sass
::
Prelexer
;
using
std
::
cout
;
using
std
::
endl
;
void
print_slice
(
const
char
*
s
,
const
char
*
t
)
{
if
(
t
)
{
...
...
@@ -39,6 +42,10 @@ char dash1[] = "|='bar'] { ... }";
char
pre1
[]
=
"^='hux'] { ... }"
;
char
suf1
[]
=
"$='baz'] { ... }"
;
char
sub1
[]
=
"*='bum'] { ... }"
;
char
ws1
[]
=
" /* hello */
\t\n
//blah
\n
/*blah*/ significant"
;
extern
const
char
slash_star
[]
=
"/*"
;
int
main
()
{
...
...
@@ -60,6 +67,11 @@ int main() {
check_twice
(
prefix_match
,
pre1
,
dash1
);
check_twice
(
suffix_match
,
suf1
,
pre1
);
check_twice
(
substring_match
,
sub1
,
suf1
);
check_twice
(
spaces_and_comments
,
ws1
,
num1
);
cout
<<
count_interval
<
'\n'
>
(
ws1
,
spaces_and_comments
(
ws1
))
<<
endl
;
cout
<<
count_interval
<
'*'
>
(
ws1
,
spaces_and_comments
(
ws1
))
<<
endl
;
cout
<<
count_interval
<
exactly
<
slash_star
>
>
(
ws1
,
spaces_and_comments
(
ws1
))
<<
endl
;
putchar
(
*
(
find_first
<
'{'
>
(
pre1
))),
putchar
(
'\n'
);
return
0
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment