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
3945804b
Commit
3945804b
authored
Feb 28, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better whitespace handling.
parent
80e62ee2
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
43 additions
and
7 deletions
+43
-7
document.hpp
src/document.hpp
+22
-5
test.scss
src/test.scss
+1
-0
token.cpp
src/token.cpp
+4
-2
token.hpp
src/token.hpp
+5
-0
unit-test-document.cpp
src/unit-test-document.cpp
+8
-0
unit-test-prelexer.cpp
src/unit-test-prelexer.cpp
+3
-0
No files found.
src/document.hpp
View file @
3945804b
...
@@ -17,20 +17,37 @@ namespace Sass {
...
@@ -17,20 +17,37 @@ namespace Sass {
~
Document
();
~
Document
();
inline
Token
&
peek
()
{
return
top
;
}
inline
Token
&
peek
()
{
return
top
;
}
template
<
prelexer
mx
>
template
<
prelexer
mx
>
bool
try_munching
()
{
bool
try_munching
()
{
char
*
after_whitespace
=
spaces_and_comments
(
position
);
char
*
after_whitespace
;
if
(
mx
==
block_comment
)
{
after_whitespace
=
optional_spaces
(
position
);
}
else
if
(
mx
==
spaces
||
mx
==
ancestor_of
)
{
after_whitespace
=
spaces
(
position
);
if
(
after_whitespace
)
{
top
=
Token
(
mx
,
position
,
after_whitespace
,
line_number
);
line_number
+=
count_interval
<
'\n'
>
(
position
,
after_whitespace
);
position
=
after_whitespace
;
return
last_munch_succeeded
=
true
;
}
else
{
return
last_munch_succeeded
=
false
;
}
}
else
{
after_whitespace
=
spaces_and_comments
(
position
);
}
line_number
+=
count_interval
<
'\n'
>
(
position
,
after_whitespace
);
line_number
+=
count_interval
<
'\n'
>
(
position
,
after_whitespace
);
char
*
after_token
=
mx
(
after_whitespace
);
char
*
after_token
=
mx
(
after_whitespace
);
if
(
after_token
)
{
if
(
after_token
)
{
top
=
Token
(
mx
,
after_whitespace
,
after_token
,
line_number
);
top
=
Token
(
mx
,
after_whitespace
,
after_token
,
line_number
);
position
=
after_token
;
position
=
after_token
;
last_munch_succeeded
=
true
;
return
last_munch_succeeded
=
true
;
return
true
;
}
}
else
{
else
{
last_munch_succeeded
=
false
;
return
last_munch_succeeded
=
false
;
return
false
;
}
}
}
}
...
...
src/test.scss
View file @
3945804b
div
{
div
{
/* a comment that should be preserved */
color
:
red
;
color
:
red
;
background
:
blue
;
background
:
blue
;
span
{
span
{
...
...
src/token.cpp
View file @
3945804b
...
@@ -11,8 +11,9 @@ namespace Sass {
...
@@ -11,8 +11,9 @@ namespace Sass {
const
char
*
_end
,
const
char
*
_end
,
unsigned
int
_line_number
)
{
unsigned
int
_line_number
)
{
type
=
_type
;
type
=
_type
;
begin
=
_begin
;
if
(
_begin
>
_end
)
begin
=
end
=
0
;
end
=
_end
;
e
lse
begin
=
_begin
,
e
nd
=
_end
;
line_number
=
_line_number
;
line_number
=
_line_number
;
}
}
}
}
\ No newline at end of file
src/token.hpp
View file @
3945804b
#include <string>
#include "prelexer.hpp"
#include "prelexer.hpp"
namespace
Sass
{
namespace
Sass
{
using
std
::
string
;
struct
Token
{
struct
Token
{
Prelexer
::
prelexer
type
;
Prelexer
::
prelexer
type
;
const
char
*
begin
;
const
char
*
begin
;
...
@@ -12,5 +15,6 @@ namespace Sass {
...
@@ -12,5 +15,6 @@ namespace Sass {
const
char
*
_end
,
const
char
*
_end
,
unsigned
int
_line_number
);
unsigned
int
_line_number
);
inline
bool
is_null
()
{
return
begin
==
0
||
end
==
0
;
}
inline
bool
is_null
()
{
return
begin
==
0
||
end
==
0
;
}
inline
operator
string
()
{
return
string
(
begin
,
end
-
begin
);
}
};
};
}
}
\ No newline at end of file
src/unit-test-document.cpp
View file @
3945804b
...
@@ -26,10 +26,18 @@ int main(int argc, char* argv[]) {
...
@@ -26,10 +26,18 @@ int main(int argc, char* argv[]) {
print_slice
(
doc
.
top
.
begin
,
doc
.
top
.
end
);
print_slice
(
doc
.
top
.
begin
,
doc
.
top
.
end
);
doc
.
try_munching
<
Prelexer
::
exactly
<
'{'
>
>
();
doc
.
try_munching
<
Prelexer
::
exactly
<
'{'
>
>
();
print_slice
(
doc
.
top
.
begin
,
doc
.
top
.
end
);
print_slice
(
doc
.
top
.
begin
,
doc
.
top
.
end
);
doc
.
try_munching
<
Prelexer
::
block_comment
>
();
print_slice
(
doc
.
top
.
begin
,
doc
.
top
.
end
);
doc
.
try_munching
<
Prelexer
::
identifier
>
();
doc
.
try_munching
<
Prelexer
::
identifier
>
();
print_slice
(
doc
.
top
.
begin
,
doc
.
top
.
end
);
print_slice
(
doc
.
top
.
begin
,
doc
.
top
.
end
);
doc
.
try_munching
<
Prelexer
::
dash_match
>
();
doc
.
try_munching
<
Prelexer
::
dash_match
>
();
print_slice
(
doc
.
top
.
begin
,
doc
.
top
.
end
);
print_slice
(
doc
.
top
.
begin
,
doc
.
top
.
end
);
printf
(
"sizeof char is %ld
\n
"
,
sizeof
(
char
));
printf
(
"sizeof document object is %ld
\n
"
,
sizeof
(
doc
));
printf
(
"sizeof node object is %ld
\n
"
,
sizeof
(
Node
));
printf
(
"sizeof Node vector object is %ld
\n
"
,
sizeof
(
std
::
vector
<
Node
>
));
printf
(
"sizeof pointer to Node vector is %ld
\n
"
,
sizeof
(
std
::
vector
<
Node
>*
));
}
}
return
0
;
return
0
;
...
...
src/unit-test-prelexer.cpp
View file @
3945804b
...
@@ -95,5 +95,7 @@ int main() {
...
@@ -95,5 +95,7 @@ int main() {
if
(
ptr1
==
ptr2
)
cout
<<
"This shouldn't be the case!"
<<
endl
;
if
(
ptr1
==
ptr2
)
cout
<<
"This shouldn't be the case!"
<<
endl
;
else
cout
<<
"The prelexer pointers are different!"
<<
endl
;
else
cout
<<
"The prelexer pointers are different!"
<<
endl
;
//ptr == prelexer(exactly<'x'>);
return
0
;
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