Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lezer/common

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lezer/common

Syntax tree data structure and parser interfaces for the lezer parser

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @lezer/common?

The @lezer/common package is part of the Lezer project, which provides a robust, performance-focused parsing system. This particular package includes common utilities and types that are used across different parts of the Lezer ecosystem. It's designed to support the creation and manipulation of syntax trees, offering tools for parsing, analyzing, and transforming text.

What are @lezer/common's main functionalities?

Syntax Tree Navigation

This feature allows for navigating through a syntax tree. The code sample demonstrates how to create a cursor from a syntax tree and iterate over its nodes, printing the name of each node's type. This is useful for analyzing or transforming the structure of parsed documents.

let cursor = tree.cursor();
while(cursor.next()) {
  console.log(cursor.node.type.name);
}

Tree Fragment Reuse

Enables efficient parsing by reusing parts of an old syntax tree. The code shows how to apply changes to an array of tree fragments and then use these fragments to assist in parsing a new tree. This significantly improves performance when making incremental updates to a document.

let fragment = TreeFragment.applyChanges(fragments, changes);
let newTree = parser.parse({fragments: [fragment]});

Syntax Node Access

Facilitates direct access to specific nodes within a syntax tree based on position. The example code retrieves a node at a given position (5) and logs its name and the range it spans. This is particularly useful for pinpointing elements in a document for further inspection or modification.

let node = tree.resolve(5);
console.log(node.name, node.from, node.to);

Other packages similar to @lezer/common

FAQs

Package last updated on 07 Dec 2023

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