Bypassing the expression parser

Mathuvathanan Mounasamy cowboymathu@REDACTED
Tue Jun 15 08:12:04 CEST 2010


Hi All,

I read this in this link
http://ulf.wiger.net/weblog/2007/11/21/extending-the-erlang-shell-part-2

> The Erlang shell fetches Erlang expressions from the line editor by calling
> io:parse_erl_exprs(Prompt). The first thing we need to do is to change
> this, so that we get a lower-level representation. Luckily,
> io:scan_erl_exprs(Prompt) exists. It allows us to preempt the expression
> parser, and potentially do something different.
>
> I chose to use the ‘@’ character to break out of the expression parser. For
> one thing, it stands out, and clearly doesn’t belong to any Erlang
> expression. The token scanner expects a full stop to follow, so the shortest
> example of this new mode would be:
>
>
> 1> @.
> lists:reverse([1,2,3]).
> @
> [3,2,1]
> 2>
>
> When a line starting with ‘@’ is detected, the user is given an empty line,
> for further input. Data is then collected until we enter another ‘@’ on an
> empty line.
>
> By default, we’re still parsing expressions, and the shell will treat this
> just as it would treat a normal multi-line shell command.
>
> So far, we haven’t gained much, except perhaps freedom from the repeating
> prompt. We can still use e.g. v(1) and e(1) to fetch the value of this
> command, or to repeat it.
>
---

But I couldn't understand and achieve this. Can someone please explain how
to do this?

Thanks,

-- 
Mathuvathanan Mou.


More information about the erlang-questions mailing list