Lezer for Dart

pub package melos

A pure Dart port of Lezer - the incremental GLR parser system that powers CodeMirror 6.

Features

  • Incremental parsing - Only re-parses changed portions of the document
  • Error recovery - Produces meaningful parse trees even for invalid input
  • Efficient - Optimized for real-time editing scenarios
  • Tree structure - Provides a concrete syntax tree for syntax highlighting and code analysis

Usage

import 'package:lezer/lezer.dart';

// Parse source code using a language parser
final tree = parser.parse('const x = 42;');

// Traverse the tree
tree.iterate(
  enter: (node) {
    print('${node.name}: ${source.substring(node.from, node.to)}');
    return true;
  },
);

Language Support

This package provides the core parsing infrastructure. Language-specific parsers are provided by the codemirror package which includes:

  • JavaScript/TypeScript/JSX/TSX
  • JSON
  • Markdown
  • HTML/CSS
  • And more...

License

MIT License - see LICENSE for details.

Based on Lezer by Marijn Haverbeke.

Libraries

lezer
Dart port of Lezer - an incremental GLR parser system.