Skip to main content

ECMAScript parsing infrastructure for multipurpose analysis in Python

Project description

Donate 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.1.tar.gz (47.0 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: esprima-4.0.1.tar.gz
  • Upload date:
  • Size: 47.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.14.0 CPython/2.7.15

File hashes

Hashes for esprima-4.0.1.tar.gz
Algorithm Hash digest
SHA256 08db1a876d3c2910db9cfaeb83108193af5411fc3a3a66ebefacd390d21323ee
MD5 47b70d12b8af1cc631842f4a947a6e48
BLAKE2b-256 cca150fccd68a12bcfc27adfc9969c090286670a9109a0259f3f70943390b721

See more details on using hashes here.

Provenance

Supported by

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