🌐
GitHub
github.com › lexanth › python-ast
GitHub - lexanth/python-ast: Python (3) Parser for JavaScript/TypeScript (based on antlr4ts)
Python (3) Parser for JavaScript/TypeScript, based on antlr4ts, grammar taken from antlr4's python grammar too (so please report bugs and open pull requests related to grammars upstream)
Starred by 15 users
Forked by 5 users
Languages   TypeScript 98.9% | JavaScript 1.1% | TypeScript 98.9% | JavaScript 1.1%
🌐
GitHub
github.com › gridaco › pyast-ts
GitHub - gridaco/pyast-ts: python typescript (ts / js / jsx / tsx) ast parser using standard typescript package
python typescript (ts / js / jsx / tsx) ast parser using standard typescript package - gridaco/pyast-ts
Author   gridaco
🌐
GitHub
github.com › anntnzrb › tsparxser
GitHub - anntnzrb/tsparxser: TypeScript mini lexer+parser implementation using Python's PLY library.
July 13, 2023 - TypeScript mini lexer+parser implementation using Python's PLY library. - anntnzrb/tsparxser
Forked by 2 users
Languages   Python 96.2% | TypeScript 3.5% | Nix 0.3% | Python 96.2% | TypeScript 3.5% | Nix 0.3%
🌐
GitHub
github.com › TheLartians › TypeScript2Python
GitHub - TheLartians/TypeScript2Python: 🚃 Transpile TypeScript types to Python! A TypeScript to Python type transpiler.
🚃 Transpile TypeScript types to Python! A TypeScript to Python type transpiler. - TheLartians/TypeScript2Python
Starred by 27 users
Forked by 3 users
Languages   TypeScript 91.3% | JavaScript 8.7%
🌐
Stack Overflow
stackoverflow.com › questions › 75870756 › how-to-parse-a-typescript-file-using-a-python-script
How to parse a Typescript file using a Python script? - Stack Overflow
import ast import typescript def get_functions(code): js_code = typescript.transpile(code) js_ast = ast.parse(js_code) functions = [] for node in js_ast.body: if isinstance(node, ast.FunctionDef): functions.append((node.lineno, node.name, typescript.transpile(ast.unparse(node)))) return functions · I'm very new with python, so If you can guide me with this it will be very appreciated. https://github.com/pypa/pip/issues/8559 enter image description here
🌐
Alibaba Cloud Community
alibabacloud.com › blog › an-introduction-to-parsing-tools-for-python-static-types-and-practices_598202
An Introduction to Parsing Tools for Python Static Types and Practices - Alibaba Cloud Community
November 2, 2021 - import logging import sys import os import importlab.environment import importlab.fs import importlab.graph import importlab.output from importlab import parsepy from sempy import util from sempy import environment_util from pytype.pyi import parser · In the demo, use Importlab to parse project dependencies and corresponding pyi files: def main(): # Specify the directory for parsing ROOT = '/path/to/demo_project' # Specify the directory TYPESHED, which can be downloaded at:https://github.com/python/typeshed TYPESHED_HOME = '/path/to/typeshed_home' util.setup_logging() # Load typeshed.
🌐
GitHub
github.com › buehler › node-typescript-parser
GitHub - buehler/node-typescript-parser: Parser for typescript (and javascript) files, that compiles those files and generates a human understandable AST.
const parser = new TypescriptParser(); // either: const parsed = await parser.parseSource(/* typescript source code as string */); // or a filepath const parsed = await parser.parseFile('/user/myfile.ts', 'workspace root');
Starred by 150 users
Forked by 43 users
Languages   TypeScript 99.8% | JavaScript 0.2% | TypeScript 99.8% | JavaScript 0.2%
🌐
GitHub
github.com › microsoft › TypeScript › blob › main › src › compiler › parser.ts
TypeScript/src/compiler/parser.ts at main · microsoft/TypeScript
// reparse all statements between start and pos. We skip existing diagnostics for the same range and allow the parser to generate new ones.
Author   microsoft
🌐
GitHub
github.com › topics › toml-parser
toml-parser · GitHub Topics · GitHub
All 100 C++ 13 Python 12 TypeScript 10 Rust 9 C 5 C# 5 Go 5 Zig 5 PHP 4 Common Lisp 2 · Star 255 · A small, fast, and correct TOML (1.1.0) parser and serializer · nodejs javascript toml-parser toml parser typescript serializer toml-serializer toml-stringify ·
Top answer
1 of 5
52

Nowadays, there is at least one better tool, called slimit:

SlimIt is a JavaScript minifier written in Python. It compiles JavaScript into more compact code so that it downloads and runs faster.

SlimIt also provides a library that includes a JavaScript parser, lexer, pretty printer and a tree visitor.

Demo:

Imagine we have the following javascript code:

$.ajax({
    type: "POST",
    url: 'http://www.example.com',
    data: {
        email: '[email protected]',
        phone: '9999999999',
        name: 'XYZ'
    }
});

And now we need to get email, phone and name values from the data object.

The idea here would be to instantiate a slimit parser, visit all nodes, filter all assignments and put them into the dictionary:

from slimit import ast
from slimit.parser import Parser
from slimit.visitors import nodevisitor


data = """
$.ajax({
    type: "POST",
    url: 'http://www.example.com',
    data: {
        email: '[email protected]',
        phone: '9999999999',
        name: 'XYZ'
    }
});
"""

parser = Parser()
tree = parser.parse(data)
fields = {getattr(node.left, 'value', ''): getattr(node.right, 'value', '')
          for node in nodevisitor.visit(tree)
          if isinstance(node, ast.Assign)}

print fields

It prints:

{'name': "'XYZ'", 
 'url': "'http://www.example.com'", 
 'type': '"POST"', 
 'phone': "'9999999999'", 
 'data': '', 
 'email': "'[email protected]'"}
2 of 5
23

ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages.

The ANTLR site provides many grammars, including one for JavaScript.

As it happens, there is a Python API available - so you can call the lexer (recognizer) generated from the grammar directly from Python (good luck).

Find elsewhere
🌐
GitHub
github.com › differentmatt › filbert
GitHub - differentmatt/filbert: JavaScript parser of Python
JavaScript parser of Python. Contribute to differentmatt/filbert development by creating an account on GitHub.
Starred by 139 users
Forked by 27 users
Languages   JavaScript 82.5% | HTML 17.1% | CSS 0.4% | JavaScript 82.5% | HTML 17.1% | CSS 0.4%
🌐
PyPI
pypi.org › project › ts-interface-parser
ts-interface-parser
October 15, 2019 - JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
npm
npmjs.com › package › dt-python-parser
dt-python-parser - npm
In addition, several auxiliary methods are provided, for example, to filter comments of type # and """ in Python statements. ... Tip: The current Parser is the Javascript language version, if necessary, you can try to compile the Grammar file to other target languages
      » npm install dt-python-parser
    
Published   Apr 07, 2022
Version   0.9.0
🌐
GitHub
github.com › topics › parsers
parsers · GitHub Topics · GitHub
react typescript csv stream input ... react-csv-parser react-csv react-csv-reader browser-csv ... A customizable Log Viewer with ability to create custom providers. Can be used with C#, C++, Python......
🌐
GitHub
github.com › EoinDavey › tsPEG
GitHub - EoinDavey/tsPEG: PEG Parser Generator for TypeScript
PEG Parser Generator for TypeScript. Contribute to EoinDavey/tsPEG development by creating an account on GitHub.
Starred by 216 users
Forked by 11 users
Languages   TypeScript 98.6% | JavaScript 1.3% | Shell 0.1% | TypeScript 98.6% | JavaScript 1.3% | Shell 0.1%
🌐
GitHub
github.com › topics › parser
parser · GitHub Topics · GitHub
parsers used as part of/in conjunction with a compiler (in this case, the parser consumes the tokenized input emitted by the Lexer and ultimately feeds the resulting parse tree/concrete syntax tree into the compiler) ... All 16,041 Python 3,299 JavaScript 1,736 TypeScript 1,310 Rust 1,247 C++ 1,169 Java 1,111 Go 1,076 C 944 C# 801 PHP 524
🌐
GitHub
github.com › topics › typescript-parser
typescript-parser · GitHub Topics · GitHub
December 10, 2019 - A semantic external parser for TypeScript files that can be used together with GMaster, PlasticSCM or SemanticMerge.
🌐
GitHub
github.com › topics › syntax-parser
syntax-parser · GitHub Topics · GitHub
python programming-language ... python3 syntax-checker syntax-parser cfg context-free-grammar if-else formal-languages context-free-language automata-and-formal-languages if-else-statement if-else-if syntax-validation ... A 4IF INSA Lyon project to create a simple LR(1) Parser. ... Light and fast 🚀parser! With zero dependents. - Sql Parser Demo added! parser typescript sql sql-parser ...
🌐
GitHub
github.com › topics › python-parser
python-parser · GitHub Topics · GitHub
Fast, flexible graph database for code relationships with 16 production-ready language parsers — Python, Rust, TypeScript, Go, C/C++, Java, Kotlin, C#, PHP, Ruby, Swift, Tcl, Verilog, COBOL, Fortran