[seed] Implement a more complete multiline repl using Seed.check_syntax
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] Implement a more complete multiline repl using Seed.check_syntax
- Date: Wed, 6 May 2009 15:07:37 -0400 (EDT)
commit 22409bd9473b099d63c7c250401f9d9df6721176
Author: Robert Carr <racarr svn gnome org>
Date: Wed May 6 15:06:49 2009 -0400
Implement a more complete multiline repl using Seed.check_syntax
---
examples/repl.js | 25 ++++---------------------
modules/readline/seed-readline.c | 16 ++++++++++++++++
2 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/examples/repl.js b/examples/repl.js
index 9c44eda..ebdbaed 100755
--- a/examples/repl.js
+++ b/examples/repl.js
@@ -2,35 +2,18 @@
readline = imports.readline;
-var eoq = 0;
-var bc = 0;
-
bind_cr = function(){
- if (bc == 0){
+ try {
+ Seed.check_syntax(readline.buffer());
readline.rl_done();
- eoq = 0;
+ }
+ catch (e){
}
Seed.print("");
}
-bind_eoq = function(){
- eoq = 1;
- Seed.print(";");
-}
-
-bind_lb = function(){
- bc++;
- Seed.print("{");
-}
-bind_rb = function(){
- bc--;
- Seed.print("}");
-}
-
readline.bind('\n', bind_cr);
readline.bind('\r', bind_cr);
-readline.bind('{', bind_lb);
-readline.bind('}', bind_rb);
while(1){
try{
diff --git a/modules/readline/seed-readline.c b/modules/readline/seed-readline.c
index 9c47d16..a49b039 100644
--- a/modules/readline/seed-readline.c
+++ b/modules/readline/seed-readline.c
@@ -85,6 +85,17 @@ seed_rl_done(SeedContext ctx,
}
static SeedValue
+seed_rl_buffer(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[],
+ SeedValue * exception)
+{
+ return seed_value_from_string (ctx, rl_line_buffer, exception);
+}
+
+static SeedValue
seed_readline(SeedContext ctx,
SeedObject function,
SeedObject this_object,
@@ -157,6 +168,11 @@ seed_module_init(SeedEngine * local_eng)
(SeedFunctionCallback) seed_rl_done,
(SeedObject) namespace_ref);
+ seed_create_function(eng->context,
+ "buffer",
+ (SeedFunctionCallback) seed_rl_buffer,
+ (SeedObject) namespace_ref);
+
return namespace_ref;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]