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
43ae0e6b
Commit
43ae0e6b
authored
Apr 12, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Starting to add error handling.
parent
5c604545
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
23 deletions
+35
-23
document.cpp
document.cpp
+3
-6
document.hpp
document.hpp
+2
-1
document_parser.cpp
document_parser.cpp
+4
-3
error.hpp
error.hpp
+3
-2
sass_interface.cpp
sass_interface.cpp
+22
-10
sassc.c
sassc.c
+1
-1
No files found.
document.cpp
View file @
43ae0e6b
...
...
@@ -2,6 +2,7 @@
#include <cstring>
#include "document.hpp"
#include "eval_apply.hpp"
#include "error.hpp"
#include <iostream>
namespace
Sass
{
...
...
@@ -112,12 +113,8 @@ namespace Sass {
// if (context.ref_count == 0) delete &context;
}
// void Document::eval_pending()
// {
// for (int i = 0; i < context.pending.size(); ++i) {
// eval(context.pending[i], context.global_env);
// }
// }
void
Document
::
syntax_error
(
string
message
,
size_t
ln
)
{
throw
Error
(
Error
::
syntax
,
ln
?
ln
:
line_number
,
path
,
message
);
}
using
std
::
string
;
using
std
::
stringstream
;
...
...
document.hpp
View file @
43ae0e6b
...
...
@@ -153,7 +153,8 @@ namespace Sass {
const
char
*
look_for_pseudo
(
const
char
*
start
=
0
);
const
char
*
look_for_attrib
(
const
char
*
start
=
0
);
void
eval_pending
();
void
syntax_error
(
string
message
,
size_t
ln
=
0
);
string
emit_css
(
CSS_Style
style
);
};
...
...
document_parser.cpp
View file @
43ae0e6b
#include "document.hpp"
#include "error.hpp"
#include <iostream>
namespace
Sass
{
...
...
@@ -15,7 +16,7 @@ namespace Sass {
else
if
(
peek
<
import
>
(
position
))
{
// TO DO: don't splice in place at parse-time -- use an expansion node
root
+=
parse_import
();
lex
<
exactly
<
';'
>
>
(
);
if
(
!
lex
<
exactly
<
';'
>
>
())
syntax_error
(
"top-level @import directive must be terminated by a semicolon"
);
}
else
if
(
peek
<
mixin
>
(
position
))
{
root
<<
parse_mixin_definition
();
...
...
@@ -23,11 +24,11 @@ namespace Sass {
else
if
(
peek
<
include
>
(
position
))
{
root
<<
parse_mixin_call
();
root
[
0
].
has_expansions
=
true
;
lex
<
exactly
<
';'
>
>
(
);
if
(
!
lex
<
exactly
<
';'
>
>
())
syntax_error
(
"top-level @include directive must be terminated by a semicolon"
);
}
else
if
(
peek
<
variable
>
(
position
))
{
root
<<
parse_assignment
();
lex
<
exactly
<
';'
>
>
(
);
if
(
!
lex
<
exactly
<
';'
>
>
())
syntax_error
(
"top-level variable binding must be terminated by a semicolon"
);
}
else
{
root
<<
parse_ruleset
();
...
...
error.hpp
View file @
43ae0e6b
...
...
@@ -3,12 +3,13 @@ namespace Sass {
struct
Error
{
enum
Type
{
read
,
write
,
syntax
,
evaluation
};
Type
type
;
size_t
line_number
;
string
file_name
;
string
message
;
Error
(
size_t
line_number
,
string
file_name
,
string
message
)
:
line_number
(
line_number
),
file_name
(
file_name
),
message
(
message
)
Error
(
Type
type
,
size_t
line_number
,
string
file_name
,
string
message
)
:
type
(
type
),
line_number
(
line_number
),
file_name
(
file_name
),
message
(
message
)
{
}
};
...
...
sass_interface.cpp
View file @
43ae0e6b
...
...
@@ -2,8 +2,10 @@
#include <string>
#include <cstdlib>
#include <unistd.h>
#include <iostream>
#include "document.hpp"
#include "eval_apply.hpp"
#include "error.hpp"
#include "sass_interface.h"
extern
"C"
{
...
...
@@ -47,22 +49,32 @@ extern "C" {
int
sass_compile
(
sass_context
*
c_ctx
)
{
using
namespace
Sass
;
// TO DO: CATCH ALL EXCEPTIONS
Context
cpp_ctx
(
c_ctx
->
options
.
include_paths
);
Document
doc
(
0
,
c_ctx
->
input_string
,
cpp_ctx
);
c_ctx
->
output_string
=
process_document
(
doc
,
c_ctx
->
options
.
output_style
);
try
{
Context
cpp_ctx
(
c_ctx
->
options
.
include_paths
);
Document
doc
(
0
,
c_ctx
->
input_string
,
cpp_ctx
);
c_ctx
->
output_string
=
process_document
(
doc
,
c_ctx
->
options
.
output_style
);
}
catch
(
Error
e
)
{
cerr
<<
"ERROR -- "
<<
e
.
file_name
<<
", line "
<<
e
.
line_number
<<
": "
<<
e
.
message
<<
endl
;
c_ctx
->
output_string
=
0
;
}
// TO DO: CATCH EVERYTHING ELSE
return
0
;
}
int
sass_compile_file
(
sass_file_context
*
c_ctx
)
{
using
namespace
Sass
;
// TO DO: CATCH ALL EXCEPTIONS
Context
cpp_ctx
(
c_ctx
->
options
.
include_paths
);
Document
doc
(
c_ctx
->
input_path
,
0
,
cpp_ctx
);
c_ctx
->
output_string
=
process_document
(
doc
,
c_ctx
->
options
.
output_style
);
try
{
Context
cpp_ctx
(
c_ctx
->
options
.
include_paths
);
Document
doc
(
c_ctx
->
input_path
,
0
,
cpp_ctx
);
c_ctx
->
output_string
=
process_document
(
doc
,
c_ctx
->
options
.
output_style
);
}
catch
(
Error
e
)
{
cerr
<<
"ERROR -- "
<<
e
.
file_name
<<
", line "
<<
e
.
line_number
<<
": "
<<
e
.
message
<<
endl
;
c_ctx
->
output_string
=
0
;
}
// TO DO: CATCH EVERYTHING ELSE
return
0
;
}
...
...
sassc.c
View file @
43ae0e6b
...
...
@@ -34,7 +34,7 @@ int main(int argc, char** argv)
sass_compile_file
(
ctx
);
printf
(
"%s"
,
ctx
->
output_string
);
if
(
ctx
->
output_string
)
printf
(
"%s"
,
ctx
->
output_string
);
sass_free_file_context
(
ctx
);
return
0
;
...
...
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