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
d3b2584d
Commit
d3b2584d
authored
Feb 29, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parsing and echoing works.
parent
2e424258
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
3 deletions
+85
-3
document.cpp
src/document.cpp
+26
-2
document.hpp
src/document.hpp
+2
-0
node.cpp
src/node.cpp
+52
-0
node.hpp
src/node.hpp
+3
-0
unit-test-document.cpp
src/unit-test-document.cpp
+2
-1
No files found.
src/document.cpp
View file @
d3b2584d
...
...
@@ -59,15 +59,38 @@ namespace Sass {
Node
Document
::
parse_declarations
()
{
try_munching
<
exactly
<
'{'
>
>
();
Node
decls
(
Node
::
declarations
);
while
(
!
try_munching
<
exactly
<
'}'
>
>
())
{
if
(
try_munching
<
block_comment
>
())
{
decls
.
push_child
(
Node
(
Node
::
comment
,
top
));
continue
;
}
try_munching
<
identifier
>
();
Token
id
=
top
;
if
(
try_munching
<
exactly
<
':'
>
>
())
{
Node
rule
(
Node
::
rule
);
rule
.
push_child
(
Node
(
Node
::
property
,
id
));
rule
.
push_child
(
Node
(
Node
::
value
,
parse_value
()));
return
rule
;
rule
.
push_child
(
parse_values
());
decls
.
push_child
(
rule
);
try_munching
<
exactly
<
';'
>
>
();
}
else
{
Node
ruleset
(
Node
::
ruleset
);
ruleset
.
push_child
(
Node
(
Node
::
selector
,
id
));
ruleset
.
push_child
(
parse_declarations
());
decls
.
push_opt_child
(
ruleset
);
}
}
return
decls
;
}
Node
Document
::
parse_values
()
{
Node
values
(
Node
::
values
);
while
(
try_munching
<
identifier
>
()
||
try_munching
<
dimension
>
()
||
try_munching
<
percentage
>
()
||
try_munching
<
number
>
())
{
values
.
push_child
(
Node
(
Node
::
value
,
top
));
}
return
values
;
}
}
\ No newline at end of file
src/document.hpp
View file @
d3b2584d
...
...
@@ -59,6 +59,7 @@ namespace Sass {
Node
parse_ruleset
();
Node
parse_selector
();
Node
parse_declarations
();
Node
parse_values
();
};
}
\ No newline at end of file
src/node.cpp
View file @
d3b2584d
#include <iostream>
#include "node.hpp"
#include <string>
using
std
::
string
;
using
std
::
cout
;
using
std
::
endl
;
namespace
Sass
{
Node
::
Node
()
{
}
...
...
@@ -15,4 +21,49 @@ namespace Sass {
void
Node
::
push_opt_child
(
const
Node
&
node
)
{
opt_children
.
push_back
(
node
);
}
void
Node
::
dump
(
unsigned
int
depth
)
{
switch
(
type
)
{
case
comment
:
for
(
int
i
=
depth
;
i
>
0
;
--
i
)
cout
<<
" "
;
cout
<<
string
(
token
)
<<
endl
;
break
;
case
selector
:
cout
<<
string
(
token
);
break
;
case
value
:
cout
<<
string
(
token
);
break
;
case
property
:
cout
<<
string
(
token
)
<<
":"
;
break
;
case
values
:
for
(
int
i
=
0
;
i
<
children
.
size
();
++
i
)
cout
<<
" "
<<
string
(
children
[
i
].
token
);
break
;
case
rule
:
for
(
int
i
=
depth
;
i
>
0
;
--
i
)
cout
<<
" "
;
children
[
0
].
dump
(
depth
);
children
[
1
].
dump
(
depth
);
cout
<<
";"
<<
endl
;
break
;
case
declarations
:
cout
<<
" {"
<<
endl
;
for
(
int
i
=
0
;
i
<
children
.
size
();
++
i
)
{
children
[
i
].
dump
(
depth
+
1
);
}
for
(
int
i
=
0
;
i
<
opt_children
.
size
();
++
i
)
{
opt_children
[
i
].
dump
(
depth
+
1
);
}
for
(
int
i
=
depth
;
i
>
0
;
--
i
)
cout
<<
" "
;
cout
<<
"}"
<<
endl
;
break
;
case
ruleset
:
for
(
int
i
=
depth
;
i
>
0
;
--
i
)
cout
<<
" "
;
children
[
0
].
dump
(
depth
);
children
[
1
].
dump
(
depth
);
break
;
default
:
cout
<<
"HUH?"
;
break
;
}
}
}
\ No newline at end of file
src/node.hpp
View file @
d3b2584d
...
...
@@ -15,6 +15,7 @@ namespace Sass {
simple_selector
,
rule
,
property
,
values
,
value
,
lookahead_sequence
,
lookahead_token
...
...
@@ -30,5 +31,6 @@ namespace Sass {
Node
(
Node_Type
_type
,
Token
&
_token
);
void
push_child
(
const
Node
&
node
);
void
push_opt_child
(
const
Node
&
node
);
void
dump
(
unsigned
int
depth
);
};
}
\ No newline at end of file
src/unit-test-document.cpp
View file @
d3b2584d
...
...
@@ -35,6 +35,7 @@ int main(int argc, char* argv[]) {
print_slice
(
doc
.
top
.
begin
,
doc
.
top
.
end
);
printf
(
"sizeof char is %ld
\n
"
,
sizeof
(
char
));
printf
(
"sizeof int is %ld
\n
"
,
sizeof
(
int
));
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
>
));
...
...
@@ -51,7 +52,7 @@ int main(int argc, char* argv[]) {
int
j
=
doc
.
statements
.
size
();
printf
(
"%d
\n
"
,
j
);
for
(
i
=
0
;
i
<
j
;
++
i
)
{
print_slice
(
doc
.
statements
[
i
].
token
.
begin
,
doc
.
statements
[
i
].
token
.
end
);
doc
.
statements
[
i
].
dump
(
0
);
}
}
...
...
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