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
633fe09d
Commit
633fe09d
authored
May 29, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on full-blown selector comparison (necessary for full-blown inheritance).
parent
46fd6b34
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
9 deletions
+50
-9
node.cpp
node.cpp
+34
-5
node.hpp
node.hpp
+4
-4
test_node_factory.cpp
test_node_factory.cpp
+12
-0
No files found.
node.cpp
View file @
633fe09d
#include <sstream>
#include <sstream>
#include <algorithm>
#include "node.hpp"
#include "node.hpp"
#include "error.hpp"
#include "error.hpp"
...
@@ -91,10 +92,13 @@ namespace Sass {
...
@@ -91,10 +92,13 @@ namespace Sass {
Type
lhs_type
=
type
();
Type
lhs_type
=
type
();
Type
rhs_type
=
rhs
.
type
();
Type
rhs_type
=
rhs
.
type
();
// comparing atomic numbers
if
((
lhs_type
==
number
&&
rhs_type
==
number
)
||
if
((
lhs_type
==
number
&&
rhs_type
==
number
)
||
(
lhs_type
==
numeric_percentage
&&
rhs_type
==
numeric_percentage
))
{
(
lhs_type
==
numeric_percentage
&&
rhs_type
==
numeric_percentage
))
{
return
numeric_value
()
<
rhs
.
numeric_value
();
return
numeric_value
()
<
rhs
.
numeric_value
();
}
}
// comparing numbers with units
else
if
(
lhs_type
==
numeric_dimension
&&
rhs_type
==
numeric_dimension
)
{
else
if
(
lhs_type
==
numeric_dimension
&&
rhs_type
==
numeric_dimension
)
{
if
(
unit
()
==
rhs
.
unit
())
{
if
(
unit
()
==
rhs
.
unit
())
{
return
numeric_value
()
<
rhs
.
numeric_value
();
return
numeric_value
()
<
rhs
.
numeric_value
();
...
@@ -103,23 +107,48 @@ namespace Sass {
...
@@ -103,23 +107,48 @@ namespace Sass {
throw
Error
(
Error
::
evaluation
,
path
(),
line
(),
"incompatible units"
);
throw
Error
(
Error
::
evaluation
,
path
(),
line
(),
"incompatible units"
);
}
}
}
}
else
if
((
type
()
>=
selector_group
&&
type
()
<=
selector_schema
)
&&
// comparing colors
else
if
(
lhs_type
==
numeric_color
&&
rhs_type
==
numeric_color
)
{
return
lexicographical_compare
(
begin
(),
end
(),
rhs
.
begin
(),
rhs
.
end
());
}
// comparing identifiers and strings (treat them as comparable)
else
if
((
lhs_type
==
identifier
||
lhs_type
==
string_constant
||
lhs_type
==
value
)
&&
(
rhs_type
==
identifier
||
lhs_type
==
string_constant
||
rhs_type
==
value
))
{
return
token
().
unquote
()
<
rhs
.
token
().
unquote
();
}
// COMPARING SELECTORS -- IMPORTANT FOR INHERITANCE
else
if
((
type
()
>=
selector_group
&&
type
()
<=
selector_schema
)
&&
(
rhs
.
type
()
>=
selector_group
&&
rhs
.
type
()
<=
selector_schema
))
{
(
rhs
.
type
()
>=
selector_group
&&
rhs
.
type
()
<=
selector_schema
))
{
if
(
type
()
!=
rhs
.
type
())
{
return
type
()
<
rhs
.
type
();
// if they're not the same kind, just compare type tags
}
if
(
type
()
!=
rhs
.
type
())
return
type
()
<
rhs
.
type
();
// otherwise we have to do more work
switch
(
type
())
switch
(
type
())
{
{
case
simple_selector
:
{
case
simple_selector
:
case
pseudo
:
{
return
token
()
<
rhs
.
token
();
return
token
()
<
rhs
.
token
();
}
break
;
}
break
;
case
attribute_selector
:
{
return
lexicographical_compare
(
begin
(),
end
(),
rhs
.
begin
(),
rhs
.
end
());
}
break
;
default
:
{
default
:
{
return
false
;
return
false
;
}
break
;
}
break
;
}
}
}
}
// END OF SELECTOR COMPARISON
// catch-all
else
{
else
{
throw
Error
(
Error
::
evaluation
,
path
(),
line
(),
"incomparable types"
);
throw
Error
(
Error
::
evaluation
,
path
(),
line
(),
"incomparable types"
);
}
}
...
...
node.hpp
View file @
633fe09d
...
@@ -178,8 +178,8 @@ namespace Sass {
...
@@ -178,8 +178,8 @@ namespace Sass {
Node
&
operator
<<
(
Node
n
);
Node
&
operator
<<
(
Node
n
);
Node
&
operator
+=
(
Node
n
);
Node
&
operator
+=
(
Node
n
);
vector
<
Node
>::
iterator
begin
();
vector
<
Node
>::
iterator
begin
()
const
;
vector
<
Node
>::
iterator
end
();
vector
<
Node
>::
iterator
end
()
const
;
void
insert
(
vector
<
Node
>::
iterator
position
,
void
insert
(
vector
<
Node
>::
iterator
position
,
vector
<
Node
>::
iterator
first
,
vector
<
Node
>::
iterator
first
,
vector
<
Node
>::
iterator
last
);
vector
<
Node
>::
iterator
last
);
...
@@ -355,9 +355,9 @@ namespace Sass {
...
@@ -355,9 +355,9 @@ namespace Sass {
return
*
this
;
return
*
this
;
}
}
inline
vector
<
Node
>::
iterator
Node
::
begin
()
inline
vector
<
Node
>::
iterator
Node
::
begin
()
const
{
return
ip_
->
children
.
begin
();
}
{
return
ip_
->
children
.
begin
();
}
inline
vector
<
Node
>::
iterator
Node
::
end
()
inline
vector
<
Node
>::
iterator
Node
::
end
()
const
{
return
ip_
->
children
.
end
();
}
{
return
ip_
->
children
.
end
();
}
inline
void
Node
::
insert
(
vector
<
Node
>::
iterator
position
,
inline
void
Node
::
insert
(
vector
<
Node
>::
iterator
position
,
vector
<
Node
>::
iterator
first
,
vector
<
Node
>::
iterator
first
,
...
...
test_node_factory.cpp
View file @
633fe09d
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include <string>
#include <string>
#include <tr1/unordered_map>
#include <tr1/unordered_map>
#include <map>
#include <map>
#include <algorithm>
#ifndef SASS_NODE_INCLUDED
#ifndef SASS_NODE_INCLUDED
#include "node.hpp"
#include "node.hpp"
...
@@ -75,6 +76,17 @@ int main()
...
@@ -75,6 +76,17 @@ int main()
cout
<<
dict
[
m
]
<<
" "
<<
dict
[
n
]
<<
endl
;
cout
<<
dict
[
m
]
<<
" "
<<
dict
[
n
]
<<
endl
;
cout
<<
"Lexicographical comparison: "
<<
endl
;
cout
<<
lexicographical_compare
(
num2
.
begin
(),
num2
.
end
(),
num3
.
begin
(),
num3
.
end
())
<<
endl
;
cout
<<
lexicographical_compare
(
num
.
begin
(),
num
.
end
(),
num2
.
begin
(),
num2
.
end
())
<<
endl
;
cout
<<
lexicographical_compare
(
num3
.
begin
(),
num3
.
end
(),
num
.
begin
(),
num
.
end
())
<<
endl
<<
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