Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Chris Müller
cherry
Commits
dee7ec4a
Commit
dee7ec4a
authored
Jul 18, 2013
by
Chris Müller
Browse files
Add line information for error messages
parent
52ffcd23
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/cherry/read.h
View file @
dee7ec4a
...
...
@@ -31,6 +31,7 @@ struct org_cherry_context {
const
char
*
filename
;
const
cy_byte_t
*
begin
;
const
cy_byte_t
*
src
;
uint32_t
line
;
struct
org_cherry_array
*
buffer
;
cy_flags_t
flags
;
};
...
...
@@ -38,6 +39,7 @@ struct org_cherry_context {
struct
org_cherry_context
*
org_cherry_context
(
const
cy_byte_t
*
source
,
const
char
*
filename
,
cy_flags_t
flags
);
struct
org_cherry_context
*
org_cherry_context_repl
(
const
cy_byte_t
*
source
);
void
org_cherry_context_repl_set_source
(
struct
org_cherry_context
*
c
,
const
cy_byte_t
*
source
);
void
org_cherry_error
(
struct
org_cherry_context
*
context
,
const
char
*
format
,
...);
...
...
source/cherry.c
View file @
dee7ec4a
...
...
@@ -86,10 +86,10 @@ org_cherry_start_repl(void)
org_cherry_env_push_exception_point
(
env
);
cy_byte_t
*
line
=
(
cy_byte_t
*
)
readline
(
"> "
);
struct
org_cherry_context
*
context
=
org_cherry_context_repl
(
line
);
while
(
1
)
{
cy_byte_t
*
line
=
(
cy_byte_t
*
)
readline
(
"> "
);
struct
org_cherry_context
*
context
=
org_cherry_context_repl
(
line
);
struct
org_cherry_value
*
exp
=
org_cherry_read
(
context
);
if
(
!
setjmp
(
EXCEPTION_JUMP
(
env
)))
{
...
...
@@ -102,6 +102,9 @@ org_cherry_start_repl(void)
}
free
(
line
);
line
=
(
cy_byte_t
*
)
readline
(
"> "
);
org_cherry_context_repl_set_source
(
context
,
line
);
}
org_cherry_env_pop_exception_point
(
env
);
...
...
source/read.c
View file @
dee7ec4a
...
...
@@ -33,6 +33,7 @@ org_cherry_context(const cy_byte_t* source, const char* filename, cy_flags_t fla
context
->
filename
=
filename
;
context
->
begin
=
source
;
context
->
src
=
(
cy_byte_t
*
)
source
;
context
->
line
=
1
;
context
->
buffer
=
org_cherry_array_new
(
sizeof
(
cy_byte_t
));
context
->
flags
=
flags
;
...
...
@@ -47,6 +48,16 @@ org_cherry_context_repl(const cy_byte_t* source)
}
void
org_cherry_context_repl_set_source
(
struct
org_cherry_context
*
c
,
const
cy_byte_t
*
source
)
{
assert
(
c
!=
0
);
c
->
begin
=
source
;
c
->
src
=
source
;
c
->
line
++
;
}
void
org_cherry_error
(
struct
org_cherry_context
*
context
,
const
char
*
format
,
...)
{
...
...
@@ -54,11 +65,11 @@ org_cherry_error(struct org_cherry_context* context, const char* format, ...)
va_start
(
args
,
format
);
if
(
context
->
filename
!=
0
)
fprintf
(
stderr
,
"ERROR %s"
,
context
->
filename
);
fprintf
(
stderr
,
"ERROR
(
%s
:%d)
"
,
context
->
filename
,
context
->
line
);
else
fprintf
(
stderr
,
"ERROR (console
)"
);
fprintf
(
stderr
,
"ERROR (console
:%d)"
,
context
->
line
);
fprintf
(
stderr
,
"
:
"
);
fprintf
(
stderr
,
"
---
"
);
vfprintf
(
stderr
,
format
,
args
);
fprintf
(
stderr
,
"
\n
"
);
...
...
@@ -600,7 +611,7 @@ org_cherry_lex(struct org_cherry_context* context)
cy_unicode_t
ch
=
org_cherry_utf8_get
(
p
);
if
(
org_cherry_unicode_isspace
(
ch
))
{
if
(
org_cherry_unicode_isspace
(
ch
)
&&
(
ch
!=
'\n'
||
ch
!=
'\r'
)
)
{
p
=
org_cherry_utf8_next
(
p
);
context
->
src
=
p
;
continue
;
...
...
@@ -609,6 +620,16 @@ org_cherry_lex(struct org_cherry_context* context)
switch
(
ch
)
{
case
'\0'
:
return
TOK_EOF
;
case
'\r'
:
if
(
*
org_cherry_utf8_next
(
p
)
==
'\n'
)
p
++
;
break
;
case
'\n'
:
context
->
line
++
;
break
;
case
'('
:
LEX_RETURN
(
TOK_ROUNDLEFTBRACE
);
case
')'
:
...
...
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