diff --git a/README.md b/README.md index 84a8f0da..3a52884a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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: @@ -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 @@ -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 @@ -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. diff --git a/documentation/images/absolute-demo.png b/documentation/images/absolute-demo.png index 60a04f25..d918f393 100644 Binary files a/documentation/images/absolute-demo.png and b/documentation/images/absolute-demo.png differ diff --git a/ingest/README.md b/ingest/README.md index 68cd109d..bdd1b4dc 100644 --- a/ingest/README.md +++ b/ingest/README.md @@ -1,87 +1,109 @@ # Masala Parser: Javascript Parser Combinators [![npm version](https://badge.fury.io/js/%40masala%2Fparser.svg)](https://badge.fury.io/js/%40masala%2Fparser) -[![Build Status](https://travis-ci.org/d-plaindoux/masala-parser.svg)](https://travis-ci.org/d-plaindoux/masala-parser) [![Coverage Status](https://coveralls.io/repos/d-plaindoux/masala-parser/badge.png?branch=master)](https://coveralls.io/r/d-plaindoux/masala-parser?branch=master) [![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges) -Masala Parser is inspired by the paper titled: +Masala Parser is an Open source javascript library to create your own parsers. +You won't need theoretical bases on languages for many usages. + +Masala Parser shines for **simplicity**, **variations** and **maintainability** +of your parsers. Typescript support and token export for AI processing will also +help you in the debug process. + +![absolute-demo.png](documentation/images/absolute-demo.png) + +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). -Masala Parser is a Javascript implementation of the Haskell **Parsec**. It is -plain Javascript that works in the browser, is tested with more than 450 unit -tests, covering 100% of code lines. +It is plain Javascript that works in the browser, is tested with more than 500 +unit tests, covering 100% of code lines. ### Use cases +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 good **typescript** type declaration -- It can validate complete structure with **variations** -- It's a great starting point for parser education. It's **way simpler than Lex - & Yacc**. -- It's designed to be written in other languages (Python, Java, Rust) with the - same interface - -Masala Parser keywords are **simplicity**, **variations** and -**maintainability**. You won't need theoretical bases on languages for -extraction or validation use cases. - -Masala Parser has relatively good performances, however, Javascript is obviously -not the fastest machine. +- 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 +- There is zero dependency +- Masala is actively supported by [Robusta Build](https://www.robusta.build) # Usage +We made a **7 minutes** Youtube video to explain how to create a parser: + +[![Masala Parser Youtube Video](documentation/images/masala-yt.png)](https://www.youtube.com/watch?v=VNUrvWdtM2g) + +### Installation + With Node Js or modern build npm install -S @masala/parser + yarn add @masala/parser + +Or in the browser, using Javascript ES Modules: -Or in the browser + import {F, standard, Streams} from 'https://unpkg.com/@masala/parser@2.0.0 - [download Release](https://github.com/d-plaindoux/masala-parser/releases) - `