[wg-camlp4] Request for feedback
alain.frisch at lexifi.com
Wed Mar 13 17:49:17 GMT 2013
On 03/13/2013 06:30 PM, Leo White wrote:
>> we can also write:
>> ((@id arg) expr)
>> which is equivalent to:
>> (expr (@id arg))
> As long as you meant
> ([@id arg] expr)
> then this is also a good idea.
No, I really meant (expr (@id arg)).
It is really the same as:
begin[@id arg] ... end
being equivalent to:
... [@id arg]
i.e. putting the attribute on the opening keyword (here the opening
parenthesis being considered as the opening keyword).
> I have to agree with Gabriel here, these things are a pain to get
> right. If you don't handle it in the lexer then you allow things like:
> let% lwt x = (* defining a lwt function? *)
> let % lwt x = (* defining the % operator? *)
> which is definitly undesirable. It also allows comments and newlines to
> be inserted in awkward places.
I can see that there is a possibility to write awkward code, but I don't
think people would actually do it. We can try to find a better syntax,
but I would find it sad to pick something more heavy only because the
light syntax could theoretically allow people to write confusing code.
I don't see "let % lwt" as a worst kind of code than:
let (* oh, you really believe I'm going to define a local value here ?
Wait a minute ...*)
(* and now you think this is a global open statement *)
> This means that you must lex "let%lwt" as a single token which can be a
> bit awkward. It is probably ok for a few specific cases, but expanding
> it to all keywords is asking for trouble.
If we go this way (and as said I'm not convinced this is required) this
would only be necessary for the keywords used as the first token of
expressions (e.g. not "in", "with", "to" for instance). And we could
limit ourselves to the most useful ones only.
> I don't think this is a good idea because you are parsing '%' as a
> strange prefix operator, so that all of the following are allowed:
> (% foo expr) ( %foo expr ) ( % foo expr )
> ((* hello world*)%
> foo expr
Again, we can try to fix that in the lexer/parser, or just publicize the
"good style". I don't think that the grammar is supposed to prevent
people from writing un-readable code, just to allow and encourage them
to write good one.
More information about the wg-camlp4