[rust-dev] JFYI: ANTLR grammar for Rust tokens

Matthieu Monrocq matthieu.monrocq at gmail.com
Tue Mar 26 10:38:05 PDT 2013


On Tue, Mar 26, 2013 at 4:02 PM, John Clements <clements at brinckerhoff.org>wrote:

>
> On Mar 26, 2013, at 7:57 AM, Felix S. Klock II wrote:
>
> > Cool, John beat me to the punch and posted a grammar to a repository!
> >
> > (And better still, John's grammar looks way more complete than my own.)
> >
> > I went ahead and shoved my version of Rust.g4 into a branch on a fork of
> your repo, so that people can skim and compare the approaches.  (E.g. the
> use of named terminals such a LPAREN versus hard-coding them as literals in
> the productions.)
> >
> >
> https://github.com/pnkfelix/rust-antlr/blob/pnkfelix-draft-from-rust-manual/Rust.g4
> >
> > Note the above link is not expected to actually work on real rust
> expressions of any size.  I was working by transcribing from the manual; I
> infer that John took a much different tack, perhaps using the parser source
> as a basis...?  In any case, I am posting this mostly to stimulate thought
> as to what tack to take that will best integrate both with our code and
> also with our documentation.
>
> Yes, I went entirely from lexer/parser source.
>
> I'll take a look at yours. Anyone else: is this something we're interested
> in? FWIW, I'm guessing that the parser generated directly from ANTLR would
> be not directly useful to us, but it might have value in two ways:
> 1) documentation,
> 2) verification that our language is LL(3) (or whatever), and
> 3) for future use when we write our own parser generator (or develop a
> Rust back-end for something fast like yacc).
>
> John
>
> Graydon was definitely interested in 2); at the very least to prove that
the language does not contain inherent ambiguities that had been missed so
far.

-- Matthieu


> >
> > Cheers,
> > -Felix
> >
> >
> > On Mon Mar 25 21:23:32 2013, John Clements wrote:
> >> Following an offhand comment of Patrick's on Friday, I decided to take
> a look and see just how easy it is to formulate an ANTLR grammar. The
> answer is: very, very easy. I wrote up a simple grammar for Rust tokens;
> it's up at
> >>
> >> https://github.com/jbclements/rust-antlr/
> >>
> >> The tokens work great, and so does a simple token-tree parser; it can
> now parse large rust files into token trees. I started adding an AST-level
> parser, but it's just got bits & pieces of the grammar, for now.
> >>
> >> John
> >>
> >> _______________________________________________
> >> Rust-dev mailing list
> >> Rust-dev at mozilla.org
> >> https://mail.mozilla.org/listinfo/rust-dev
> >
> >
> >
> > --
> > irc: pnkfelix on irc.mozilla.org
> > email: {fklock, pnkfelix}@mozilla.org
> >
> > _______________________________________________
> > Rust-dev mailing list
> > Rust-dev at mozilla.org
> > https://mail.mozilla.org/listinfo/rust-dev
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20130326/f2c606e1/attachment.html>


More information about the Rust-dev mailing list