NAME

Javascript::Grammar - Parse::Yapp grammar for Javascript

SYNOPSIS

  my $JS = q{alert('Hello World!'};

  my $parser = Javascript::Grammar->new();
  $parser->YYData->{code} = $JS;
  my $tree = $self->yyparser->YYParse(
                  yylex => \&Javascript::Grammar::yylex,
                  yyerror => sub { $self->error },
                  #yydebug => 0x1F,
             );

DESCRIPTION

This is the grammar for Javascript, oriented at the ECMA standard. It tries to produce something not entirely unlike the <autotree> directive of Parse::RecDescent.

For better handling of the resulting parse tree, see Javascript::PurePerl

EXPORT

None by default.

list LISTCLASS

The list keyword is used to declare lists for the rules. A class that is a list will have the two methods append and prepend. This is mostly used to dissolve left- or right-recursion descents.

rule RULENAME

The rule keyword is used to declare the name of the currently applied rule for easier error diagnosis and better error messages.

It walks the caller chain upwards one step to find the parser. rule returns $_[1] of the caller, so that the following code does what you'd expect:

  Rule : SubRule
         { rule "Rule" }
       ;

The name of the current rule is stored as $_[0]->YYData->{rule}

SEE ALSO

Javascript::PurePerl,Parse::Yapp,Parse::RecDescent, Javascript

AUTHOR

Max Maischein <corion@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2003,2004 by Max Maischein

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available.