parser-combinators 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +5 -1
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.js +19 -0
  5. package/{parser.d.ts → dist/parser.d.ts} +0 -0
  6. package/{parser.js → dist/parser.js} +0 -0
  7. package/{parsers → dist/parsers}/any.d.ts +2 -0
  8. package/{parsers → dist/parsers}/any.js +11 -2
  9. package/{parsers → dist/parsers}/between.d.ts +0 -0
  10. package/{parsers → dist/parsers}/between.js +0 -0
  11. package/{parsers → dist/parsers}/exhaust.d.ts +0 -0
  12. package/{parsers → dist/parsers}/exhaust.js +0 -0
  13. package/{parsers → dist/parsers}/index.d.ts +0 -0
  14. package/{parsers → dist/parsers}/index.js +5 -1
  15. package/{parsers → dist/parsers}/many.d.ts +1 -1
  16. package/{parsers → dist/parsers}/many.js +4 -2
  17. package/{parsers → dist/parsers}/map.d.ts +0 -0
  18. package/{parsers → dist/parsers}/map.js +0 -0
  19. package/{parsers → dist/parsers}/opt.d.ts +0 -0
  20. package/{parsers → dist/parsers}/opt.js +0 -0
  21. package/{parsers → dist/parsers}/regex.d.ts +0 -0
  22. package/{parsers → dist/parsers}/regex.js +0 -0
  23. package/{parsers → dist/parsers}/seq.d.ts +1 -0
  24. package/{parsers → dist/parsers}/seq.js +0 -0
  25. package/{parsers → dist/parsers}/str.d.ts +0 -0
  26. package/{parsers → dist/parsers}/str.js +0 -0
  27. package/{parsers → dist/parsers}/utilities.d.ts +5 -1
  28. package/{parsers → dist/parsers}/utilities.js +15 -2
  29. package/{parsers → dist/parsers}/values.d.ts +0 -0
  30. package/{parsers → dist/parsers}/values.js +0 -0
  31. package/{types.d.ts → dist/types.d.ts} +0 -0
  32. package/{types.js → dist/types.js} +0 -0
  33. package/package.json +15 -22
package/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright 2022 Michał Isalski
2
+
3
+ Permission to use, copy, modify, and/or distribute
4
+ this software for any purpose with or without fee is hereby granted,
5
+ provided that the above copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
9
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
10
+ OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
11
+ WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
12
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -6,7 +6,6 @@
6
6
 
7
7
  ![NPM](https://img.shields.io/npm/l/parser-combinators)
8
8
  [![NPM Version](https://badge.fury.io/js/parser-combinators.svg)](https://badge.fury.io/js/parser-combinators)
9
- [![No Dependencies](https://status.david-dm.org/gh/michalusio/parser.svg)](https://status.david-dm.org/)
10
9
 
11
10
  A library of parser combinators, with which you can create your own parsers.
12
11
 
@@ -38,6 +37,8 @@ A library of parser combinators, with which you can create your own parsers.
38
37
  - Utility combinators:
39
38
  - `ref`er
40
39
  - `expect`
40
+ - `expectErase`
41
+ - `surely`
41
42
  - Ready-made value combinators:
42
43
  - `spaces`
43
44
  - `spacesPlus`
@@ -45,6 +46,9 @@ A library of parser combinators, with which you can create your own parsers.
45
46
  - `bool` (and `boolP`)
46
47
  - `int` (and `intP`)
47
48
  - `real` (and `realP`)
49
+ - Whole parsers:
50
+ - Extended Backus-Naur Form (`EBNF`)
51
+ - JavaScript Object Notation (`JSON`)
48
52
 
49
53
  ### Example usage:
50
54
 
@@ -0,0 +1,3 @@
1
+ export * from "./types";
2
+ export * from "./parsers";
3
+ export * from "./parser";
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./parsers"), exports);
19
+ __exportStar(require("./parser"), exports);
File without changes
File without changes
@@ -13,3 +13,5 @@ export declare function any<T, U, V, W>(...parsers: [Parser<T>, Parser<U>, Parse
13
13
  export declare function any<T, U, V>(...parsers: [Parser<T>, Parser<U>, Parser<V>]): Parser<T | U | V>;
14
14
  export declare function any<T, U>(...parsers: [Parser<T>, Parser<U>]): Parser<T | U>;
15
15
  export declare function any<T>(...parsers: [Parser<T>]): Parser<T>;
16
+ export declare function any<T>(...parsers: Parser<T>[]): Parser<T>;
17
+ export declare function surely<T>(parser: Parser<T>): Parser<T>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.any = void 0;
3
+ exports.surely = exports.any = void 0;
4
+ const _1 = require(".");
4
5
  const types_1 = require("../types");
5
6
  function any(...parsers) {
6
7
  return (ctx) => {
@@ -8,13 +9,21 @@ function any(...parsers) {
8
9
  for (const parser of parsers) {
9
10
  const res = parser(ctx);
10
11
  if ((0, types_1.isFailure)(res)) {
12
+ if (res.history.includes('surely')) {
13
+ console.log('shot');
14
+ return (0, types_1.failure)(res.ctx, res.expected, res.history.filter(h => h !== 'surely'));
15
+ }
11
16
  expected.push(res);
12
17
  }
13
18
  else
14
19
  return res;
15
20
  }
16
- const longest = expected.reduce((a, b) => a.ctx.index > b.ctx.index ? a : b);
21
+ const longest = expected.reduce((a, b) => a.history.length > b.history.length ? a : b);
17
22
  return (0, types_1.failure)(longest.ctx, longest.expected, ['any', ...longest.history]);
18
23
  };
19
24
  }
20
25
  exports.any = any;
26
+ function surely(parser) {
27
+ return (0, _1.expect)(parser, 'surely');
28
+ }
29
+ exports.surely = surely;
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -10,7 +10,7 @@ export declare function zeroOrMany<T, V>(item: Parser<T>, separator: Parser<V>):
10
10
  /** Parses one or more occurences of the given parser, separated with the separator parser.
11
11
  * @returns A parser returning an array of many parses, omitting the separator.
12
12
  */
13
- export declare function oneOrMany<T, V>(item: Parser<T>, separator: Parser<V>): Parser<T[]>;
13
+ export declare function oneOrMany<T, V>(item: Parser<T>, separator?: Parser<V> | undefined): Parser<T[]>;
14
14
  /** Parses one or more occurences of the given parser, separated with the separator parser.
15
15
  * @returns A parser returning the result of many parses, reduced using the `reducer` function passed in.
16
16
  */
@@ -33,8 +33,10 @@ exports.zeroOrMany = zeroOrMany;
33
33
  /** Parses one or more occurences of the given parser, separated with the separator parser.
34
34
  * @returns A parser returning an array of many parses, omitting the separator.
35
35
  */
36
- function oneOrMany(item, separator) {
37
- const sequencer = (0, map_1.map)((0, seq_1.seq)(item, many((0, map_1.map)((0, seq_1.seq)(separator, item), ([, t]) => t))), ([t, ts]) => ([t, ...ts]));
36
+ function oneOrMany(item, separator = undefined) {
37
+ const sequencer = (0, map_1.map)((0, seq_1.seq)(item, many(separator
38
+ ? (0, map_1.map)((0, seq_1.seq)(separator, item), ([, t]) => t)
39
+ : item)), ([t, ts]) => ([t, ...ts]));
38
40
  return (ctx) => {
39
41
  const res = sequencer(ctx);
40
42
  if ((0, types_1.isFailure)(res)) {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -13,3 +13,4 @@ export declare function seq<T, U, V, W>(...parsers: [Parser<T>, Parser<U>, Parse
13
13
  export declare function seq<T, U, V>(...parsers: [Parser<T>, Parser<U>, Parser<V>]): Parser<[T, U, V]>;
14
14
  export declare function seq<T, U>(...parsers: [Parser<T>, Parser<U>]): Parser<[T, U]>;
15
15
  export declare function seq<T>(...parsers: [Parser<T>]): Parser<[T]>;
16
+ export declare function seq<T>(...parsers: Parser<T>[]): Parser<T[]>;
File without changes
File without changes
File without changes
@@ -2,8 +2,12 @@ import { Parser } from '../types';
2
2
  /** Allows to make a condition on the result of the parsing function.
3
3
  * @returns A parser returning the same but also performing a given check on the result.
4
4
  */
5
- export declare function ref<T>(parser: Parser<T>, check: ((p: T) => boolean), expected: string): Parser<T>;
5
+ export declare function ref<T>(parser: Parser<T>, check: ((p: T) => boolean), expected?: string): Parser<T>;
6
6
  /** Changes the expected value for when the parser fails.
7
7
  * @returns A parser returning the same but with a different expected value.
8
8
  */
9
9
  export declare function expect<T>(parser: Parser<T>, expected: string): Parser<T>;
10
+ /** Changes the expected value for when the parser fails. Erases the previous history.
11
+ * @returns A parser returning the same but with a different expected value.
12
+ */
13
+ export declare function expectErase<T>(parser: Parser<T>, expected: string): Parser<T>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.expect = exports.ref = void 0;
3
+ exports.expectErase = exports.expect = exports.ref = void 0;
4
4
  const types_1 = require("../types");
5
5
  /** Allows to make a condition on the result of the parsing function.
6
6
  * @returns A parser returning the same but also performing a given check on the result.
@@ -9,7 +9,7 @@ function ref(parser, check, expected) {
9
9
  return (ctx) => {
10
10
  const res = parser(ctx);
11
11
  if (!(0, types_1.isFailure)(res) && !check(res.value)) {
12
- return (0, types_1.failure)(res.ctx, expected, [`ref: ${expected}`]);
12
+ return (0, types_1.failure)(res.ctx, expected !== null && expected !== void 0 ? expected : 'check', [`ref: ${expected !== null && expected !== void 0 ? expected : 'check'}`]);
13
13
  }
14
14
  return res;
15
15
  };
@@ -28,3 +28,16 @@ function expect(parser, expected) {
28
28
  };
29
29
  }
30
30
  exports.expect = expect;
31
+ /** Changes the expected value for when the parser fails. Erases the previous history.
32
+ * @returns A parser returning the same but with a different expected value.
33
+ */
34
+ function expectErase(parser, expected) {
35
+ return (ctx) => {
36
+ const res = parser(ctx);
37
+ if ((0, types_1.isFailure)(res)) {
38
+ return (0, types_1.failure)(res.ctx, expected, [expected]);
39
+ }
40
+ return res;
41
+ };
42
+ }
43
+ exports.expectErase = expectErase;
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "parser-combinators",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "license": "ISC",
5
5
  "maintainers": [
6
6
  "Micha_i"
@@ -16,33 +16,26 @@
16
16
  "description": "A library of parser combinators, with which you can create your own parsers. The library will be continuously improved in time.",
17
17
  "scripts": {
18
18
  "build": "tsc",
19
- "publishing:prepare": "copy package.json dist && copy README.md dist",
20
- "publishing:patch": "npm version patch && npm run publishing:prepare",
21
- "publishing:minor": "npm version minor && npm run publishing:prepare",
22
- "publishing:major": "npm version major && npm run publishing:prepare",
23
19
  "start": "tsc && node .",
24
20
  "lint": "eslint . --ext .ts",
25
- "test:unit": "cross-env TS_NODE_PROJECT=tsconfig.spec.json mocha",
21
+ "test:unit": "cross-env TS_NODE_PROJECT=tsconfig.spec.json mocha tests/**/*.ts",
26
22
  "test": "nyc -e '.ts' --r html -r lcov -r text npm run test:unit",
27
- "test:report": "nyc report --reporter=json > coverage/coverage.json && codecov"
23
+ "test:report": "nyc report --reporter=json > coverage/coverage.json"
28
24
  },
29
25
  "author": "Micha_i <isalski.michal@gmail.com> (https://github.com/michalusio)",
30
- "main": "./parser.js",
31
- "types": "./parser.d.ts",
32
- "dependencies": {},
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
33
28
  "devDependencies": {
34
- "@types/mocha": "^9.0.0",
35
- "@types/node": "^16.7.6",
36
- "@typescript-eslint/eslint-plugin": "^4.14.2",
37
- "@typescript-eslint/parser": "^4.14.2",
38
- "codecov": "^3.8.3",
39
- "cross-env": "^7.0.3",
40
- "eslint": "^7.15.0",
41
- "istanbul": "1.1.0-alpha.1",
42
- "mocha": "^9.1.0",
43
- "nyc": "^15.1.0",
44
- "ts-node": "^10.2.1",
45
- "typescript": "^4.2.4"
29
+ "@types/mocha": "10.0.0",
30
+ "@types/node": "18.11.3",
31
+ "@typescript-eslint/eslint-plugin": "5.40.1",
32
+ "@typescript-eslint/parser": "5.40.1",
33
+ "cross-env": "7.0.3",
34
+ "eslint": "8.25.0",
35
+ "mocha": "10.1.0",
36
+ "nyc": "15.1.0",
37
+ "ts-node": "10.9.1",
38
+ "typescript": "4.8.4"
46
39
  },
47
40
  "keywords": [
48
41
  "parser",