[rust-dev] A plea for removing context-free ambiguity / context-required parsing

David Rajchenbach-Teller dteller at mozilla.com
Thu Aug 16 13:33:51 PDT 2012

On 8/16/12 10:26 PM, Nathan wrote:
> One is to ensure that it's always possible when looking at an
> identifier in *any* context whether or not it is a discriminator or a
> binding/reference.  Haskell does this elegantly, IMO, by forcing
> discriminators to start with upper case and bindings/references to
> start with lower case.  Any other rule that prevents the identifiers
> from overlapping is sufficient.  I prefer this approach because it
> solves the ambiguity problem for *every* grammar production which
> involves either a reference/binding *or* an enum discriminator.
> Another is to change the specific match syntax so you say something like:
> match myfoo {
>   discriminator bar => /* yes, this is a klunky new keyword, so I
> don't recommend this in practice, but it makes the point. */
>   bar => /* bare identifiers are always bindings. */
> }

fwiw, OCaml does

match myfoo with
   | #bar -> (*any item of sum type bar*)
   | `bar -> (*sum constructor `bar*)
   | bar  -> (*binding*)

It works nicely in practice.

David Rajchenbach-Teller, PhD
 Performance Team, Mozilla

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: OpenPGP digital signature
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20120816/49bacefb/attachment.sig>

More information about the Rust-dev mailing list