high-performance javascript parser, tokenizer and lexical analyser
Project description
esprima2 is a javascript parser written in python. It works for ECMAScript 2024 and has ~1500 unit tests.
Credits
- Ariya Hidayat created the original [esprima]((https://github.com/jquery/esprima) library.
- Kronuz created a python port as esprima-python, line-by-line - faithfully.
esprimalibrary hasn't been updated since ECMAScript 2019 andesprima-pythonsince ECMAScript 2017.- With
esprima2, I added the missing syntax support and now we can parse modern javascript.
Features
- Full support for ECMAScript 2024
- Sensible syntax tree format as tandardized by ESTree project
- Experimental support for JSX, a syntax extension for React
- Optional tracking of syntax node location (index-based and line-column)
- Heavily tested (~1500 unit tests)
Installation
pip install esprima2
Usage
Esprima can be used to perform lexical analysis (tokenization) or syntactic analysis (parsing) 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"
}
More (and original) documentation is available here: https://esprima.org
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file esprima2-5.0.0.tar.gz.
File metadata
- Download URL: esprima2-5.0.0.tar.gz
- Upload date:
- Size: 5.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2c2213adda66ed5ac2b6998f3c7cb4957d7a120453888c06c9b088c29ff8eaf
|
|
| MD5 |
c76ebe396045755012198b8e9a9e7427
|
|
| BLAKE2b-256 |
76ff93db74202800e8553d93f255489fe96e5c56d19c5c236f56dee018e60c6b
|
File details
Details for the file esprima2-5.0.0-py3-none-any.whl.
File metadata
- Download URL: esprima2-5.0.0-py3-none-any.whl
- Upload date:
- Size: 67.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
084b6fc2b472adb570e15698a8fa670e099393cb3ca8230684deb68009f194d1
|
|
| MD5 |
bfce0de416695983f4d142e00e59c392
|
|
| BLAKE2b-256 |
778ee9933d74b86e38dc9dcce11830be78e3eeaec8d9e757e26f127e9e1571a4
|