* Spaces please!
@ 2009-12-01 16:19 andrea
2009-12-02 13:33 ` Thien-Thi Nguyen
0 siblings, 1 reply; 7+ messages in thread
From: andrea @ 2009-12-01 16:19 UTC (permalink / raw)
To: help-gnu-emacs
I get sick sometimes to read something like
x=y+1*(2-3*a^2)
but I get even more sick to add spaces manually every time.
I ask help to you elisp gurus, should I use a regexp or a macro-like
function (go-here, do-this)?
I think I should define some rules like:
- which operators want spaces (and if before or after)
- what is the arity of them
One problem for example could arise from things like
(-2)^10
but we could have some operators that could be binary or unary and check
that somehow.
Someone has done it already maybe?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Spaces please!
[not found] <mailman.11955.1259684648.2239.help-gnu-emacs@gnu.org>
@ 2009-12-01 17:06 ` Pascal J. Bourguignon
2009-12-01 17:42 ` Harald Hanche-Olsen
2009-12-01 17:46 ` Lennart Borgman
2009-12-01 18:21 ` Burkhard Schultheis
1 sibling, 2 replies; 7+ messages in thread
From: Pascal J. Bourguignon @ 2009-12-01 17:06 UTC (permalink / raw)
To: help-gnu-emacs
andrea <andrea.crotti.0@gmail.com> writes:
> I get sick sometimes to read something like
> x=y+1*(2-3*a^2)
> but I get even more sick to add spaces manually every time.
Funny. I get sick reading something like
x = y+1 * ( 2-3 * a ^2)
;-)
Perhaps the best form would be:
(= x
(+ y
(* 1
(- 2
(* 3
(^ a 2))))))
but that would be a different syntax. Notice that it could be the
work of an editor to read a source in whatever "syntax" it may happen
to be, to present it to the user in whatever form the user prefers,
allowing it to do structural editing instead of textual edition, and
saving it back to whatever "syntax" is required.
A little like it is done for character encodings, where you can load a
file in iso-2022, edit it in emacs unicode, and save it in utf-8, only
for language syntaxes.
But that'd be a whole project.
> I ask help to you elisp gurus, should I use a regexp
No, you cannot parse arithmetic expressions with regular expressions,
they are too weak! You need a parser.
> or a macro-like
> function (go-here, do-this)?
>
> I think I should define some rules like:
> - which operators want spaces (and if before or after)
> - what is the arity of them
>
> One problem for example could arise from things like
>
> (-2)^10
> but we could have some operators that could be binary or unary and check
> that somehow.
>
> Someone has done it already maybe?
Well, you could hack something half working yourself, or perhaps you
could use a predefined parser for the language in question.
http://cedet.sourceforget.net has a parser generator (the
"bovinator", and parsers predefined for a number of programming
languages, that you could use to implement your "formula beautifier".
Once you have the parse tree, it is indeed trivial to generate the
expression with the number of spaces you want.
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Spaces please!
2009-12-01 17:06 ` Spaces please! Pascal J. Bourguignon
@ 2009-12-01 17:42 ` Harald Hanche-Olsen
2009-12-01 17:46 ` Lennart Borgman
1 sibling, 0 replies; 7+ messages in thread
From: Harald Hanche-Olsen @ 2009-12-01 17:42 UTC (permalink / raw)
To: help-gnu-emacs
+ pjb@informatimago.com (Pascal J. Bourguignon):
> Perhaps the best form would be:
>
> (= x
> (+ y
> (* 1
> (- 2
> (* 3
> (^ a 2))))))
Who needs stinkin' parentheses? Polish notation is the way to go.
=x+y*1-2*3^a2
> but that would be a different syntax.
Oh. Well, never mind then.
--
* Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
when there is no ground whatsoever for supposing it is true.
-- Bertrand Russell
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Spaces please!
2009-12-01 17:06 ` Spaces please! Pascal J. Bourguignon
2009-12-01 17:42 ` Harald Hanche-Olsen
@ 2009-12-01 17:46 ` Lennart Borgman
1 sibling, 0 replies; 7+ messages in thread
From: Lennart Borgman @ 2009-12-01 17:46 UTC (permalink / raw)
To: Pascal J. Bourguignon; +Cc: help-gnu-emacs
On Tue, Dec 1, 2009 at 6:06 PM, Pascal J. Bourguignon
<pjb@informatimago.com> wrote:
>
> No, you cannot parse arithmetic expressions with regular expressions,
> they are too weak! You need a parser.
Some recursion + reg exps?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Spaces please!
[not found] <mailman.11955.1259684648.2239.help-gnu-emacs@gnu.org>
2009-12-01 17:06 ` Spaces please! Pascal J. Bourguignon
@ 2009-12-01 18:21 ` Burkhard Schultheis
2009-12-01 18:26 ` Burkhard Schultheis
1 sibling, 1 reply; 7+ messages in thread
From: Burkhard Schultheis @ 2009-12-01 18:21 UTC (permalink / raw)
To: help-gnu-emacs
Am 01.12.2009 17:19, schrieb andrea:
>
> I get sick sometimes to read something like
> x=y+1*(2-3*a^2)
> but I get even more sick to add spaces manually every time.
> I ask help to you elisp gurus, should I use a regexp or a macro-like
> function (go-here, do-this)?
>
> I think I should define some rules like:
> - which operators want spaces (and if before or after)
> - what is the arity of them
>
> One problem for example could arise from things like
>
> (-2)^10
> but we could have some operators that could be binary or unary and check
> that somehow.
I would do it with a beautifier like uncrustify with GUI universalident
(<http://sourceforge.net/projects/universalindent/>. It can do that and
much, much more!
Regards
Burkhard
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Spaces please!
2009-12-01 18:21 ` Burkhard Schultheis
@ 2009-12-01 18:26 ` Burkhard Schultheis
0 siblings, 0 replies; 7+ messages in thread
From: Burkhard Schultheis @ 2009-12-01 18:26 UTC (permalink / raw)
To: help-gnu-emacs
Am 01.12.2009 19:21, schrieb Burkhard Schultheis:
> Am 01.12.2009 17:19, schrieb andrea:
>>
>> I get sick sometimes to read something like
>> x=y+1*(2-3*a^2)
>> but I get even more sick to add spaces manually every time.
>> I ask help to you elisp gurus, should I use a regexp or a macro-like
>> function (go-here, do-this)?
>>
>> I think I should define some rules like:
>> - which operators want spaces (and if before or after)
>> - what is the arity of them
>>
>> One problem for example could arise from things like
>>
>> (-2)^10
>> but we could have some operators that could be binary or unary and check
>> that somehow.
>
> I would do it with a beautifier like uncrustify with GUI universalident
> (<http://sourceforge.net/projects/universalindent/>. It can do that and
> much, much more!
>
> Regards
> Burkhard
... but these programs do it for source code files, I think. ;-)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Spaces please!
2009-12-01 16:19 andrea
@ 2009-12-02 13:33 ` Thien-Thi Nguyen
0 siblings, 0 replies; 7+ messages in thread
From: Thien-Thi Nguyen @ 2009-12-02 13:33 UTC (permalink / raw)
To: help-gnu-emacs
() andrea <andrea.crotti.0@gmail.com>
() Tue, 01 Dec 2009 17:19:30 +0100
Someone has done it already maybe?
Indeed! Try looking at:
(info "(calc) Language Modes")
I imagine the parsed (and unparsed) form of
an expression could be displayed as an overlay.
thi
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-12-02 13:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.11955.1259684648.2239.help-gnu-emacs@gnu.org>
2009-12-01 17:06 ` Spaces please! Pascal J. Bourguignon
2009-12-01 17:42 ` Harald Hanche-Olsen
2009-12-01 17:46 ` Lennart Borgman
2009-12-01 18:21 ` Burkhard Schultheis
2009-12-01 18:26 ` Burkhard Schultheis
2009-12-01 16:19 andrea
2009-12-02 13:33 ` Thien-Thi Nguyen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).