[pypy-dev] New Javascript parser in the works

Carl Friedrich Bolz cfbolz at gmx.de
Tue Apr 24 10:58:38 CEST 2007

Hi Leonardo!

Leonardo Santagada wrote:
> I started development of the javascript parser, based on the
> pythongrammar.txt file on parsing test dir.

This is the point that does not really make sense to me already. You
should base your grammar on the official (Mozilla) one, otherwise you
will end up chasing and understanding strange corner cases. Also it
makes updating the grammar much easier for future versions of the
language. If you don't want to (or can't, for some reason) use the
official grammar directly, you should use at least parts of it.

> The thing is still in its
> infancy, but I just wanted to say that I am working on it, and would
> love any help. It is living in users/santagada/newjsparser for now...
> will move to js when it is at least kind of working.

I looked quickly at the directory, my comment is that you should really
write tests. Otherwise you will get regressions when you change the
grammar. As you know, PyPy is very strict about untested code, and an
untested grammar is not really a good plan either. Also, the tests would
have told me what you expect to work, in the current state it is
completely worthless to me since I have no clue what should work and
what not.

> About the parsing lib I have some questions (should be asking cfbolz
> but I don't seem to find him on irc lately):

Sorry, I am enjoying my free time too much currently and don't want to
be online consistently. Mail is fine for such a technical discussion
anyway (and it has the additional benefit that I can answer you during
this boring lecture I am sitting in now).

> 	* ParsingError should print something like lineno: self.lineno+1
> collum: self.collum+1 (I know there is a pretty error function, but
> still)

There is no class called ParsingErro and ParseError (which exists) does
not have a lineno attribute, so what exactly do you mean? If it is only
a cosmetic change, just fix it yourself, I will look at it. Note that
the line and column numbers of the parse errors are guesses only, there
is no way to pinpoint the exact error location with PEGs.

> 	* IGNORE and friends, how do I make then work?

What friends? IGNORE itself is a bit documented, so read the docs (and
the tests). The idea is that IGNORE is a regular expression of things
that should be ignored in the input (probably comments and whitespace).

> 	* I don't know why when it recognizes something (or I think it
> should) it just gives me list index out of bounds (I will check what
> is happening, but if someone know why it would be better).

Check in a failing test (skipped or not, it's your directory anyway),
otherwise I have no clue what you are talking about.

> About the grammar:
> 	* based on python grammar, so automatic semicolon insertion is OFF.
> You have optional semicolons at the end of lines though
> 	* No regex literals (ahh someday maybe, i'm not really interested in
> them)

Regex literals will only be possible after refactoring the parser
generator, I fear.

> 	* Lot's of work to be done still :)



Carl Friedrich

More information about the Pypy-dev mailing list