ECMAScript parsing infrastructure for multipurpose analysis in Python
Project description
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
Full support for ECMAScript 2017 (ECMA-262 8th Edition)
Sensible syntax tree format as standardized by ESTree project
Optional tracking of syntax node location (index-based and line-column)
Heavily tested (~1500 unit tests with full code coverage)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file esprima-4.0.0.dev11.tar.gz
.
File metadata
- Download URL: esprima-4.0.0.dev11.tar.gz
- Upload date:
- Size: 44.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 116168996e3888d4ef3ed336d728ac82287da4b9a1aa76149bbec0feb05ca21c |
|
MD5 | 61b6c75c0b8e04200c2e95f3b2e94d0c |
|
BLAKE2b-256 | 2bdb04c98cbdc738bb1110fa987de2cf4bc5157798c97bf0184c51694bffba7f |