The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
NAME
    MarpaX::Languages::ECMAScript::AST - Translate a ECMAScript source to an
    AST

VERSION
    version 0.019

SYNOPSIS
        use strict;
        use warnings FATAL => 'all';
        use MarpaX::Languages::ECMAScript::AST;
        use Log::Log4perl qw/:easy/;
        use Log::Any::Adapter;
        use Log::Any qw/$log/;
        #
        # Init log
        #
        our $defaultLog4perlConf = '
        log4perl.rootLogger              = WARN, Screen
        log4perl.appender.Screen         = Log::Log4perl::Appender::Screen
        log4perl.appender.Screen.stderr  = 0
        log4perl.appender.Screen.layout  = PatternLayout
        log4perl.appender.Screen.layout.ConversionPattern = %d %-5p %6P %m{chomp}%n
        ';
        Log::Log4perl::init(\$defaultLog4perlConf);
        Log::Any::Adapter->set('Log4perl');
        #
        # Parse ECMAScript
        #
        my $ecmaSourceCode = 'var i = 0;';
        my $ecmaAstObject = MarpaX::Languages::ECMAScript::AST->new();
        $log->infof('%s', $ecmaAstObject->parse($ecmaSourceCode));

DESCRIPTION
    This module translates ECMAScript source into an AST tree. If you want
    to enable logging, be aware that this module is using Log::Any.

SUBROUTINES/METHODS
  new($class, %options)
    Instantiate a new object. Takes as parameter an optional hash of options
    that can be:

    grammarName
        Name of a grammar. Default is 'ECMAScript-262-5'.

    cache
        Produced AST can be cached: very often the same ECMAScript is used
        again and again, so there is no need to always compute it at each
        call. The cache key is the buffer MD4 checksum, eventual collisions
        being handled. The cache location is the my_dist_data directory
        provided by File::HomeDir package. Default is a false value.

    ANYTHINGELSE
        Any other option that will be specific to the ECMAScript specific
        implementation. In practice these are:

        Template
            Reference to a hash for template options. C.f. per-ECMAScript
            documentation.

        StringNumericLiteral
            Reference to a hash for StringNumericLiteral grammar options.
            C.f. per-ECMAScript documentation.

        Pattern
            Reference to a hash for Pattern grammar options. C.f.
            per-ECMAScript documentation.

  describe($self)
    Get a description of the G1 grammar. Returns a reference to hash, that
    has this structure: key => value, where

    key 'G1' or 'G0', with value being a reference to all rules, LHS being
        the first.

  grammarAlias($self)
    Returns the grammar alias, i.e. the one that is used within this
    distribution, corresponding to a true directory on the filesystem.

  templatePath($self)
    Returns the templates absolute path.

  parse($self, $source)
    Get an AST from the ECMAScript source, pointed by $source. This method
    will call all the intermediary steps (lexical, transformation,
    evaluation) necessary to produce the AST. An AST is a reference to
    nested arrays, containing either:

    valuesAndRuleId
        An entry describing a G1 rule (i.e. a non-terminal) is a reference
        to an array. The array contains the values of the right-hand side of
        the rule, followed by the rule Id.

    startAndLengthAndValue
        An entry describing a lexeme (i.e. a terminal) is a reference to an
        array. The array contains the start location in the stream, length
        and lexeme as perl's utf8 string.

  template($self)
    Return the generic template for this grammar. This template is doing
    nothing else but reproduce an ECMAScript source that, if parsed, would
    have an AST similar to the original source.

  stringNumericLiteral($self)
    Return the generic stringNumericLiteral for this grammar.

  pattern($self)
    Return the generic Pattern for this grammar.

  JSON($self)
    Return the generic JSON for this grammar.

  URI($self)
    Return the generic URI for this grammar.

SEE ALSO
    Log::Any

    Marpa::R2

    Digest::MD4

    CHI::Driver::File

    MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5

SUPPORT
  Bugs / Feature Requests
    Please report any bugs or feature requests through the issue tracker at
    <https://rt.cpan.org/Public/Dist/Display.html?Name=MarpaX-Languages-ECMA
    Script-AST>. You will be notified automatically of any progress on your
    issue.

  Source Code
    This is open source software. The code repository is available for
    public review and contribution under the terms of the license.

    <https://github.com/jddurand/marpax-languages-ecmascript-ast>

      git clone git://github.com/jddurand/marpax-languages-ecmascript-ast.git

AUTHOR
    Jean-Damien Durand <jeandamiendurand@free.fr>

CONTRIBUTOR
    jddurand <jeandamiendurand@free.fr>

COPYRIGHT AND LICENSE
    This software is copyright (c) 2013 by Jean-Damien Durand.

    This is free software; you can redistribute it and/or modify it under
    the same terms as the Perl 5 programming language system itself.