The application demonstrates how to create custom Query Language for CodeMirror using the Lezer Parser System.
My goal was to create query language that is unbound from an application domain. So the grammar part defines just a syntax for queries, but does not contains any properties or values. Thus, domain specific data can be defined independently of grammar.
Start:
pnpm run dev
Rebuild grammar:
pnpm run grammar
Run tests:
pnpm test
- main.ts is an entrypoint. It finds the root DOM element and render the app.
- Universal query language: language contains a set of CodeMirror plugins that implement work with the query language defined in Grammar
- grammar contains everything about parsing a text to an AST
- QueryLanguage.grammar grammar definition in terms of The Lezer Parser System. The parser itself is autogenerated based on the grammar file.
- query a helper to transform AST to query tree, it helps to visualize the parsing result and test the parser
- highlighter highlights different semantic tokens with different colors
- linter shows errors for improper tokens
- decorator shows user-defined widgets for some tokens
- autocomplete suggests related tokens to a user
- language combines them all
- grammar contains everything about parsing a text to an AST
- Domain Specific Data
- data contains some data and declarations that are related to a specific app (e.g. task manager)
- properties describes possible properties and its values available for QL
- persons contains some imaginable “users” that could be used for filtering by an author
- decorator defines how to replace query tokens with rich HTML widgets, e.g. it replaces usernames of authors with their names
- data contains some data and declarations that are related to a specific app (e.g. task manager)