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
d235ff2d
Commit
d235ff2d
authored
Mar 14, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on handling imports.
parent
0f2b1c70
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
54 additions
and
13 deletions
+54
-13
context.cpp
context.cpp
+0
-0
context.hpp
context.hpp
+9
-0
document.cpp
document.cpp
+13
-8
document.hpp
document.hpp
+7
-2
document_parser.cpp
document_parser.cpp
+4
-3
prelexer.cpp
prelexer.cpp
+10
-0
prelexer.hpp
prelexer.hpp
+6
-0
unit-test-prelexer.cpp
unit-test-prelexer.cpp
+5
-0
No files found.
context.cpp
0 → 100644
View file @
d235ff2d
context.hpp
0 → 100644
View file @
d235ff2d
namespace
Sass
{
using
std
::
map
;
struct
Context
{
map
<
Token
,
Node
>
environment
;
Context
()
:
environment
(
map
<
Token
,
Node
>
())
{
}
};
}
\ No newline at end of file
document.cpp
View file @
d235ff2d
...
@@ -3,9 +3,14 @@
...
@@ -3,9 +3,14 @@
namespace
Sass
{
namespace
Sass
{
Document
::
Document
(
char
*
_path
,
char
*
_source
)
{
Document
::
Document
(
char
*
path
,
char
*
source
)
path
=
_path
;
:
path
(
path
),
source
(
source
),
if
(
!
_source
)
{
line_number
(
1
),
own_source
(
false
),
context
(
*
(
new
Context
())),
statements
(
vector
<
Node
>
()),
lexed
(
Token
())
{
if
(
!
source
)
{
std
::
FILE
*
f
;
std
::
FILE
*
f
;
// TO DO: CHECK f AGAINST NULL/0
// TO DO: CHECK f AGAINST NULL/0
f
=
std
::
fopen
(
path
,
"rb"
);
f
=
std
::
fopen
(
path
,
"rb"
);
...
@@ -17,16 +22,15 @@ namespace Sass {
...
@@ -17,16 +22,15 @@ namespace Sass {
std
::
fread
(
source
,
sizeof
(
char
),
len
,
f
);
std
::
fread
(
source
,
sizeof
(
char
),
len
,
f
);
source
[
len
]
=
'\0'
;
source
[
len
]
=
'\0'
;
std
::
fclose
(
f
);
std
::
fclose
(
f
);
}
own_source
=
true
;
else
{
source
=
_source
;
}
}
position
=
source
;
position
=
source
;
line_number
=
1
;
// printf("INPUT FILE:\n%s", source)
;
}
}
Document
::~
Document
()
{
Document
::~
Document
()
{
delete
[]
source
;
if
(
own_source
)
delete
[]
source
;
delete
&
context
;
}
}
}
}
\ No newline at end of file
document.hpp
View file @
d235ff2d
#include <map>
#include <map>
#include "node.hpp"
#include "node.hpp"
#include "context.hpp"
namespace
Sass
{
namespace
Sass
{
using
std
::
vector
;
using
std
::
vector
;
...
@@ -13,14 +14,18 @@ namespace Sass {
...
@@ -13,14 +14,18 @@ namespace Sass {
char
*
source
;
char
*
source
;
char
*
position
;
char
*
position
;
size_t
line_number
;
size_t
line_number
;
bool
own_source
;
// TO DO: move the environment up into the context class when it's ready
// TO DO: move the environment up into the context class when it's ready
map
<
Token
,
Node
>
environment
;
// map<Token, Node> environment;
Context
&
context
;
vector
<
Node
>
statements
;
vector
<
Node
>
statements
;
Token
lexed
;
Token
lexed
;
Document
(
char
*
_path
,
char
*
_source
=
0
);
Document
(
char
*
path
,
char
*
source
=
0
);
// Document(char* path, Context& context);
~
Document
();
~
Document
();
template
<
prelexer
mx
>
template
<
prelexer
mx
>
...
...
document_parser.cpp
View file @
d235ff2d
...
@@ -11,7 +11,7 @@ namespace Sass {
...
@@ -11,7 +11,7 @@ namespace Sass {
if
(
lex
<
block_comment
>
())
{
if
(
lex
<
block_comment
>
())
{
statements
.
push_back
(
Node
(
line_number
,
Node
::
comment
,
lexed
));
statements
.
push_back
(
Node
(
line_number
,
Node
::
comment
,
lexed
));
}
}
else
if
(
lex
<
variable
>
(
))
{
else
if
(
peek
<
variable
>
(
position
))
{
parse_var_def
();
parse_var_def
();
lex
<
exactly
<
';'
>
>
();
lex
<
exactly
<
';'
>
>
();
}
}
...
@@ -24,9 +24,10 @@ namespace Sass {
...
@@ -24,9 +24,10 @@ namespace Sass {
void
Document
::
parse_var_def
()
void
Document
::
parse_var_def
()
{
{
lex
<
variable
>
();
const
Token
key
(
lexed
);
const
Token
key
(
lexed
);
lex
<
exactly
<
':'
>
>
();
lex
<
exactly
<
':'
>
>
();
environment
[
key
]
=
parse_values
();
context
.
environment
[
key
]
=
parse_values
();
}
}
Node
Document
::
parse_ruleset
()
Node
Document
::
parse_ruleset
()
...
@@ -209,7 +210,7 @@ namespace Sass {
...
@@ -209,7 +210,7 @@ namespace Sass {
lex
<
hex
>
()
||
lex
<
string_constant
>
()
||
lex
<
hex
>
()
||
lex
<
string_constant
>
()
||
lex
<
variable
>
())
{
lex
<
variable
>
())
{
if
(
lexed
.
begin
[
0
]
==
'$'
)
{
if
(
lexed
.
begin
[
0
]
==
'$'
)
{
Node
fetched
(
environment
[
lexed
]);
Node
fetched
(
context
.
environment
[
lexed
]);
for
(
int
i
=
0
;
i
<
fetched
.
children
->
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
fetched
.
children
->
size
();
++
i
)
{
values
<<
fetched
.
children
->
at
(
i
);
values
<<
fetched
.
children
->
at
(
i
);
}
}
...
...
prelexer.cpp
View file @
d235ff2d
...
@@ -13,6 +13,9 @@ namespace Sass {
...
@@ -13,6 +13,9 @@ namespace Sass {
return
*
src
?
0
:
src
;
return
*
src
?
0
:
src
;
}
}
// Match any single character.
char
*
any_char
(
char
*
src
)
{
return
*
src
?
src
++
:
src
;
}
// Match a single character satisfying the ctype predicates.
// Match a single character satisfying the ctype predicates.
char
*
space
(
char
*
src
)
{
return
std
::
isspace
(
*
src
)
?
src
+
1
:
0
;
}
char
*
space
(
char
*
src
)
{
return
std
::
isspace
(
*
src
)
?
src
+
1
:
0
;
}
char
*
alpha
(
char
*
src
)
{
return
std
::
isalpha
(
*
src
)
?
src
+
1
:
0
;
}
char
*
alpha
(
char
*
src
)
{
return
std
::
isalpha
(
*
src
)
?
src
+
1
:
0
;
}
...
@@ -197,5 +200,11 @@ namespace Sass {
...
@@ -197,5 +200,11 @@ namespace Sass {
return
sequence
<
exactly
<
'$'
>
,
name
>
(
src
);
return
sequence
<
exactly
<
'$'
>
,
name
>
(
src
);
}
}
// Path matching functions.
char
*
folder
(
char
*
src
)
{
return
sequence
<
zero_plus
<
negate
<
exactly
<
'/'
>
>
>
,
exactly
<
'/'
>
>
(
src
);
}
}
}
}
}
\ No newline at end of file
prelexer.hpp
View file @
d235ff2d
...
@@ -84,6 +84,9 @@ namespace Sass {
...
@@ -84,6 +84,9 @@ namespace Sass {
}
}
}
}
// Match any single character.
char
*
any_char
(
char
*
src
);
// Matches zero characters (always succeeds without consuming input).
// Matches zero characters (always succeeds without consuming input).
char
*
epsilon
(
char
*
);
char
*
epsilon
(
char
*
);
...
@@ -308,6 +311,9 @@ namespace Sass {
...
@@ -308,6 +311,9 @@ namespace Sass {
// Match SCSS variable names.
// Match SCSS variable names.
char
*
variable
(
char
*
src
);
char
*
variable
(
char
*
src
);
// Path matching functions.
char
*
folder
(
char
*
src
);
// Utility functions for finding and counting characters in a string.
// Utility functions for finding and counting characters in a string.
template
<
char
c
>
template
<
char
c
>
char
*
find_first
(
char
*
src
)
{
char
*
find_first
(
char
*
src
)
{
...
...
unit-test-prelexer.cpp
View file @
d235ff2d
...
@@ -54,6 +54,9 @@ char nonanc1[] = " { blah";
...
@@ -54,6 +54,9 @@ char nonanc1[] = " { blah";
char
bi1
[]
=
"+2n + 42"
;
char
bi1
[]
=
"+2n + 42"
;
char
bi2
[]
=
"23n+1"
;
char
bi2
[]
=
"23n+1"
;
char
nonbi1
[]
=
"- n+2"
;
char
nonbi1
[]
=
"- n+2"
;
char
fld1
[]
=
"blah/bloo/foo.txt"
;
char
fld2
[]
=
"/bloo/blee"
;
char
nonfld1
[]
=
"blah.txt"
;
extern
const
char
slash_star
[]
=
"/*"
;
extern
const
char
slash_star
[]
=
"/*"
;
...
@@ -101,6 +104,8 @@ int main() {
...
@@ -101,6 +104,8 @@ int main() {
check_twice
(
ancestor_of
,
anc1
,
nonanc1
);
check_twice
(
ancestor_of
,
anc1
,
nonanc1
);
check_twice
(
binomial
,
bi1
,
nonbi1
);
check_twice
(
binomial
,
bi1
,
nonbi1
);
check_twice
(
binomial
,
bi2
,
nonbi1
);
check_twice
(
binomial
,
bi2
,
nonbi1
);
check_twice
(
folder
,
fld1
,
nonfld1
);
check_twice
(
folder
,
fld2
,
nonfld1
);
cout
<<
count_interval
<
'\n'
>
(
ws1
,
spaces_and_comments
(
ws1
))
<<
endl
;
cout
<<
count_interval
<
'\n'
>
(
ws1
,
spaces_and_comments
(
ws1
))
<<
endl
;
cout
<<
count_interval
<
'*'
>
(
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
;
cout
<<
count_interval
<
exactly
<
slash_star
>
>
(
ws1
,
spaces_and_comments
(
ws1
))
<<
endl
;
...
...
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