guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

REPL reader of multi-language


From: Nala Ginrut
Subject: REPL reader of multi-language
Date: Fri, 30 May 2014 16:25:40 +0800

hi folks!
When I'm hacking guile-lua on Guile, I realize that some languages may
need two different reader for REPL(interactive environment) and
compiler.

For an instance, the reader in Lua REPL has little different from its
compiler reader:
------------------------------cut-------------------------------------
In interactive mode, Lua usually interprets each line that you type as a
complete chunk. However, if it detects that the line cannot form a
complete chunk, it waits for more input, until it has a complete chunk.
When Lua is waiting for a line continuation, it shows a different
prompt...
------------------------------end--------------------------------------

But in Lua compiler/interpreter, a chunk(the minimum unit of compiling)
will be detected when the reader encounters EOF. Except for -l option
which let you input multiple chunks from command line.

It's not a problem for Ecmascript, because its statement has to be ended
with semicolon. So it's easier to detect the minimum compiling unit in
REPL. 
Lua accepts semicolon as an optional ending token. But it's strange to
force users to input semicolon or Ctrl+d to see the result in REPL. It's
better to mimic original Lua REPL.


So here's my problem, there's only one reader slot defined in each
language type ,say, in (system base language). I have to implement just
one reader to fit them all:
1. If I provide the interactive reader in Guile, the reader becomes
inefficient. Because each time users input `Enter', the source code
typed so far will be detected in lalr-parser, and exception would be
caught when the line doesn't complete a chunk, then the REPL returns
continue prompt, say '...'.

2. If I provide compiler reader, people have to type semicolon or ctrl+d
to see the result.


Here's my solution:
1. Provide two readers in language type, repl-reader and reader. And let
the frontend writers decide how to use;
2. Another way is to set a flag when we're in interactive mode. But I
didn't find the mechanism in our repl modules;
3. I saw there're various hooks in REPL, but there' no any docs for
them. Maybe there's chance to take advantage of them?

Any help?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]