Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
260f41ed
Commit
260f41ed
authored
May 12, 2012
by
Yukihiro Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no #include unistd.h stdbool; close #124
parent
96819cf8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
23 deletions
+25
-23
tools/mirb/mirb.c
tools/mirb/mirb.c
+25
-23
No files found.
tools/mirb/mirb.c
View file @
260f41ed
...
...
@@ -7,9 +7,6 @@
*/
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include <fcntl.h>
#include <mruby.h>
#include <mruby/proc.h>
...
...
@@ -18,8 +15,10 @@
/* Guess if the user might want to enter more
* or if he wants an evaluation of his code now */
bool
is_code_block_open
(
struct
mrb_parser_state
*
parser
)
{
bool
code_block_open
=
false
;
int
is_code_block_open
(
struct
mrb_parser_state
*
parser
)
{
int
code_block_open
=
FALSE
;
switch
(
parser
->
lstate
)
{
...
...
@@ -28,32 +27,32 @@ bool is_code_block_open(struct mrb_parser_state *parser) {
case
EXPR_BEG
:
// an expression was just started,
// we can't end it like this
code_block_open
=
true
;
code_block_open
=
TRUE
;
break
;
case
EXPR_DOT
:
// a message dot was the last token,
// there has to come more
code_block_open
=
true
;
code_block_open
=
TRUE
;
break
;
case
EXPR_CLASS
:
// a class keyword is not enough!
// we need also a name of the class
code_block_open
=
true
;
code_block_open
=
TRUE
;
break
;
case
EXPR_FNAME
:
// a method name is necessary
code_block_open
=
true
;
code_block_open
=
TRUE
;
break
;
case
EXPR_VALUE
:
// if, elsif, etc. without condition
code_block_open
=
true
;
code_block_open
=
TRUE
;
break
;
// now all the states which are closed
case
EXPR_ARG
:
// an argument is the last token
code_block_open
=
false
;
code_block_open
=
FALSE
;
break
;
// all states which are unsure
...
...
@@ -93,25 +92,25 @@ bool is_code_block_open(struct mrb_parser_state *parser) {
if
(
strcmp
(
parser
->
error_buffer
[
0
].
message
,
"syntax error, unexpected $end, expecting ';' or '
\\
n'"
)
==
0
)
{
code_block_open
=
true
;
code_block_open
=
TRUE
;
}
else
if
(
strcmp
(
parser
->
error_buffer
[
0
].
message
,
"syntax error, unexpected $end, expecting keyword_end"
)
==
0
)
{
code_block_open
=
true
;
code_block_open
=
TRUE
;
}
else
if
(
strcmp
(
parser
->
error_buffer
[
0
].
message
,
"syntax error, unexpected $end, expecting '<' or ';' or '
\\
n'"
)
==
0
)
{
code_block_open
=
true
;
code_block_open
=
TRUE
;
}
else
if
(
strcmp
(
parser
->
error_buffer
[
0
].
message
,
"syntax error, unexpected keyword_end"
)
==
0
)
{
code_block_open
=
true
;
code_block_open
=
TRUE
;
}
else
if
(
strcmp
(
parser
->
error_buffer
[
0
].
message
,
"syntax error, unexpected $end, expecting keyword_then or ';' or '
\\
n'"
)
==
0
)
{
code_block_open
=
true
;
code_block_open
=
TRUE
;
}
else
if
(
strcmp
(
parser
->
error_buffer
[
0
].
message
,
"syntax error, unexpected tREGEXP_BEG"
)
==
0
)
{
code_block_open
=
true
;
code_block_open
=
TRUE
;
}
else
if
(
strcmp
(
parser
->
error_buffer
[
0
].
message
,
"unterminated string meets end of file"
)
==
0
)
{
code_block_open
=
true
;
code_block_open
=
TRUE
;
}
}
}
else
{
...
...
@@ -131,7 +130,9 @@ void print_hint(void)
}
/* Print the command line prompt of the REPL */
void
print_cmdline
(
bool
code_block_open
)
{
void
print_cmdline
(
int
code_block_open
)
{
if
(
code_block_open
)
{
printf
(
"* "
);
}
else
{
...
...
@@ -139,7 +140,8 @@ void print_cmdline(bool code_block_open) {
}
}
int
main
(
void
)
int
main
(
void
)
{
char
last_char
,
ruby_code
[
1024
],
last_code_line
[
1024
];
int
char_index
;
...
...
@@ -147,7 +149,7 @@ int main(void)
mrb_state
*
mrb_interpreter
;
mrb_value
mrb_return_value
;
int
byte_code
;
bool
code_block_open
=
false
;
int
code_block_open
=
FALSE
;
print_hint
();
...
...
@@ -156,7 +158,7 @@ int main(void)
memset
(
ruby_code
,
0
,
sizeof
(
*
ruby_code
));
memset
(
last_code_line
,
0
,
sizeof
(
*
last_code_line
));
while
(
true
)
{
while
(
TRUE
)
{
print_cmdline
(
code_block_open
);
char_index
=
0
;
...
...
@@ -174,7 +176,7 @@ int main(void)
if
(
strcmp
(
last_code_line
,
"exit"
)
==
0
)
{
if
(
code_block_open
)
{
// cancel the current block and reset
code_block_open
=
false
;
code_block_open
=
FALSE
;
memset
(
ruby_code
,
0
,
sizeof
(
*
ruby_code
));
memset
(
last_code_line
,
0
,
sizeof
(
*
last_code_line
));
continue
;
...
...
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