[wg-camlp4] [Caml-list] Working Group: the future of syntax extensions in OCaml, after camlp4

Gerd Stolpmann info at gerd-stolpmann.de
Mon Jan 28 21:12:13 GMT 2013


Am 28.01.2013 13:15:06 schrieb(en) Alain Frisch:
> On 01/24/2013 05:24 PM, Gerd Stolpmann wrote:
>> It's used in the tool, but only for stream parsing. I could also
>> distribute the already-preprocessed file (and maybe I'll do so in the
>> next release).
>> 
>> Stream parsing is certainly one of the topics to discuss.
> 
> I've no idea how widely stream parsing is used.  Has anyone some  
> intuition about this?
> 
> Stream parsers probably fall in the same category as bitstring or  
> sedlex (custom notions of pattern matching).  It seems that stream  
> parsers (which I'm not familiar with) require to be able to write  
> expressions within "left-hand sides", which might require special  
> support.  Or maybe the whole left-hand sides should just be  
> quotations.
> 
> Anyway, for a basic infrastructure tool such as ocamlfind, I'd  
> probably advocate for a "manual" solution which works out of the box  
> with a basic OCaml installation (ocamlyacc or manual top-down  
> parser).  Gerd: does that sound reasonable to you?

Of course. META is easy enough to parse with any tool.

But I'd also like to fight for stream parsers a bit. In general, they  
are a nice way to write top-down parsers. Like for all top-down  
parsers, the class of acceptable grammars is not very powerful (less  
than LALR(1)), but you can easily add things that are nearly impossible  
with bottom-up parsers, like stores or contextuality, and you can  
locally escape from the parsing discipline entirely. Sometimes it is a  
perfect match.

 From an old OCaml manual:

expr ::= ...
         | [< >]
         | [< stream-component {; stream-component} >]
         | parser [pattern] stream-matching
         | match expr with parser [pattern] stream-matching

stream-component ::= ’ expr
                    | expr
stream-matching ::= stream-pattern [pattern] -> expr
                     { | stream-pattern [pattern] -> expr}
stream-pattern ::= [< >]
                   | [< stream-pat-comp {; stream-pat-comp [?? expr]} >]
stream-pat-comp ::= ’ pattern [when expr]
                   | pattern = expr
                   | ident

Doing this with -ppx is certainly a challenge.

Some ideas:

  - [< >]: Maybe we should simply add several types of brackets to
    the grammar. Syntax as for list, but reserved for extensions.

  - 'expr: This is like a tag. Maybe use I(expr) instead, where "I"
    means "item".

  - pattern = expr: I guess this is what Alain sees as difficulty.
    As quotation it would look strange. What we need here is something
    in the Parsetree that allows us to include expressions into patterns
    (which would look like a "computed pattern"). Maybe `(expr) inside
    patterns. Or another notation...

Gerd


> 
> 
> Alain
> 
> 


-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd at gerd-stolpmann.de
Creator of GODI and camlcity.org.
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------


More information about the wg-camlp4 mailing list