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
193110d6
Commit
193110d6
authored
Mar 15, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changing the way nodes are stored at the root level. Makes for easier tree splicing.
parent
81ac5275
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
77 additions
and
21 deletions
+77
-21
document.cpp
document.cpp
+28
-4
document.hpp
document.hpp
+8
-4
document_emitter.cpp
document_emitter.cpp
+16
-5
document_parser.cpp
document_parser.cpp
+16
-2
node.cpp
node.cpp
+5
-3
node.hpp
node.hpp
+1
-0
token.cpp
token.cpp
+2
-2
token.hpp
token.hpp
+1
-1
No files found.
document.cpp
View file @
193110d6
...
...
@@ -3,17 +3,19 @@
namespace
Sass
{
Document
::
Document
(
char
*
path
,
char
*
source
)
Document
::
Document
(
string
path
,
char
*
source
)
:
path
(
path
),
source
(
source
),
line_number
(
1
),
own_source
(
false
),
context
(
*
(
new
Context
())),
statements
(
vector
<
Node
>
()),
root
(
Node
(
1
,
Node
::
root
)),
// statements(vector<Node>()),
lexed
(
Token
())
{
// if (!source) read_file();
if
(
!
source
)
{
std
::
FILE
*
f
;
// TO DO: CHECK f AGAINST NULL/0
f
=
std
::
fopen
(
path
,
"rb"
);
f
=
std
::
fopen
(
path
.
c_str
()
,
"rb"
);
std
::
fseek
(
f
,
0
,
SEEK_END
);
int
len
=
std
::
ftell
(
f
);
std
::
rewind
(
f
);
...
...
@@ -25,7 +27,29 @@ namespace Sass {
own_source
=
true
;
}
position
=
source
;
// printf("INPUT FILE:\n%s", source);
}
Document
::
Document
(
string
path
,
Context
&
context
)
:
path
(
path
),
source
(
source
),
line_number
(
1
),
own_source
(
false
),
context
(
context
),
root
(
Node
(
1
,
Node
::
root
)),
// statements(vector<Node>()),
lexed
(
Token
())
{
std
::
FILE
*
f
;
// TO DO: CHECK f AGAINST NULL/0
f
=
std
::
fopen
(
path
.
c_str
(),
"rb"
);
std
::
fseek
(
f
,
0
,
SEEK_END
);
int
len
=
std
::
ftell
(
f
);
std
::
rewind
(
f
);
// TO DO: WRAP THE new[] IN A TRY/CATCH BLOCK
source
=
new
char
[
len
+
1
];
std
::
fread
(
source
,
sizeof
(
char
),
len
,
f
);
source
[
len
]
=
'\0'
;
std
::
fclose
(
f
);
own_source
=
true
;
position
=
source
;
}
Document
::~
Document
()
{
...
...
document.hpp
View file @
193110d6
...
...
@@ -3,6 +3,7 @@
#include "context.hpp"
namespace
Sass
{
using
std
::
string
;
using
std
::
vector
;
using
std
::
map
;
using
namespace
Prelexer
;
...
...
@@ -10,7 +11,7 @@ namespace Sass {
struct
Document
{
enum
CSS_Style
{
nested
,
expanded
,
compact
,
compressed
,
echo
};
char
*
path
;
string
path
;
char
*
source
;
char
*
position
;
size_t
line_number
;
...
...
@@ -21,11 +22,12 @@ namespace Sass {
Context
&
context
;
vector
<
Node
>
statements
;
Node
root
;
// vector<Node> statements;
Token
lexed
;
Document
(
char
*
path
,
char
*
source
=
0
);
// Document(char*
path, Context& context);
Document
(
string
path
,
char
*
source
=
0
);
Document
(
string
path
,
Context
&
context
);
~
Document
();
template
<
prelexer
mx
>
...
...
@@ -120,5 +122,6 @@ namespace Sass {
char
*
look_for_values
(
char
*
start
=
0
);
string
emit_css
(
CSS_Style
style
);
};
}
\ No newline at end of file
document_emitter.cpp
View file @
193110d6
...
...
@@ -7,19 +7,30 @@ namespace Sass {
string
Document
::
emit_css
(
CSS_Style
style
)
{
stringstream
output
;
for
(
int
i
=
0
;
i
<
statements
.
size
();
++
i
)
{
// for (int i = 0; i < statements.size(); ++i) {
// switch (style) {
// case echo:
// statements[i].echo(output);
// break;
// case nested:
// statements[i].emit_nested_css(output, 0, vector<string>());
// break;
// case expanded:
// statements[i].emit_expanded_css(output, "");
// break;
// }
// }
switch
(
style
)
{
case
echo
:
statements
[
i
]
.
echo
(
output
);
root
.
echo
(
output
);
break
;
case
nested
:
statements
[
i
]
.
emit_nested_css
(
output
,
0
,
vector
<
string
>
());
root
.
emit_nested_css
(
output
,
0
,
vector
<
string
>
());
break
;
case
expanded
:
statements
[
i
]
.
emit_expanded_css
(
output
,
""
);
root
.
emit_expanded_css
(
output
,
""
);
break
;
}
}
string
retval
(
output
.
str
());
if
(
!
retval
.
empty
())
retval
.
resize
(
retval
.
size
()
-
1
);
return
retval
;
...
...
document_parser.cpp
View file @
193110d6
...
...
@@ -7,16 +7,30 @@ namespace Sass {
void
Document
::
parse_scss
()
{
lex
<
optional_spaces
>
();
// while(*position) {
// if (lex< block_comment >()) {
// statements.push_back(Node(line_number, Node::comment, lexed));
// }
// else if (peek< variable >(position)) {
// parse_var_def();
// lex< exactly<';'> >();
// }
// else {
// statements.push_back(parse_ruleset());
// }
// lex<optional_spaces>();
// }
while
(
*
position
)
{
if
(
lex
<
block_comment
>
())
{
statements
.
push_back
(
Node
(
line_number
,
Node
::
comment
,
lexed
)
);
root
<<
Node
(
line_number
,
Node
::
comment
,
lexed
);
}
else
if
(
peek
<
variable
>
(
position
))
{
parse_var_def
();
lex
<
exactly
<
';'
>
>
();
}
else
{
statements
.
push_back
(
parse_ruleset
()
);
root
<<
parse_ruleset
(
);
}
lex
<
optional_spaces
>
();
}
...
...
node.cpp
View file @
193110d6
...
...
@@ -77,6 +77,11 @@ namespace Sass {
const
vector
<
string
>&
prefixes
)
{
switch
(
type
)
{
case
root
:
for
(
int
i
=
0
;
i
<
children
->
size
();
++
i
)
{
children
->
at
(
i
).
emit_nested_css
(
buf
,
depth
,
prefixes
);
}
break
;
case
ruleset
:
{
Node
sel_group
(
children
->
at
(
0
));
Node
block
(
children
->
at
(
1
));
...
...
@@ -93,9 +98,6 @@ namespace Sass {
for
(
int
i
=
0
;
i
<
prefixes
.
size
();
++
i
)
{
for
(
int
j
=
0
;
j
<
sel_group
.
children
->
size
();
++
j
)
{
new_prefixes
.
push_back
(
sel_group
.
children
->
at
(
j
).
to_string
(
prefixes
[
i
]));
// new_prefixes.push_back(prefixes[i] +
// ' ' +
// string(sel_group.children->at(j)));
}
}
}
...
...
node.hpp
View file @
193110d6
...
...
@@ -10,6 +10,7 @@ namespace Sass {
struct
Node
{
enum
Type
{
nil
,
root
,
comment
,
ruleset
,
propset
,
...
...
token.cpp
View file @
193110d6
...
...
@@ -2,8 +2,8 @@
namespace
Sass
{
Token
::
Token
()
:
begin
(
0
),
end
(
0
)
{
}
Token
::
Token
(
const
char
*
_begin
,
const
char
*
_
end
)
:
begin
(
_begin
),
end
(
_
end
)
{
}
Token
::
Token
(
const
char
*
begin
,
const
char
*
end
)
:
begin
(
begin
),
end
(
end
)
{
}
void
Token
::
stream_unquoted
(
std
::
stringstream
&
buf
)
const
{
const
char
*
p
=
begin
;
...
...
token.hpp
View file @
193110d6
...
...
@@ -10,7 +10,7 @@ namespace Sass {
const
char
*
end
;
Token
();
Token
(
const
char
*
_begin
,
const
char
*
_
end
);
Token
(
const
char
*
begin
,
const
char
*
end
);
inline
operator
string
()
const
{
return
string
(
begin
,
end
-
begin
);
}
...
...
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