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
3b0663f4
Commit
3b0663f4
authored
Apr 23, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More flexible lookahead; provides better compatibility with Sass, and is probably faster too.
parent
b4b88d1a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
3 deletions
+48
-3
document.hpp
document.hpp
+2
-0
document_parser.cpp
document_parser.cpp
+42
-2
node.cpp
node.cpp
+4
-1
No files found.
document.hpp
View file @
3b0663f4
...
@@ -145,6 +145,8 @@ namespace Sass {
...
@@ -145,6 +145,8 @@ namespace Sass {
Node
parse_string
();
Node
parse_string
();
Node
parse_value_schema
();
Node
parse_value_schema
();
const
char
*
lookahead_for_selector
(
const
char
*
start
=
0
);
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 @
3b0663f4
...
@@ -38,7 +38,8 @@ namespace Sass {
...
@@ -38,7 +38,8 @@ namespace Sass {
root
<<
parse_assignment
();
root
<<
parse_assignment
();
if
(
!
lex
<
exactly
<
';'
>
>
())
syntax_error
(
"top-level variable binding must be terminated by ';'"
);
if
(
!
lex
<
exactly
<
';'
>
>
())
syntax_error
(
"top-level variable binding must be terminated by ';'"
);
}
}
else
if
(
look_for_selector_group
(
position
))
{
// else if (look_for_selector_group(position)) {
else
if
(
lookahead_for_selector
(
position
))
{
root
<<
parse_ruleset
();
root
<<
parse_ruleset
();
}
}
else
if
(
peek
<
exactly
<
'+'
>
>
())
{
else
if
(
peek
<
exactly
<
'+'
>
>
())
{
...
@@ -474,7 +475,8 @@ namespace Sass {
...
@@ -474,7 +475,8 @@ namespace Sass {
// block << parse_ruleset();
// block << parse_ruleset();
// block.has_blocks = true;
// block.has_blocks = true;
// }
// }
else
if
(
const
char
*
p
=
look_for_selector_group
(
position
))
{
//else if (const char* p = look_for_selector_group(position)) {
else
if
(
const
char
*
p
=
lookahead_for_selector
(
position
))
{
block
<<
parse_ruleset
(
definition
);
block
<<
parse_ruleset
(
definition
);
block
[
0
].
has_blocks
=
true
;
block
[
0
].
has_blocks
=
true
;
}
}
...
@@ -905,6 +907,44 @@ namespace Sass {
...
@@ -905,6 +907,44 @@ namespace Sass {
// return p == start ? 0 : p;
// return p == start ? 0 : p;
// }
// }
const
char
*
Document
::
lookahead_for_selector
(
const
char
*
start
)
{
const
char
*
p
=
start
?
start
:
position
;
const
char
*
q
;
while
((
q
=
peek
<
identifier
>
(
p
))
||
(
q
=
peek
<
id_name
>
(
p
))
||
(
q
=
peek
<
class_name
>
(
p
))
||
(
q
=
peek
<
sequence
<
pseudo_prefix
,
identifier
>
>
(
p
))
||
(
q
=
peek
<
string_constant
>
(
p
))
||
(
q
=
peek
<
exactly
<
'*'
>
>
(
p
))
||
(
q
=
peek
<
exactly
<
'('
>
>
(
p
))
||
(
q
=
peek
<
exactly
<
')'
>
>
(
p
))
||
(
q
=
peek
<
exactly
<
'['
>
>
(
p
))
||
(
q
=
peek
<
exactly
<
']'
>
>
(
p
))
||
(
q
=
peek
<
exactly
<
'+'
>
>
(
p
))
||
(
q
=
peek
<
exactly
<
'~'
>
>
(
p
))
||
(
q
=
peek
<
exactly
<
'>'
>
>
(
p
))
||
(
q
=
peek
<
exactly
<
','
>
>
(
p
))
||
(
q
=
peek
<
binomial
>
(
p
))
||
(
q
=
peek
<
sequence
<
optional
<
sign
>
,
optional
<
digits
>
,
exactly
<
'n'
>
>
>
(
p
))
||
(
q
=
peek
<
sequence
<
optional
<
sign
>
,
digits
>
>
(
p
))
||
(
q
=
peek
<
number
>
(
p
))
||
(
q
=
peek
<
exactly
<
'&'
>
>
(
p
))
||
(
q
=
peek
<
alternatives
<
exact_match
,
class_match
,
dash_match
,
prefix_match
,
suffix_match
,
substring_match
>
>
(
p
)))
{
p
=
q
;
}
if
(
peek
<
exactly
<
'{'
>
>
(
p
))
return
p
;
else
return
0
;
}
// NEW LOOKAHEAD FUNCTIONS. THIS ESSENTIALLY IMPLEMENTS A BACKTRACKING
// NEW LOOKAHEAD FUNCTIONS. THIS ESSENTIALLY IMPLEMENTS A BACKTRACKING
// PARSER, BECAUSE SELECTORS AND VALUES ARE NOT EXPRESSIBLE IN A
// PARSER, BECAUSE SELECTORS AND VALUES ARE NOT EXPRESSIBLE IN A
// REGULAR LANGUAGE.
// REGULAR LANGUAGE.
...
...
node.cpp
View file @
3b0663f4
...
@@ -72,7 +72,10 @@ namespace Sass {
...
@@ -72,7 +72,10 @@ namespace Sass {
}
break
;
}
break
;
case
selector_combinator
:
{
case
selector_combinator
:
{
return
content
.
token
.
to_string
();
string
result
(
prefix
.
empty
()
?
""
:
prefix
+
" "
);
result
+=
content
.
token
.
to_string
();
return
result
;
// return content.token.to_string();
// if (std::isspace(content.token.begin[0])) return string(" ");
// if (std::isspace(content.token.begin[0])) return string(" ");
// else return string(content.token);
// else return string(content.token);
}
break
;
}
break
;
...
...
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