Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-zozol committed Jun 5, 2019
2 parents c1dc5c5 + f029323 commit 8564310
Show file tree
Hide file tree
Showing 155 changed files with 20,775 additions and 2,526 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ coverage
*.iml
**/parser-combinator.js
**/parser-combinator.min.js

quick-test*
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.

A restlet API design tool
Copyright (C) 2013 Didier Plaindoux
Masala-Parser a Javascript Parser Combinator
Copyright (C) 2016-2019 Didier Plaindoux & Nicolas Zozol

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
251 changes: 123 additions & 128 deletions README.md

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
Changelog
====

0.8.1: better ts support
---

Minor change on ts and bug fix


0.7 ->0.8: Using Tuples with then
---

* Any then() and thenXYZ() function call will return a `Tuple` . This tuple has `single()` and `array()` methods to get value.
`Parser.drop()`, `F.nop()` methods will produce a *Neutral element* for that Tuple : it will be ignored.
* Therefore `thenReturns()` is renamed `returns()`.
* `rep()` and `optrep()` will also produce a Tuple
- combination of `rep()` and `then()` will produce one unique Tuple
- you can *break apart* this tuple using `Parser.array()` at any point if needed
* `GenLex` has been totally refactored and simplified for high level parsers on tokens.
* Typescript interface is operational and `masala-parser.d.ts` documentation will generate Masala Parser reference.
* `N.digit()` and `N.digits()` return a number, not a string
* Markdown bundled is removed from the lib, and put as example in typescript integration

Less important :

* `F.layer()` along with `Parser.and()` produces an array of results when all parsers are satisfied.
- it makes backtracking like `F.try()` with `Parser.or()`
- warning: it's still experimental for side cases
* Bug correction on offset for high level parsers.
- Random Access in `ParserStream` will result in unpredicted value. Don't do it.
* `response.isConsumed()` is replaced by `response.isEos()`


0.6 -> 0.7: Typescript support
----

Expand Down
26 changes: 25 additions & 1 deletion documentation/genlex.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,28 @@ Genlex Todos
or it will start a lot of unnecessary functions.
* class Token very strange
* each token should have a decent toString()
*
*



Equivalence
=====

For simple case

let genlex = new GenLex();
genlex.setSeparatorsParser(eol().then(eol().rep()));
const tkBullets = genlex.tokenize(bulletBlock(), 'bulletBlock',500);
const parser = F.any().rep();
Is equivalent to

let separators = eol().then(eol().rep());
let any = separators.optrep().then(bulletBlock()).then(separators.optrep());
let parser = any.rep();

So it might be good to use the second form if stuck when debugging with Genlex.

GenLex is more interesting when the parser is not `F.any()`.
62 changes: 5 additions & 57 deletions documentation/parser-core-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ Usually, you would **NOT** create a Parser from its constructor. You will combin
* the `parseFunction` function will determine the behaviour of the Parser


Here is an example of a home-made parser for going back after an Accept: [https://github.com/d-plaindoux/masala-parser/issues/138#issuecomment-49162720 5]

# Essential Parser functions

### then

* difficulty : 1
* Construct an array of values from previous accepted values
* Construct a Tuple of values from previous accepted values

```js

Expand All @@ -66,7 +67,7 @@ assertEquals(parsing.value, 'abc');
```js
const stream = Streams.ofString('|4.6|');
const floorCombinator = C.char('|').drop()
.then(N.numberLiteral()) // we have ['|',4.6], we keep 4.6
.then(N.number()) // we have ['|',4.6], we keep 4.6
.then(C.char('|').drop()) // we have [4.6, '|'], we keep 4.6
.map(x =>Math.floor(x));

Expand Down Expand Up @@ -95,7 +96,7 @@ const combinator = N.integer()
assertEquals(combinator.parse(stream).value, 40)
```

### thenReturns(value)
### returns(value)

* difficulty : 1
* Forces the value at a given point
Expand Down Expand Up @@ -294,56 +295,3 @@ TODO : Is it possible to have a value for this error ? It would give a
























































Loading

0 comments on commit 8564310

Please sign in to comment.