
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
good-enough-parser
Advanced tools
TypeScript library aiming to fill the gap between usage of ad-hoc regular expressions and generation of complete grammar descriptions.
While most programming languages provide parser tooling for the language they're written in, sometimes we need a uniform way to deal with the variety of languages from JavaScript (or TypeScript).
The library is divided into multiple levels of abstraction, from the lowest to the highest one:
lib/lexer
Configures the moo tokenizer for specific language features such as:
()
, {}
, []
, etc'foo'
, "bar"
, """baz"""
, etc${foo}
, {{bar}}
, $(baz)
, etc#...
, //...
, etc/*...*/
, (*...*)
, etcfoo
, Bar
, _baz123
, etc\
, the next one will be treated as its continuationRefer to the LexerConfig
interface for more details.
Also check out our usage example for Python.
lib/parser
This layer is responsible for transforming the token sequence to the nested tree with the tokens as leafs. Internally, we're using functional zipper data structure to perform queries on the tree.
lib/query
To understand parser-utils
queries, it's useful to keep in mind the principle of how regular expressions work.
Each query represents sequence of adjacent tokens and tree elements.
For example, consider following query:
q.num('2').op('+').num('2').op('=').num('4');
It will match on the following fragments 2 + 2 = 4
or 2+2=4
, but won't match on 2+2==4
nor 4=2+2
.
Once brackets are defined, their inner contents will be wrapped into a tree node. It's possible to query tree nodes:
q.tree({
search: q.num('2').op('+').num('2'),
})
.op('=')
.num('4');
The above query will match these strings:
(2 + 2) = 4
[2 + 2] = 4
(1 + 2 + 2 - 1) = 4
(1 + (2 + 2) - 1) = 4
It won't match 2 + 2 = 4
because there is no any nesting.
Add link to CONTRIBUTING.md file that will explain how to get started developing for this package. This can be done once things stabilize enough for us to accept external contributions.
FAQs
Parse and query computer programs source code
The npm package good-enough-parser receives a total of 136,801 weekly downloads. As such, good-enough-parser popularity was classified as popular.
We found that good-enough-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.