[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: End-of-line
=> Within Centaur, does it exist a way to handle atomic values
=> inside of which
=> there is an end-of-line character?
Unfortunately not.
A work around is to modify your parser and your abstract syntax to
handle multi-line strings as a list of tokens.
If the language is new, you may also modify its syntax and stick
to C like conventions (use \n as a line terminator). But you will
encounter another problem when the strings become too long and
should be truncated on the screen.
You may also try the following hack, which won't work in
incremental mode.
*x where *x in {string *value} ->
[<v> if resetcounter (*value) = 0
printsubstring(*value) tail::*x];
tail::*x where *x in {string *value} ->
[<h> if tail(*value)>0 [<v> printsubstring(*value) tail::*x]];
then the ugly lisp code :
(defvar :counter 0)
(de :resetcounter (value)
;; not necessary in normal mode, but may help in incremental mode
(setq :counter 0)
)
(de :printsubstring (value)
(let ((old :counter))
(setq :counter (get-next-new-line-index value :counter))
(substring value old :counter) ;;look at the doc, i'm not sure
)
(de :tail (value)
:counter
)
Good luck.
There is a trade off between a nice abstract syntax (for semantic
use), and a nice pretty printer. If you want your pretty printer
to be fast and efficient, you should keep a readable form for
tokens in the abstract syntax.
I give an example. A token parsed as <foo> may be kept as the
string foo or <foo>:
- If the internal representation is foo, the value will
easily be used as is, but the pretty printer will have to compute
<foo> every time it is run, this is time and memory consuming.
- On the other hand, if the internal representation is
<foo>, formatting will be improved, but your tool (say a compiler)
will have to convert the value when it uses it.
Vincent Prunet