esprima
v4.0.1ECMAScript parsing infrastructure for multipurpose analysis in Python
$ uv add esprimaEsprima (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 <http://www.ecma-international.org/publications/standards/Ecma-262.htm>`__)
- Sensible `syntax tree
format <https://github.com/estree/estree/blob/master/es5.md>__ as standardized by ESTree project <https://github.com/estree/estree>`__
- 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 <https://github.com/jquery/esprima/tree/master/test/fixtures>__ with full code coverage <https://codecov.io/github/jquery/esprima>`__)
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_.
Details
- Version
- 4.0.1
- License
- BSD License
- Maintainer
- German M. Bravo (Kronuz)
Links
Maintainers
- German M. Bravo (Kronuz) · [email protected]