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
a5365756
Commit
a5365756
authored
Mar 27, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapting the old mixin parsing functions for the new parsing & expansion phases.
parent
aa3b799b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
161 additions
and
122 deletions
+161
-122
document.hpp
document.hpp
+11
-7
document_parser.cpp
document_parser.cpp
+146
-113
node.hpp
node.hpp
+4
-2
No files found.
document.hpp
View file @
a5365756
...
@@ -109,22 +109,24 @@ namespace Sass {
...
@@ -109,22 +109,24 @@ namespace Sass {
}
}
}
}
void
parse_scss
();
void
parse_scss
(
bool
definition
=
false
);
Node
parse_import
();
Node
parse_import
(
bool
definition
=
false
);
Node
parse_include
();
Node
parse_include
();
Node
parse_mixin_def
();
Node
parse_mixin_definition
();
Node
parse_mixin_parameters
();
Node
parse_parameter
();
Node
parse_parameter
();
Node
parse_arguments
();
Node
parse_mixin_call
();
Node
parse_mixin_params
();
Node
parse_mixin_arguments
();
Node
parse_argument
();
Node
parse_assignment
();
Node
parse_assignment
();
Node
parse_ruleset
();
Node
parse_ruleset
(
bool
definition
=
false
);
Node
parse_selector_group
();
Node
parse_selector_group
();
Node
parse_selector
();
Node
parse_selector
();
Node
parse_simple_selector_sequence
();
Node
parse_simple_selector_sequence
();
Node
parse_simple_selector
();
Node
parse_simple_selector
();
Node
parse_pseudo
();
Node
parse_pseudo
();
Node
parse_attribute_selector
();
Node
parse_attribute_selector
();
Node
parse_block
();
Node
parse_block
(
bool
definition
=
false
);
Node
parse_rule
();
Node
parse_rule
();
Node
parse_values
();
Node
parse_values
();
Node
parse_list
();
Node
parse_list
();
...
@@ -134,6 +136,8 @@ namespace Sass {
...
@@ -134,6 +136,8 @@ namespace Sass {
Node
parse_term
();
Node
parse_term
();
Node
parse_factor
();
Node
parse_factor
();
Node
parse_value
();
Node
parse_value
();
Node
parse_identifier
();
Node
parse_variable
();
const
char
*
look_for_rule
(
const
char
*
start
=
0
);
const
char
*
look_for_rule
(
const
char
*
start
=
0
);
const
char
*
look_for_values
(
const
char
*
start
=
0
);
const
char
*
look_for_values
(
const
char
*
start
=
0
);
...
...
document_parser.cpp
View file @
a5365756
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
namespace
Sass
{
namespace
Sass
{
using
namespace
std
;
using
namespace
std
;
void
Document
::
parse_scss
()
void
Document
::
parse_scss
(
bool
definition
)
{
{
lex
<
optional_spaces
>
();
lex
<
optional_spaces
>
();
while
(
*
position
)
{
while
(
*
position
)
{
...
@@ -13,32 +13,41 @@ namespace Sass {
...
@@ -13,32 +13,41 @@ namespace Sass {
root
<<
Node
(
line_number
,
Node
::
comment
,
lexed
);
root
<<
Node
(
line_number
,
Node
::
comment
,
lexed
);
}
}
else
if
(
peek
<
import
>
(
position
))
{
else
if
(
peek
<
import
>
(
position
))
{
root
+=
parse_import
();
root
+=
parse_import
(
definition
);
lex
<
exactly
<
';'
>
>
();
lex
<
exactly
<
';'
>
>
();
}
}
// else if (peek< include >(position)) {
else
if
(
peek
<
mixin
>
(
position
))
{
// Node to_include(parse_include());
// TO DO: check to see if we're already inside a definition in order
// root += to_include;
// to disallow definitions that are sneakily nested via imports.
// root.has_rules_or_comments |= to_include.has_rules_or_comments;
if
(
!
definition
)
context
.
pending
.
push_back
(
parse_mixin_definition
());
// root.has_rulesets |= to_include.has_rulesets;
}
// root.has_propsets |= to_include.has_propsets;
else
if
(
peek
<
include
>
(
position
))
{
// lex< exactly<';'> >();
Node
call
(
parse_mixin_call
());
// }
root
<<
call
;
// else if (peek< mixin >(position)) {
root
.
has_rules_or_comments
|=
call
.
has_rules_or_comments
;
// parse_mixin_def();
root
.
has_rulesets
|=
call
.
has_rulesets
;
// }
root
.
has_propsets
|=
call
.
has_propsets
;
lex
<
exactly
<
';'
>
>
();
if
(
!
definition
)
context
.
pending
.
push_back
(
call
);
}
else
if
(
peek
<
variable
>
(
position
))
{
else
if
(
peek
<
variable
>
(
position
))
{
context
.
pending
.
push_back
(
parse_assignment
());
Node
assn
(
parse_assignment
());
lex
<
exactly
<
';'
>
>
();
lex
<
exactly
<
';'
>
>
();
if
(
!
definition
)
{
context
.
pending
.
push_back
(
assn
);
}
else
{
root
<<
assn
;
}
}
}
else
{
else
{
root
<<
parse_ruleset
();
root
<<
parse_ruleset
(
definition
);
}
}
lex
<
optional_spaces
>
();
lex
<
optional_spaces
>
();
}
}
}
}
Node
Document
::
parse_import
()
Node
Document
::
parse_import
(
bool
definition
)
{
{
lex
<
import
>
();
lex
<
import
>
();
lex
<
string_constant
>
();
lex
<
string_constant
>
();
...
@@ -47,86 +56,102 @@ namespace Sass {
...
@@ -47,86 +56,102 @@ namespace Sass {
const
char
*
curr_path_end
=
folders
(
curr_path_start
);
const
char
*
curr_path_end
=
folders
(
curr_path_start
);
string
current_path
(
curr_path_start
,
curr_path_end
-
curr_path_start
);
string
current_path
(
curr_path_start
,
curr_path_end
-
curr_path_start
);
Document
importee
(
current_path
+
import_path
,
context
);
Document
importee
(
current_path
+
import_path
,
context
);
importee
.
parse_scss
();
importee
.
parse_scss
(
definition
);
return
importee
.
root
;
return
importee
.
root
;
}
}
Node
Document
::
parse_mixin_definition
()
{
lex
<
mixin
>
();
lex
<
identifier
>
();
Node
name
(
line_number
,
Node
::
identifier
,
lexed
);
Node
params
(
parse_mixin_parameters
());
Node
body
(
parse_block
(
true
));
Node
mixin
(
line_number
,
Node
::
mixin
,
3
);
mixin
<<
name
<<
params
<<
body
;
//
// cerr << "parsed mixin definition: ";
// cerr << string(mixin[0].token) << "(";
// if (params.size() > 0) {
// cerr << string(params[0].token);
// for (int i = 1; i < params.size(); ++i) {
// cerr << ", " << string(params[i].token);
// }
// }
// cerr << ")" << endl;
//
return
mixin
;
}
Node
Document
::
parse_mixin_parameters
()
{
Node
params
(
line_number
,
Node
::
parameters
);
lex
<
exactly
<
'('
>
>
();
if
(
peek
<
variable
>
())
{
params
<<
parse_parameter
();
while
(
lex
<
exactly
<
','
>
>
())
{
params
<<
parse_parameter
();
}
}
lex
<
exactly
<
')'
>
>
();
return
params
;
}
Node
Document
::
parse_parameter
()
{
lex
<
variable
>
();
Node
var
(
line_number
,
Node
::
variable
,
lexed
);
if
(
lex
<
exactly
<
':'
>
>
())
{
// default value
Node
val
(
parse_space_list
());
Node
par_and_val
(
line_number
,
Node
::
assignment
,
2
);
par_and_val
<<
var
<<
val
;
return
par_and_val
;
}
else
{
return
var
;
}
}
Node
Document
::
parse_mixin_call
()
{
lex
<
include
>
();
lex
<
identifier
>
();
Node
name
(
line_number
,
Node
::
identifier
,
lexed
);
Node
args
(
parse_mixin_arguments
());
Node
call
(
line_number
,
Node
::
mixin_expansion
,
2
);
call
<<
name
<<
args
;
return
call
;
}
// Node Document::parse_include(bool delay)
Node
Document
::
parse_mixin_arguments
()
// {
{
// lex< include >();
Node
args
(
line_number
,
Node
::
arguments
);
// lex< identifier >();
lex
<
exactly
<
'('
>
>
();
// Node name(line_number, Node::identifier, lexed);
if
(
!
peek
<
exactly
<
')'
>
>
(
position
))
{
// Node args(line_number, Node::parameters, parse_arguments(delay));
args
<<
parse_argument
();
// Node call(line_number, Node::mixin_call, 2);
while
(
lex
<
exactly
<
','
>
>
())
{
// call << name << args;
args
<<
parse_argument
();
// if (!delay) {
}
// cerr << "including " << string(name.token) << endl;
}
// // expand the mixin
lex
<
exactly
<
')'
>
>
();
// return name;
return
args
;
// }
}
// else {
// return call;
// }
// }
//
// Node Document::parse_arguments(bool delay)
// {
// lex< exactly<'('> >();
//
//
//
// lex< exactly<')'> >();
// }
// void Document::parse_mixin_def()
// {
// lex< mixin >();
// lex< identifier >();
// Node name(line_number, Node::identifier, lexed);
// Node params(parse_mixin_params());
// Node body(parse_block(true));
// Node mixin(line_number, Node::mixin, 3);
// mixin << name << params << body;
// context.mixins[name.token] = mixin;
//
// cerr << "parsed mixin definition: ";
// cerr << string(mixin[0].token) << "(";
// if (params.size() > 0) {
// cerr << string(params[0].token);
// for (int i = 1; i < params.size(); ++i) {
// cerr << " ," << string(params[i].token);
// }
// }
// cerr << ")" << endl;
// }
// Node Document::parse_mixin_params()
Node
Document
::
parse_argument
()
// {
{
// Node params(line_number, Node::parameters);
// lex< exactly<'('> >();
if
(
peek
<
sequence
<
variable
,
spaces_and_comments
,
exactly
<
':'
>
>
>
())
{
// if (peek< variable >()) {
lex
<
variable
>
();
// params << parse_parameter();
Node
var
(
line_number
,
Node
::
variable
,
lexed
);
// while (lex< exactly<','> >()) {
lex
<
exactly
<
':'
>
>
();
// params << parse_parameter();
Node
val
(
parse_space_list
());
// }
Node
assn
(
line_number
,
Node
::
assignment
,
2
);
// }
assn
<<
var
<<
val
;
// lex< exactly<')'> >();
return
assn
;
// return params;
}
// }
else
{
//
return
parse_space_list
();
// Node Document::parse_parameter() {
}
// lex< variable >();
}
// Node var(line_number, Node::variable, lexed);
// if (lex< exactly<':'> >()) { // default value
// Node val(parse_space_list(true));
// Node par_and_val(line_number, Node::assignment, 2);
// par_and_val << var << val;
// return par_and_val;
// }
// else {
// return var;
// }
// }
Node
Document
::
parse_assignment
()
Node
Document
::
parse_assignment
()
{
{
...
@@ -146,11 +171,11 @@ namespace Sass {
...
@@ -146,11 +171,11 @@ namespace Sass {
// context.environment[key] = evaled;
// context.environment[key] = evaled;
}
}
Node
Document
::
parse_ruleset
()
Node
Document
::
parse_ruleset
(
bool
definition
)
{
{
Node
ruleset
(
line_number
,
Node
::
ruleset
,
2
);
Node
ruleset
(
line_number
,
Node
::
ruleset
,
2
);
ruleset
<<
parse_selector_group
();
ruleset
<<
parse_selector_group
();
ruleset
<<
parse_block
();
ruleset
<<
parse_block
(
definition
);
return
ruleset
;
return
ruleset
;
}
}
...
@@ -283,7 +308,7 @@ namespace Sass {
...
@@ -283,7 +308,7 @@ namespace Sass {
return
attr_sel
;
return
attr_sel
;
}
}
Node
Document
::
parse_block
()
Node
Document
::
parse_block
(
bool
definition
)
{
{
lex
<
exactly
<
'{'
>
>
();
lex
<
exactly
<
'{'
>
>
();
bool
semicolon
=
false
;
bool
semicolon
=
false
;
...
@@ -313,22 +338,19 @@ namespace Sass {
...
@@ -313,22 +338,19 @@ namespace Sass {
}
}
semicolon
=
true
;
semicolon
=
true
;
}
}
// else if (peek< include >(position)) {
else
if
(
peek
<
include
>
(
position
))
{
// Node to_include(parse_include(delay));
Node
call
(
parse_mixin_call
());
// if (!delay) {
root
<<
call
;
// block += to_include;
root
.
has_rules_or_comments
|=
call
.
has_rules_or_comments
;
// block.has_rules_or_comments |= to_include.has_rules_or_comments;
root
.
has_rulesets
|=
call
.
has_rulesets
;
// block.has_rulesets |= to_include.has_rulesets;
root
.
has_propsets
|=
call
.
has_propsets
;
// block.has_propsets |= to_include.has_propsets;
semicolon
=
true
;
// }
if
(
!
definition
)
context
.
pending
.
push_back
(
call
);
// else {
}
// block << to_include;
// }
// semicolon = true;
// }
else
if
(
lex
<
variable
>
())
{
else
if
(
lex
<
variable
>
())
{
context
.
pending
.
push_back
(
parse_assignment
());
Node
assn
(
parse_assignment
());
semicolon
=
true
;
semicolon
=
true
;
if
(
!
definition
)
context
.
pending
.
push_back
(
assn
);
}
}
// else if (look_for_rule(position)) {
// else if (look_for_rule(position)) {
// block << parse_rule();
// block << parse_rule();
...
@@ -340,13 +362,15 @@ namespace Sass {
...
@@ -340,13 +362,15 @@ namespace Sass {
// block.has_rulesets = true;
// block.has_rulesets = true;
// }
// }
else
if
(
const
char
*
p
=
look_for_selector_group
(
position
))
{
else
if
(
const
char
*
p
=
look_for_selector_group
(
position
))
{
block
<<
parse_ruleset
();
block
<<
parse_ruleset
(
definition
);
block
.
has_rulesets
=
true
;
block
.
has_rulesets
=
true
;
}
}
else
if
(
!
peek
<
exactly
<
';'
>
>
())
{
else
if
(
!
peek
<
exactly
<
';'
>
>
())
{
block
<<
parse_rule
();
Node
rule
(
parse_rule
());
block
<<
rule
;
block
.
has_rules_or_comments
=
true
;
block
.
has_rules_or_comments
=
true
;
semicolon
=
true
;
semicolon
=
true
;
if
(
!
definition
&&
rule
[
1
].
eval_me
)
context
.
pending
.
push_back
(
rule
);
}
}
else
lex
<
exactly
<
';'
>
>
();
else
lex
<
exactly
<
';'
>
>
();
}
}
...
@@ -360,7 +384,6 @@ namespace Sass {
...
@@ -360,7 +384,6 @@ namespace Sass {
lex
<
exactly
<
':'
>
>
();
lex
<
exactly
<
':'
>
>
();
// rule << parse_values();
// rule << parse_values();
rule
<<
parse_list
();
rule
<<
parse_list
();
if
(
rule
[
1
].
eval_me
)
context
.
pending
.
push_back
(
rule
);
return
rule
;
return
rule
;
}
}
...
@@ -571,6 +594,16 @@ namespace Sass {
...
@@ -571,6 +594,16 @@ namespace Sass {
return
var
;
return
var
;
}
}
}
}
Node
Document
::
parse_identifier
()
{
lex
<
identifier
>
();
return
Node
(
line_number
,
Node
::
identifier
,
lexed
);
}
Node
Document
::
parse_variable
()
{
lex
<
variable
>
();
return
Node
(
line_number
,
Node
::
variable
,
lexed
);
}
// const char* Document::look_for_rule(const char* start)
// const char* Document::look_for_rule(const char* start)
// {
// {
...
...
node.hpp
View file @
a5365756
...
@@ -64,9 +64,11 @@ namespace Sass {
...
@@ -64,9 +64,11 @@ namespace Sass {
mixin
,
mixin
,
parameters
,
parameters
,
mixin_expansion
,
arguments
,
variable
,
variable
,
assignment
,
assignment
mixin_call
};
};
static
size_t
fresh
;
static
size_t
fresh
;
...
...
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