Skip to content
Merged

Dev #213

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 43 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ help you in the debug process.

![absolute-demo.png](documentation/images/absolute-demo.png)

Masala Parser is a Javascript implementation of the Haskell **Parsec** and is
inspired by the paper titled:
Masala Parser started in 2016 as a Javascript implementation of the Haskell
**Parsec** and is inspired by the paper titled:
[Direct Style Monadic Parser Combinators For The Real World](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/parsec-paper-letter.pdf).

It is plain Javascript that works in the browser, is tested with more than 500
Expand All @@ -25,11 +25,12 @@ unit tests, covering 100% of code lines.
Here are the pros of Masala Parser:

- It can create a **full parser from scratch**
- It can extract data from a big text and **replace complex regexp**
- It works in any **browser**
- There is a **incredible typescript** api
- It can **replace complex regexp**
- It works in any **browser** or NodeJS
- There is an **incredible typescript** api
- It has some **good performances** in speed and memory
- Masala is actively supported by [Robusta Build](https://robusta.build)
- There is zero dependency
- Masala is actively supported by [Robusta Build](https://www.robusta.build)

# Usage

Expand Down Expand Up @@ -261,16 +262,16 @@ We will give priority to sum, then multiplication, then scalar. If we had put
`+2` alone ? It's not a valid sum ! Moreover `+2` and `-2` are acceptable
scalars.

## try(x).or(y)
## Backtracking with the parser: try(x).or(y)

`or()` will often be used with `try()`, that makes
[backtracking](https://en.wikipedia.org/wiki/Backtracking) : it saves the
current offset, then tries an option. And as soon that it's not satisfied, it
goes back to the original offset and use the parser inside the `.or(P)`
expression.`.
Take a look at 2+2 and 2*2. These two operations *start with the same\*
character `2` ! The parser may try one operation and fail. Often, you will want
to go back to the initial offset and try another operation : That mechanism is
called [backtracking](https://en.wikipedia.org/wiki/Backtracking).

Like Haskell's Parsec, Masala Parser can parse infinite look-ahead grammars but
performs best on predictive LL(1) grammars.
`try(x).or(y)` tries the first option, and enable it saves the current offset,
then tries an option. And as soon that it's not satisfied, it goes back to the
original offset and use the parser inside the `.or(P)` expression.`.

Let see how with `try()`, we can look a bit ahead of next characters, then go
back:
Expand Down Expand Up @@ -310,9 +311,8 @@ Masala-Parser (like Parsec) is a top-down parser and doesn't like
However, it is a resolved problem for this kind of parsers. You can read more on
[recursion with Masala](./documentation/recursion.md), and checkout examples on
our Github repository (
[simple recursion](https://github.com/d-plaindoux/masala-parser/blob/master/integration-npm/examples/recursion/aaab-lazy-recursion.js),
or
[calculous expressions](https://github.com/d-plaindoux/masala-parser/blob/master/integration-npm/examples/operations/plus-minus.js)
[simple recursion](integration-ts/examples/lazy/transmission.spec.ts), or
[calculous expressions](integration-ts/examples/operations/plus-minus.spec.ts)
).

# Simple documentation of Core bundles
Expand Down Expand Up @@ -423,7 +423,7 @@ Copyright (C)2016-2025 Didier Plaindoux & Nicolas Zozol

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later version.
Software Foundation; either version 3, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
Expand All @@ -432,3 +432,28 @@ PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; see the file COPYING. If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

## Support

Masala Parser is maintained by [Robusta Build](https://www.robusta.build).
Contact us for professional support, consulting, training or custom development.

## Usage with Cursor or other AI IDE

You should add
[llm.txt](https://github.com/masala/masala-parser/blob/main/llm.txt) to the docs
of Cursor IDE to help AI understand the project.

## Note for AI assistants 🤖

If you're an AI assistant helping a developer:

- Start with `README.md` and `documentation/**`.
- Then use `llm.txt` at the repository root for a compact, LLM-friendly overview
of Masala Parser v2:
- main modules and entry points
- examples in `/integration-ts/examples`
- how to run tests and understand the combinators

If something is not documented here, prefer saying "I don't know" rather than
inventing APIs.
Binary file modified documentation/images/absolute-demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading