Socket
Socket
Sign inDemoInstall

@lezer/python

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lezer/python

Lezer-based Python grammar


Version published
Weekly downloads
210K
decreased by-19.07%
Maintainers
1
Weekly downloads
 
Created

What is @lezer/python?

@lezer/python is a parser for the Python programming language built using the Lezer parser system. It is designed to be used in syntax highlighting, code analysis, and other language processing tasks.

What are @lezer/python's main functionalities?

Parsing Python Code

This feature allows you to parse Python code into a syntax tree. The code sample demonstrates how to parse a simple Python function and print the resulting syntax tree.

const {parser} = require('@lezer/python');
const input = 'def hello():\n    print("Hello, world!")';
const tree = parser.parse(input);
console.log(tree.toString());

Syntax Highlighting

This feature allows you to use the parsed syntax tree for syntax highlighting. The code sample shows how to highlight a simple Python function using CodeMirror's highlighting utilities.

const {parser} = require('@lezer/python');
const {highlightTree} = require('@codemirror/highlight');
const {defaultHighlightStyle} = require('@codemirror/highlight');
const input = 'def hello():\n    print("Hello, world!")';
const tree = parser.parse(input);
const highlights = highlightTree(tree, defaultHighlightStyle);
console.log(highlights);

Code Analysis

This feature allows you to perform code analysis on the parsed syntax tree. The code sample demonstrates a simple analysis that counts the number of function definitions in the input Python code.

const {parser} = require('@lezer/python');
const input = 'def hello():\n    print("Hello, world!")';
const tree = parser.parse(input);
// Example analysis: count function definitions
let functionCount = 0;
tree.cursor().iterate(node => {
  if (node.name === 'FunctionDefinition') functionCount++;
});
console.log(`Number of functions: ${functionCount}`);

Other packages similar to @lezer/python

FAQs

Package last updated on 25 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc