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
33c5ecdf
Commit
33c5ecdf
authored
Feb 29, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bam! Variable substitution works!
parent
6ffd60ae
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
10 deletions
+53
-10
document.cpp
src/document.cpp
+30
-5
document.hpp
src/document.hpp
+8
-1
node.cpp
src/node.cpp
+2
-2
node.hpp
src/node.hpp
+1
-1
test.scss
src/test.scss
+5
-0
token.hpp
src/token.hpp
+7
-1
No files found.
src/document.cpp
View file @
33c5ecdf
#include <cstdio>
#include <cstdio>
#include "document.hpp"
#include "document.hpp"
#include <iostream>
namespace
Sass
{
namespace
Sass
{
using
namespace
Prelexer
;
using
namespace
Prelexer
;
using
std
::
cout
;
using
std
::
endl
;
Document
::
Document
(
char
*
_path
,
char
*
_source
)
{
Document
::
Document
(
char
*
_path
,
char
*
_source
)
{
path
=
_path
;
path
=
_path
;
...
@@ -42,13 +44,24 @@ namespace Sass {
...
@@ -42,13 +44,24 @@ namespace Sass {
if
(
try_munching
<
block_comment
>
())
{
if
(
try_munching
<
block_comment
>
())
{
return
Node
(
Node
::
comment
,
top
);
return
Node
(
Node
::
comment
,
top
);
}
}
else
if
(
try_munching
<
variable
>
())
{
return
parse_var_def
();
}
else
return
parse_ruleset
();
else
return
parse_ruleset
();
}
}
Node
Document
::
parse_var_def
()
{
const
Token
key
=
top
;
try_munching
<
exactly
<
':'
>
>
();
environment
[
string
(
key
)]
=
parse_values
();
try_munching
<
exactly
<
';'
>
>
();
return
Node
(
Node
::
null
);
}
Node
Document
::
parse_ruleset
()
{
Node
Document
::
parse_ruleset
()
{
Node
ruleset
(
Node
::
ruleset
);
Node
ruleset
(
Node
::
ruleset
);
ruleset
.
push_child
(
parse_selector
());
ruleset
.
push_child
(
parse_selector
());
ruleset
.
push_child
(
parse_
declaration
s
());
ruleset
.
push_child
(
parse_
clause
s
());
return
ruleset
;
return
ruleset
;
}
}
...
@@ -57,14 +70,18 @@ namespace Sass {
...
@@ -57,14 +70,18 @@ namespace Sass {
return
Node
(
Node
::
selector
,
top
);
return
Node
(
Node
::
selector
,
top
);
}
}
Node
Document
::
parse_
declaration
s
()
{
Node
Document
::
parse_
clause
s
()
{
try_munching
<
exactly
<
'{'
>
>
();
try_munching
<
exactly
<
'{'
>
>
();
Node
decls
(
Node
::
declaration
s
);
Node
decls
(
Node
::
clause
s
);
while
(
!
try_munching
<
exactly
<
'}'
>
>
())
{
while
(
!
try_munching
<
exactly
<
'}'
>
>
())
{
if
(
try_munching
<
block_comment
>
())
{
if
(
try_munching
<
block_comment
>
())
{
decls
.
push_child
(
Node
(
Node
::
comment
,
top
));
decls
.
push_child
(
Node
(
Node
::
comment
,
top
));
continue
;
continue
;
}
}
else
if
(
try_munching
<
variable
>
())
{
decls
.
push_child
(
parse_var_def
());
continue
;
}
try_munching
<
identifier
>
();
try_munching
<
identifier
>
();
Token
id
=
top
;
Token
id
=
top
;
if
(
try_munching
<
exactly
<
':'
>
>
())
{
if
(
try_munching
<
exactly
<
':'
>
>
())
{
...
@@ -77,7 +94,7 @@ namespace Sass {
...
@@ -77,7 +94,7 @@ namespace Sass {
else
{
else
{
Node
ruleset
(
Node
::
ruleset
);
Node
ruleset
(
Node
::
ruleset
);
ruleset
.
push_child
(
Node
(
Node
::
selector
,
id
));
ruleset
.
push_child
(
Node
(
Node
::
selector
,
id
));
ruleset
.
push_child
(
parse_
declaration
s
());
ruleset
.
push_child
(
parse_
clause
s
());
decls
.
push_opt_child
(
ruleset
);
decls
.
push_opt_child
(
ruleset
);
}
}
}
}
...
@@ -87,7 +104,15 @@ namespace Sass {
...
@@ -87,7 +104,15 @@ namespace Sass {
Node
Document
::
parse_values
()
{
Node
Document
::
parse_values
()
{
Node
values
(
Node
::
values
);
Node
values
(
Node
::
values
);
while
(
try_munching
<
identifier
>
()
||
try_munching
<
dimension
>
()
||
while
(
try_munching
<
identifier
>
()
||
try_munching
<
dimension
>
()
||
try_munching
<
percentage
>
()
||
try_munching
<
number
>
())
{
try_munching
<
percentage
>
()
||
try_munching
<
number
>
()
||
try_munching
<
hex
>
()
||
try_munching
<
variable
>
())
{
if
(
top
.
begin
[
0
]
==
'$'
)
{
Node
stuff
(
environment
[
string
(
top
)]);
for
(
int
i
=
0
;
i
<
stuff
.
children
.
size
();
++
i
)
{
values
.
push_child
(
stuff
.
children
[
i
]);
}
}
else
values
.
push_child
(
Node
(
Node
::
value
,
top
));
values
.
push_child
(
Node
(
Node
::
value
,
top
));
}
}
return
values
;
return
values
;
...
...
src/document.hpp
View file @
33c5ecdf
#include <map>
#include "node.hpp"
#include "node.hpp"
namespace
Sass
{
namespace
Sass
{
using
std
::
vector
;
using
std
::
vector
;
using
std
::
map
;
using
namespace
Prelexer
;
using
namespace
Prelexer
;
struct
Document
{
struct
Document
{
...
@@ -9,6 +11,10 @@ namespace Sass {
...
@@ -9,6 +11,10 @@ namespace Sass {
char
*
source
;
char
*
source
;
char
*
position
;
char
*
position
;
unsigned
int
line_number
;
unsigned
int
line_number
;
// TO DO: move the environment up into the context class when it's ready
map
<
string
,
Node
>
environment
;
vector
<
Node
>
statements
;
vector
<
Node
>
statements
;
Token
top
;
Token
top
;
bool
last_munch_succeeded
;
bool
last_munch_succeeded
;
...
@@ -57,9 +63,10 @@ namespace Sass {
...
@@ -57,9 +63,10 @@ namespace Sass {
void
parse_scss
();
void
parse_scss
();
Node
parse_statement
();
Node
parse_statement
();
Node
parse_var_def
();
Node
parse_ruleset
();
Node
parse_ruleset
();
Node
parse_selector
();
Node
parse_selector
();
Node
parse_
declaration
s
();
Node
parse_
clause
s
();
Node
parse_values
();
Node
parse_values
();
};
};
...
...
src/node.cpp
View file @
33c5ecdf
...
@@ -48,7 +48,7 @@ namespace Sass {
...
@@ -48,7 +48,7 @@ namespace Sass {
children
[
1
].
dump
(
depth
);
children
[
1
].
dump
(
depth
);
cout
<<
";"
<<
endl
;
cout
<<
";"
<<
endl
;
break
;
break
;
case
declaration
s
:
case
clause
s
:
cout
<<
" {"
<<
endl
;
cout
<<
" {"
<<
endl
;
for
(
int
i
=
0
;
i
<
children
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
children
.
size
();
++
i
)
{
children
[
i
].
dump
(
depth
+
1
);
children
[
i
].
dump
(
depth
+
1
);
...
@@ -92,7 +92,7 @@ namespace Sass {
...
@@ -92,7 +92,7 @@ namespace Sass {
children
[
1
].
emit_expanded_css
(
buf
,
prefix
);
children
[
1
].
emit_expanded_css
(
buf
,
prefix
);
buf
<<
";"
<<
endl
;
buf
<<
";"
<<
endl
;
break
;
break
;
case
declaration
s
:
case
clause
s
:
buf
<<
" {"
<<
endl
;
buf
<<
" {"
<<
endl
;
for
(
int
i
=
0
;
i
<
children
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
children
.
size
();
++
i
)
children
[
i
].
emit_expanded_css
(
buf
,
prefix
);
children
[
i
].
emit_expanded_css
(
buf
,
prefix
);
...
...
src/node.hpp
View file @
33c5ecdf
...
@@ -9,7 +9,7 @@ namespace Sass {
...
@@ -9,7 +9,7 @@ namespace Sass {
null
,
null
,
comment
,
comment
,
ruleset
,
ruleset
,
declaration
s
,
clause
s
,
selector_group
,
selector_group
,
selector
,
selector
,
simple_selector_sequence
,
simple_selector_sequence
,
...
...
src/test.scss
View file @
33c5ecdf
$blah
:
bloo
;
/* top level comment -- should preserved */
/* top level comment -- should preserved */
div
{
div
{
/* another comment that should be preserved */
/* another comment that should be preserved */
color
:
red
;
color
:
red
;
background
:
blue
;
background
:
blue
;
$blux
:
hux
;
span
{
span
{
font-weight
:
bold
;
font-weight
:
bold
;
a
{
a
{
text-decoration
:
none
;
text-decoration
:
none
;
color
:
green
;
color
:
green
;
border
:
1px
$blah
red
;
}
}
/* yet another comment that should be preserved */
/* yet another comment that should be preserved */
display
:
inline-block
;
display
:
inline-block
;
}
}
p
{
p
{
padding
:
10px
8%
;
padding
:
10px
8%
;
-webkit-box-sizing
:
$blux
;
}
}
margin
:
10px
5px
;
margin
:
10px
5px
;
}
}
...
...
src/token.hpp
View file @
33c5ecdf
...
@@ -16,6 +16,11 @@ namespace Sass {
...
@@ -16,6 +16,11 @@ namespace Sass {
unsigned
int
_line_number
);
unsigned
int
_line_number
);
Token
(
const
Token
&
t
);
Token
(
const
Token
&
t
);
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
);
}
inline
operator
string
()
const
{
return
string
(
begin
,
end
-
begin
);
}
inline
bool
operator
<
(
const
Token
&
rhs
)
const
{
return
(
begin
<
rhs
.
begin
)
||
(
begin
==
rhs
.
begin
&&
end
<
rhs
.
end
);
}
};
};
}
}
\ 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