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
059ce633
Commit
059ce633
authored
Mar 28, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More refactoring.
parent
4fa3b14c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
50 deletions
+90
-50
document_eval_pending.cpp
document_eval_pending.cpp
+52
-42
eval_apply.cpp
eval_apply.cpp
+33
-4
eval_apply.hpp
eval_apply.hpp
+5
-4
No files found.
document_eval_pending.cpp
View file @
059ce633
...
@@ -5,50 +5,59 @@ namespace Sass {
...
@@ -5,50 +5,59 @@ namespace Sass {
void
Document
::
eval_pending
()
void
Document
::
eval_pending
()
{
{
for
(
int
i
=
0
;
i
<
context
.
pending
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
context
.
pending
.
size
();
++
i
)
{
Node
n
(
context
.
pending
[
i
]);
switch
(
n
.
type
)
{
case
Node
:
:
assignment
:
{
Node
val
(
n
[
1
]);
if
(
val
.
type
==
Node
::
comma_list
||
val
.
type
==
Node
::
space_list
)
{
for
(
int
i
=
0
;
i
<
val
.
size
();
++
i
)
{
if
(
val
[
i
].
eval_me
)
val
[
i
]
=
eval
(
val
[
i
],
context
.
global_env
);
}
}
else
{
val
=
eval
(
val
,
context
.
global_env
);
}
context
.
global_env
[
n
[
0
].
token
]
=
val
;
}
break
;
case
Node
:
:
rule
:
{
eval
(
context
.
pending
[
i
],
context
.
global_env
);
// treat top-level lists differently from nested ones
// Node rhs(n[1]);
// if (rhs.type == Node::comma_list || rhs.type == Node::space_list) {
// for (int i = 0; i < rhs.size(); ++i) {
// if (rhs[i].eval_me) rhs[i] = eval(rhs[i], context.global_env);
// }
// }
// else {
// n[1] = eval(n[1], context.global_env);
// }
eval
(
n
,
context
.
global_env
);
}
break
;
case
Node
:
:
mixin
:
{
context
.
global_env
[
n
[
0
].
token
]
=
n
;
}
break
;
case
Node
:
:
expansion
:
{
// Node n(context.pending[i]);
Token
name
(
n
[
0
].
token
);
// switch (n.type)
Node
args
(
n
[
1
]);
// {
Node
mixin
(
context
.
global_env
[
name
]);
// // case Node::assignment: {
n
.
children
->
pop_back
();
// // // Node val(n[1]);
n
.
children
->
pop_back
();
// // // if (val.type == Node::comma_list || val.type == Node::space_list) {
n
+=
apply
(
mixin
,
args
,
context
.
global_env
);
// // // for (int i = 0; i < val.size(); ++i) {
}
break
;
// // // if (val[i].eval_me) val[i] = eval(val[i], context.global_env);
}
// // // }
// // // }
// // // else {
// // // val = eval(val, context.global_env);
// // // }
// // // context.global_env[n[0].token] = val;
// //
// // eval(n, context.global_env);
// // } break;
// //
// // case Node::rule: {
// // // treat top-level lists differently from nested ones
// // // Node rhs(n[1]);
// // // if (rhs.type == Node::comma_list || rhs.type == Node::space_list) {
// // // for (int i = 0; i < rhs.size(); ++i) {
// // // if (rhs[i].eval_me) rhs[i] = eval(rhs[i], context.global_env);
// // // }
// // // }
// // // else {
// // // n[1] = eval(n[1], context.global_env);
// // // }
// //
// // eval(n, context.global_env);
// // } break;
// //
// // case Node::mixin: {
// // // context.global_env[n[0].token] = n;
// //
// // eval(n, context.global_env);
// // } break;
//
// // case Node::expansion: {
// // Token name(n[0].token);
// // Node args(n[1]);
// // Node mixin(context.global_env[name]);
// // n.children->pop_back();
// // n.children->pop_back();
// // n += apply(mixin, args, context.global_env);
// // } break;
//
// default: eval(n, context.global_env);
// }
}
}
}
}
}
}
\ No newline at end of file
eval_apply.cpp
View file @
059ce633
...
@@ -5,10 +5,39 @@
...
@@ -5,10 +5,39 @@
namespace
Sass
{
namespace
Sass
{
using
std
::
cerr
;
using
std
::
endl
;
using
std
::
cerr
;
using
std
::
endl
;
Node
eval
(
const
Node
&
expr
,
Environment
&
env
)
Node
eval
(
Node
&
expr
,
Environment
&
env
)
{
{
switch
(
expr
.
type
)
switch
(
expr
.
type
)
{
{
case
Node
:
:
mixin
:
{
env
[
expr
[
0
].
token
]
=
expr
;
return
expr
;
}
break
;
case
Node
:
:
expansion
:
{
Token
name
(
expr
[
0
].
token
);
Node
args
(
expr
[
1
]);
Node
mixin
(
env
[
name
]);
expr
.
children
->
pop_back
();
expr
.
children
->
pop_back
();
expr
+=
apply
(
mixin
,
args
,
env
);
return
expr
;
}
break
;
case
Node
:
:
assignment
:
{
Node
val
(
expr
[
1
]);
if
(
val
.
type
==
Node
::
comma_list
||
val
.
type
==
Node
::
space_list
)
{
for
(
int
i
=
0
;
i
<
val
.
size
();
++
i
)
{
if
(
val
[
i
].
eval_me
)
val
[
i
]
=
eval
(
val
[
i
],
env
);
}
}
else
{
val
=
eval
(
val
,
env
);
}
env
[
expr
[
0
].
token
]
=
val
;
return
expr
;
}
break
;
case
Node
:
:
rule
:
{
case
Node
:
:
rule
:
{
Node
rhs
(
expr
[
1
]);
Node
rhs
(
expr
[
1
]);
if
(
rhs
.
type
==
Node
::
comma_list
||
rhs
.
type
==
Node
::
space_list
)
{
if
(
rhs
.
type
==
Node
::
comma_list
||
rhs
.
type
==
Node
::
space_list
)
{
...
@@ -97,7 +126,7 @@ namespace Sass {
...
@@ -97,7 +126,7 @@ namespace Sass {
}
}
}
}
Node
accumulate
(
const
Node
::
Type
op
,
Node
&
acc
,
Node
&
rhs
)
Node
accumulate
(
Node
::
Type
op
,
Node
&
acc
,
Node
&
rhs
)
{
{
Node
lhs
(
acc
.
children
->
back
());
Node
lhs
(
acc
.
children
->
back
());
double
lnum
=
lhs
.
numeric_value
;
double
lnum
=
lhs
.
numeric_value
;
...
@@ -174,7 +203,7 @@ namespace Sass {
...
@@ -174,7 +203,7 @@ namespace Sass {
return
acc
;
return
acc
;
}
}
double
operate
(
const
Node
::
Type
op
,
double
lhs
,
double
rhs
)
double
operate
(
Node
::
Type
op
,
double
lhs
,
double
rhs
)
{
{
// TO DO: check for division by zero
// TO DO: check for division by zero
switch
(
op
)
switch
(
op
)
...
@@ -187,7 +216,7 @@ namespace Sass {
...
@@ -187,7 +216,7 @@ namespace Sass {
}
}
}
}
Node
apply
(
const
Node
&
mixin
,
const
Node
&
args
,
Environment
&
env
)
Node
apply
(
Node
&
mixin
,
const
Node
&
args
,
Environment
&
env
)
{
{
Node
params
(
mixin
[
1
]);
Node
params
(
mixin
[
1
]);
Node
body
(
mixin
[
2
].
clone
());
Node
body
(
mixin
[
2
].
clone
());
...
...
eval_apply.hpp
View file @
059ce633
...
@@ -11,9 +11,9 @@
...
@@ -11,9 +11,9 @@
namespace
Sass
{
namespace
Sass
{
using
std
::
map
;
using
std
::
map
;
Node
eval
(
const
Node
&
expr
,
Environment
&
env
);
Node
eval
(
Node
&
expr
,
Environment
&
env
);
Node
accumulate
(
const
Node
::
Type
op
,
Node
&
acc
,
Node
&
rhs
);
Node
accumulate
(
Node
::
Type
op
,
Node
&
acc
,
Node
&
rhs
);
double
operate
(
const
Node
::
Type
op
,
double
lhs
,
double
rhs
);
double
operate
(
Node
::
Type
op
,
double
lhs
,
double
rhs
);
Node
apply
(
const
Node
&
mixin
,
const
Node
&
args
,
Environment
&
env
);
Node
apply
(
Node
&
mixin
,
const
Node
&
args
,
Environment
&
env
);
}
}
\ 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