Skip to main content

ECMAScript parsing infrastructure for multipurpose analysis in Python

Project description

PyPI Version PyPI License PyPI Format PyPI Status

Esprima (esprima.org, BSD license) is a high performance, standard-compliant ECMAScript parser officially written in ECMAScript (also popularly known as JavaScript) and ported to Python. Esprima is created and maintained by Ariya Hidayat, with the help of many contributors.

Python port is a line-by-line manual translation and was created and is maintained by German Mendez Bravo (Kronuz).

Features

Installation

pip install esprima

API

Esprima can be used to perform lexical analysis (tokenization) or syntactic analysis (parsing) of a JavaScript program.

A simple example:

>>> import esprima
>>> program = 'const answer = 42'

>>> esprima.tokenize(program)
[{
    type: "Keyword",
    value: "const"
}, {
    type: "Identifier",
    value: "answer"
}, {
    type: "Punctuator",
    value: "="
}, {
    type: "Numeric",
    value: "42"
}]

>>> esprima.parseScript(program)
{
    body: [
        {
            kind: "const",
            declarations: [
                {
                    init: {
                        raw: "42",
                        type: "Literal",
                        value: 42
                    },
                    type: "VariableDeclarator",
                    id: {
                        type: "Identifier",
                        name: "answer"
                    }
                }
            ],
            type: "VariableDeclaration"
        }
    ],
    type: "Program",
    sourceType: "script"
}

For more information, please read the complete documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

esprima-4.0.0.tar.gz (46.9 kB view details)

Uploaded Source

File details

Details for the file esprima-4.0.0.tar.gz.

File metadata

  • Download URL: esprima-4.0.0.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for esprima-4.0.0.tar.gz
Algorithm Hash digest
SHA256 3951d0afe8fa61394bcfad94a56bb852aa904f73d9bde71c00dfc1125fbe718c
MD5 d7f5e6ed2acafe1f2a11f4b68f672225
BLAKE2b-256 8661ff7a62bcf79cebb6faf42c0ff28756c152a9dcf7244019093ca4513d80ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page