Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Re: Parse::JavaScript

by OeufMayo (Curate)
on Aug 27, 2002 at 08:45 UTC ( #193103=note: print w/replies, xml ) Need Help??

in reply to Re: Parse::JavaScript
in thread JavaScript::Parse::PurePerl (was Parse::JavaScript)

Thanks for your input podmaster. Here are a few valid JavaScript samples that don't parse too well.


var foo = 3 / 4 + 1 / 2;

is parsed as :

var foo = 3; / 4 + 1 /; 2;

var foo = (3/4) + 1 / 2; is not parsed at all (though I suspect it could be fixed by adjusting the precedence)

Elisions (though I have yet to see this construct in a real script)

var foo = foo[ , , bar];

Wrong parsing

bar ++foo;

Is parsed as:

bar++; foo;

Which is wrong. the parser should give an error (no line terminator allowed between 'bar' and '++') or be nice and get parse it as bar++;foo;

The following code is found in one of the the mozilla/js test script, but it doesn't seem to be valid, according to the specs (and obviously, doesn't parse).

try { //some stuff }catch (e if e == 3){ /* do stuff */ }

There are probably some more bugs, but the regex/division confusion is by far the most annoying

Update here is another major bugs due to the Optional Semicolon:

return a + b

Should be:

return; a + b;

But it is parsed as

return a + b;

This bug is mainly due to the fact that line terminators are silently skipped by the lexer

Update 2002-09-01: I'm glad to say that all these bugs are now fixed in the current version of this node (except for the elision.)


Replies are listed 'Best First'.
Re: Re: Re: Parse::JavaScript
by Corion (Pope) on Aug 27, 2002 at 19:47 UTC

    Very interesting code and discussion - but my internal parser parses

    bar++ foo;
    bar+ +foo;

    which would be instantly valid. But on the other side, I don't know much about JavaScript (and C-style) operator syntax, and maybe two pluses automatically mean postincrement / preincrement operator ...

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
Re^3: Parse::JavaScript
by Anonymous Monk on Mar 11, 2016 at 03:21 UTC

    I apologise for ressurecting a zombie thread, but just wanted to provide this info just in case anyone else was looking at the parser.

    I had to make the following corrections to get the module to work
    line 1495 comment out the entire line
    # /* vi:set syn=yacc: */
    to elminate error "Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE  vi:set syn=yacc: */ at PurePerl.yp line 1495."
    And also line 1307 changed from
    my $temp_pos = pos($$input); $$input =~ s/\G\s*(\n)\s*([+-]{2})/$1;$2/sg; pos($$input) = $temp_pos;
    my $temp_pos = pos($$input); $temp_pos =~ s/\G\s*(\n)\s*([+-]{2})/$1;$2/sg; pos($$input) = $temp_pos;
    to eliminate error "Modification of a read-only value attempted at PurePerl.yp line 1307."
    Hope this is of assistance to someone.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://193103]
NodeReaper . o O ( Did I forget to leave the gas on? )

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2018-05-26 03:15 GMT
Find Nodes?
    Voting Booth?