@beeff/tuco 0.0.0-stage → 1.0.0-rc0
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.
- package/CHANGELOG.md +115 -0
- package/LICENSE +22 -0
- package/README.md +35 -2
- package/lib/tuco.d.ts +78 -0
- package/lib/tuco.js +282 -0
- package/lib/tuco.js.map +1 -0
- package/package.json +48 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
# version 1.0.0
|
|
4
|
+
|
|
5
|
+
- [x] 36 [build] Add publish files to `package.json` `files`: `lib`, `README.md`, `CHANGELOG.md`, `LICENSE`
|
|
6
|
+
- [x] 35 [docs] Rename `TODO.md` to `CHANGELOG.md` and update the references in `CLAUDE.md` (section header + text) and the self-references in the changelog
|
|
7
|
+
- [x] 34 [tests] Replace `node:assert` (`deepEqual`/`strictEqual`/`assert`/`throws`) with `@beeff/loose-match` matchers in every test: one `match(...).with(...)` per test; add `@beeff/loose-match` to devDeps; rewrite the `DESIGN.md` test-style section
|
|
8
|
+
- [x] 33 [docs] Translate `.md` files to English (`DESIGN.md`, `CHANGELOG.md`, `CLAUDE.md`; `README.md` was already English) and document the language rule + `CHANGELOG.md` workflow in `CLAUDE.md`
|
|
9
|
+
- [x] 32 [docs] Translate the remaining Russian comments to English: `test/demo.abnf.ts` (header, inline, `;`-comments inside `source`), `test/demo.calculator.test.ts` (header + inline), `test/demo.query.test.ts` (op0/op1 precedence block); `src/` is already English; `DESIGN.md`/`CHANGELOG.md`/`CLAUDE.md` — docs/backlog/instructions, untouched
|
|
10
|
+
- [x] 31 [breaking] Replace `chain`/`foldl`/`foldr` with `foldLeft`/`foldRight` (chain+fold in one step, no `[head, pairs]` leak); `chain`/`foldl`/`foldr` become internal `__*`; update demos/tests and the default export; two overloads (default tree → `Parser<any>`, custom `apply` → `Parser<A>`)
|
|
11
|
+
- [x] 30 [types] Type `foldl`/`foldr` (option 1): input `(value: [V, [P, V][]]) => any`; `apply` with `op: P`, `left`/`right` by meaning (operand `V` / accumulator `any`); the result stays `any`; defaults `V = any`, `P = any`
|
|
12
|
+
- [x] 29 [types] Remove `Parser<any>` via variadic-tuple inference (no overloads): `Combinator<A>` + helpers `ValueOf`/`ValuesOf`/`ScalarOrTuple`/`RepValue`; one generic signature per combinator (`all`/`first`/`second`/`between`/`rep1`/`rep0`/`optional`/`or`/`chain`); leave the bodies unchanged (`__expose<any>` is already compatible — signatures only); leave `char*`/`word` — already `Parser<string>`
|
|
13
|
+
- [x] 28 [docs] Compact JSDoc comments for the 17 public functions of `src/tuco.ts` (in English); translate the Russian `__all` comment (arity asymmetry) to English
|
|
14
|
+
- [x] 27 [verify] `npm run typecheck` (clean), `npm test` (107 passing), `npm run build` → `lib/`, sanity-import `lib/tuco.js`
|
|
15
|
+
- [x] 26 [docs] `README.md`: remove `gulp`, describe `npm install`/`npm test`/`npm run build`/`npm run typecheck`
|
|
16
|
+
- [x] 25 [var] `var` → `const`/`let` in `src/` and `test/`; update `DESIGN.md` (style `var` → `const`/`let`, assert example → `deepEqual`)
|
|
17
|
+
- [x] 24 [tests] `test/*.js` → `test/*.ts`: import `../src/tuco.ts`; assert via `deepEqual`/`'failed' in r`; forward decls `: any`; `.mocharc.cjs` → `test/*.ts`
|
|
18
|
+
- [x] 23 [lib] `tuco.js` → `src/tuco.ts`: types `Cursor`/`Fail`/`Success`/`Result`/`Parser`, rest parameters instead of `arguments`, type-only export of types, public API unchanged (default object + 17 named)
|
|
19
|
+
- [x] 22 [setup] Toolchain: devDeps `typescript@7` + `tsx` + `@types/node` + `@types/mocha`; `tsconfig.json` + `tsconfig.build.json`; `package.json` (`main`/`types`/`files`/scripts); `.gitignore` + `lib`
|
|
20
|
+
|
|
21
|
+
- [x] 21 [bug] Unary minus binds tighter than `^` (should be looser)
|
|
22
|
+
- Where: `test/demo.calculator-2.test.js` — `atom = ... | '-' atom`.
|
|
23
|
+
- Effect: `-2^2` parsed as `(-2)^2`, but the convention is `-(2^2)`.
|
|
24
|
+
- Fix: remove `'-' atom` from `atom`, insert a `unary = '-' unary | power` level between `mul` and `power`.
|
|
25
|
+
|
|
26
|
+
- [x] 20 [feature] `chain` / `foldl` / `foldr` — folding operator chains
|
|
27
|
+
- Where: `tuco.js` (exports `chain`, `foldl`, `foldr`), tests `test/tuco.test.js`.
|
|
28
|
+
- `chain(operand, operator)` = `all(operand, rep0(all(operator, operand)))`, returns `[head, pairs]`.
|
|
29
|
+
- `foldl(apply?)` / `foldr(apply?)` fold the pairs left/right; the default `apply` is `(op, a, b) => [op, a, b]`.
|
|
30
|
+
- Gives left (`2-3-4`) and right (`2^3^2`) associativity without left recursion.
|
|
31
|
+
|
|
32
|
+
- [x] 19 [test] Regression tests for the bugs found
|
|
33
|
+
- The suite is green now (74 passing), but bugs 1–6 are not covered by tests.
|
|
34
|
+
- Add: `word('')` (expect at construction), `rep1()/rep0()/optional()` with no arguments, `2-3-4` for associativity, `buildClauses(null)`, `deepEqual` instead of `assert(r, {...})`.
|
|
35
|
+
|
|
36
|
+
- [x] 18 [test] `demo.calculator.test.js` doesn't test
|
|
37
|
+
- `assert` is imported but unused — only `console.log` of the AST. Not a single assertion (mocha sees an empty file).
|
|
38
|
+
- Fix: add asserts (and catch item 4 along the way).
|
|
39
|
+
|
|
40
|
+
- [x] 17 [improvement] Metadata inconsistency
|
|
41
|
+
- npm name `tuco` vs bower name `tuco.js` (`package.json:2`, `bower.json:2`);
|
|
42
|
+
- license URL → `hollander/tuco.js` (`package.json:23`), bower homepage → `Hollander/tuco.js` (`bower.json:4`), repository → `Pavel-Husakouski/tuco.js` (`package.json:7`).
|
|
43
|
+
- Fix: unify on one account and one name.
|
|
44
|
+
|
|
45
|
+
- [x] 16 [improvement] The gulp task is named `build`, but runs tests
|
|
46
|
+
- Where: `gulpfile.js:4`.
|
|
47
|
+
- Fix: rename to `test`/`default`; add `"scripts": {"test": "gulp build"}` to package.json.
|
|
48
|
+
|
|
49
|
+
- [x] 15 [design] `demo.abnf.js` — ABNF instead of EBNF
|
|
50
|
+
- Renamed `test/demo.ebnf.js` → `test/demo.abnf.js`; the spec was rewritten in ABNF (RFC 5234).
|
|
51
|
+
- The meta-demo (parsing this ABNF with tuco itself) is not part of the item — it stays a future idea.
|
|
52
|
+
|
|
53
|
+
- [x] 14 [design] The two-operator `Op0`/`Op1` trick in the query grammar
|
|
54
|
+
- Where: `test/demo.query.test.js`.
|
|
55
|
+
- `AND` before a parenthesis without a space binds as shaped, before a word otherwise. A subtle precedence mechanism that doesn't read from the code — needs an explanatory comment.
|
|
56
|
+
|
|
57
|
+
- [x] 13 [design] `nsImport` via `eval`
|
|
58
|
+
- Removed: the library moved to ESM (`"type": "module"`), tests use named imports.
|
|
59
|
+
|
|
60
|
+
- [x] 12 [design] The `optional(a)` vs `optional(a, b)` asymmetry
|
|
61
|
+
- Documented in `DESIGN.md` and by a comment in `__all`.
|
|
62
|
+
|
|
63
|
+
- [x] 11 [design] `rep1` builds its array via concat + slice
|
|
64
|
+
- Replaced with direct code: `[v].concat(x == null ? [] : x)`.
|
|
65
|
+
|
|
66
|
+
- [x] 10 [design] `parseWithRestore` is fragile
|
|
67
|
+
- Where: `test/demo.query.test.js`.
|
|
68
|
+
- If `parser(text)` returns `null` — it crashes on `result.rest`. It only survives now because `query` never returns `null` (all parts are under `optional`) — that's non-obvious and worth a comment.
|
|
69
|
+
|
|
70
|
+
- [x] 9 [design] `null` as an error loses position and expectations
|
|
71
|
+
- You can't tell *where* parsing stopped and *what* was expected. That's why the query demo grew the `parseWithRestore` hack (rewrites the input, replacing the "bad" character with a space).
|
|
72
|
+
- Option: return `{expected, pos}` or a failure object instead of `null` — removes the need for the workaround.
|
|
73
|
+
|
|
74
|
+
- [x] 8 [design] O(n²) on slices
|
|
75
|
+
- Where: `tuco.js:96-97` — `__anyChar` does `rest.slice(1)` per character, copying the rest of the string each time.
|
|
76
|
+
- Unnoticeable for query strings, painful for long texts.
|
|
77
|
+
- Option: an internal cursor `{str, pos}` while keeping the external API.
|
|
78
|
+
|
|
79
|
+
- [x] 7 [design] `Function.prototype.map` — a global prototype patch
|
|
80
|
+
- Where: `tuco.js:35`.
|
|
81
|
+
- Any function in the app gains `.map`, and an enumerable one at that. The idea "parser = function → mappable" is good, but the implementation is risky.
|
|
82
|
+
- Option: a plain `map(parser, f)` function + keep `.map` as sugar; or make the property non-enumerable.
|
|
83
|
+
|
|
84
|
+
- [x] 6 [bug] `assert(r, {...})` instead of `assert.deepEqual`
|
|
85
|
+
- Where: `test/tuco.test.js:420` (the "all not null when match" test).
|
|
86
|
+
- Effect: the second `assert` argument is a *message*, not an expectation: values are never checked, the test passes "by luck".
|
|
87
|
+
- Fix: `assert.deepEqual(r, { value:['x','y','z','1'], rest:'rest' });`.
|
|
88
|
+
|
|
89
|
+
- [x] 5 [bug] `!result == null` — a dead guard due to operator precedence
|
|
90
|
+
- Where: `test/demo.query.test.js:110` in `buildClauses`.
|
|
91
|
+
- Effect: `(!result) == null` is always `false`, the early exit never fires; on `null` it crashes on `result.kind`.
|
|
92
|
+
- Fix: `if(result == null) return [];`.
|
|
93
|
+
|
|
94
|
+
- [x] 4 [bug] Calculator: right associativity for `-` and `/`
|
|
95
|
+
- Where: `test/demo.calculator.test.js` — `expr_tail > ["+" factor expr_tail | "-" factor expr_tail]` (a right-recursive tail).
|
|
96
|
+
- Effect: `2-3-4` parses as `2-(3-4)`, not `(2-3)-4`. Irrelevant for `+`/`*`, wrong semantics for `-`/`/`. Not caught because the demo only prints the AST and doesn't evaluate.
|
|
97
|
+
- Verified: `expr('2-3-4')` → `[2, ["-", 3, ["-", 4]]]`.
|
|
98
|
+
- Fix: left associativity (accumulator/fold in the tail) + evaluation in the demo so the test catches it.
|
|
99
|
+
|
|
100
|
+
- [x] 3 [bug] `rep1()` / `rep0()` / `optional()` with no arguments
|
|
101
|
+
- Where: `tuco.js:201-206`, `tuco.js:224-230`, `tuco.js:232-244` — there's no length check (unlike `all()` and `or()`, which have one); `__areCombinators([])` returns `true`, because `[].every(...)` on an empty array is truthy.
|
|
102
|
+
- Effect: the same TypeError via `__all([])`.
|
|
103
|
+
- Verified: `tuco.rep1()('a')`, `tuco.optional()('a')` → TypeError.
|
|
104
|
+
- Fix: add `args.length >= 1` to `__expect`.
|
|
105
|
+
|
|
106
|
+
- [x] 2 [bug] `word('')` builds a broken parser
|
|
107
|
+
- Where: `tuco.js:190-199` — `__expect` only checks `__isString`, though the message promises "non-empty string".
|
|
108
|
+
- Effect: `''.split('')` → `[]`, `__all([])` returns a parser that throws `TypeError: Cannot read properties of undefined (reading 'rest')` when called (`tuco.js:168`). It fails at parse time, not at construction.
|
|
109
|
+
- Verified: `tuco.word('')('a')` → TypeError.
|
|
110
|
+
- Fix: `__expect(__isString(text) && text.length > 0, ...)`.
|
|
111
|
+
|
|
112
|
+
- [x] 1 [bug] `package.json` — invalid JSON
|
|
113
|
+
- Where: `package.json:11` — a trailing comma after `"name": "Pavel Husakouski",`
|
|
114
|
+
- Effect: `npm install` fails to parse; even `mocha` can't start from the repo (`ERR_MOCHA_UNPARSABLE_FILE`), needing the `--no-package` flag.
|
|
115
|
+
- Fix: remove the comma. Also: `"licenses"` → `"license": "MIT"` (SPDX), `"tags"` → `"keywords"`, add `"scripts": {"test": "gulp build"}`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pavel Husakouski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
In memories of Tuco Benedicto Pacifico Juan Maria Ramirez and Eli Herschel Wallach
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
tuco
|
|
6
|
+
====
|
|
7
|
+
|
|
8
|
+
Minimalist library to use with simple query grammars, built on parser combinators. Written in TypeScript: source lives in `src/`, compiled to `lib/`.
|
|
9
|
+
|
|
10
|
+
Usage
|
|
11
|
+
-----
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { or, word } from '@beeff/tuco';
|
|
15
|
+
|
|
16
|
+
const parser = or(word('first'), word('second'));
|
|
17
|
+
parser('firstsecond'); // { value: 'first', rest: 'second' }
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Look at `test/demo*.ts` for more details.
|
|
21
|
+
|
|
22
|
+
Development
|
|
23
|
+
-----------
|
|
24
|
+
|
|
25
|
+
* npm install
|
|
26
|
+
* npm test # mocha + tsx
|
|
27
|
+
* npm run typecheck # tsc --noEmit
|
|
28
|
+
* npm run build # tsc -> lib/ (JS + .d.ts + sourcemaps)
|
|
29
|
+
|
|
30
|
+
Priorities
|
|
31
|
+
----------
|
|
32
|
+
|
|
33
|
+
* Quality
|
|
34
|
+
* Very minimum set of features
|
|
35
|
+
* Easy to read, easy to understand, easy to use
|
|
36
|
+
* Short, compact code
|
package/lib/tuco.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export type Cursor = {
|
|
2
|
+
str: string;
|
|
3
|
+
pos: number;
|
|
4
|
+
};
|
|
5
|
+
export type Fail = {
|
|
6
|
+
failed: true;
|
|
7
|
+
pos: number;
|
|
8
|
+
expected: string[];
|
|
9
|
+
};
|
|
10
|
+
export type Success<T> = {
|
|
11
|
+
value: T;
|
|
12
|
+
rest: string;
|
|
13
|
+
};
|
|
14
|
+
export type Result<T> = Success<T> | Fail;
|
|
15
|
+
export interface Parser<T> {
|
|
16
|
+
(input: string | null): Result<T>;
|
|
17
|
+
map<U>(projection: (value: T) => U): Parser<U>;
|
|
18
|
+
}
|
|
19
|
+
export type Combinator<A = any> = string | ((input: string | null) => Result<A>);
|
|
20
|
+
export type ValueOf<C> = C extends string ? string : C extends Parser<infer A> ? A : any;
|
|
21
|
+
export type ValuesOf<Cs extends Combinator[]> = {
|
|
22
|
+
[K in keyof Cs]: ValueOf<Cs[K]>;
|
|
23
|
+
};
|
|
24
|
+
export type ScalarOrTuple<V extends any[]> = V extends [infer A] ? A : V;
|
|
25
|
+
export type RepValue<Cs extends Combinator[]> = Cs extends [infer C] ? ValueOf<C>[] : ValuesOf<Cs>[];
|
|
26
|
+
/** Matches a single character not present in `chars`. */
|
|
27
|
+
export declare function charExcept(chars: string): Parser<string>;
|
|
28
|
+
/** Matches a single character present in `chars`. */
|
|
29
|
+
export declare function charOneOf(chars: string): Parser<string>;
|
|
30
|
+
/** Matches the single character `chr`. */
|
|
31
|
+
export declare function charIs(chr: string): Parser<string>;
|
|
32
|
+
/** Matches one character satisfying `predicate`; `expected` names it in errors. */
|
|
33
|
+
export declare function charMeets(predicate: (ch: string) => boolean, expected?: string): Parser<string>;
|
|
34
|
+
/** Matches any single character. */
|
|
35
|
+
export declare function anyChar(): Parser<string>;
|
|
36
|
+
/** Matches two or more combinators in order; value is the array of their values. */
|
|
37
|
+
export declare function all<Cs extends Combinator[]>(...combinators: Cs): Parser<ValuesOf<Cs>>;
|
|
38
|
+
/** Matches `a` then `b`; returns `a`'s value. */
|
|
39
|
+
export declare function first<A extends Combinator, B extends Combinator>(a: A, b: B): Parser<ValueOf<A>>;
|
|
40
|
+
/** Matches `a` then `b`; returns `b`'s value. */
|
|
41
|
+
export declare function second<A extends Combinator, B extends Combinator>(a: A, b: B): Parser<ValueOf<B>>;
|
|
42
|
+
/** Matches `a`, `b`, `c` in order; returns `b`'s value. */
|
|
43
|
+
export declare function between<A extends Combinator, B extends Combinator, C extends Combinator>(a: A, b: B, c: C): Parser<ValueOf<B>>;
|
|
44
|
+
/** Matches the literal string `text`. */
|
|
45
|
+
export declare function word(text: string): Parser<string>;
|
|
46
|
+
/** One or more repetitions; a single combinator yields a flat array, several yield a list of pairs. */
|
|
47
|
+
export declare function rep1<Cs extends Combinator[]>(...combinators: Cs): Parser<RepValue<Cs>>;
|
|
48
|
+
/** Zero or more repetitions; a single combinator yields a flat array (or null), several yield a list of pairs. */
|
|
49
|
+
export declare function rep0<Cs extends Combinator[]>(...combinators: Cs): Parser<RepValue<Cs> | null>;
|
|
50
|
+
/** Matches zero or one; a single combinator yields a scalar, several yield an array. */
|
|
51
|
+
export declare function optional<Cs extends Combinator[]>(...combinators: Cs): Parser<ScalarOrTuple<ValuesOf<Cs>> | null>;
|
|
52
|
+
/** Tries combinators in order; keeps the furthest failure. */
|
|
53
|
+
export declare function or<Cs extends Combinator[]>(...combinators: Cs): Parser<ValuesOf<Cs>[number]>;
|
|
54
|
+
/** Parses `operand (operator operand)*`, left-folding the operators into the value. */
|
|
55
|
+
export declare function foldLeft<O extends Combinator, P extends Combinator>(operand: O, operator: P): Parser<any>;
|
|
56
|
+
export declare function foldLeft<O extends Combinator, P extends Combinator, A = any>(operand: O, operator: P, apply: (op: ValueOf<P>, left: A, right: ValueOf<O>) => A): Parser<A>;
|
|
57
|
+
/** Parses `operand (operator operand)*`, right-folding the operators into the value. */
|
|
58
|
+
export declare function foldRight<O extends Combinator, P extends Combinator>(operand: O, operator: P): Parser<any>;
|
|
59
|
+
export declare function foldRight<O extends Combinator, P extends Combinator, A = any>(operand: O, operator: P, apply: (op: ValueOf<P>, left: ValueOf<O>, right: A) => A): Parser<A>;
|
|
60
|
+
declare const _default: {
|
|
61
|
+
all: typeof all;
|
|
62
|
+
anyChar: typeof anyChar;
|
|
63
|
+
between: typeof between;
|
|
64
|
+
charExcept: typeof charExcept;
|
|
65
|
+
charIs: typeof charIs;
|
|
66
|
+
charMeets: typeof charMeets;
|
|
67
|
+
charOneOf: typeof charOneOf;
|
|
68
|
+
foldLeft: typeof foldLeft;
|
|
69
|
+
foldRight: typeof foldRight;
|
|
70
|
+
optional: typeof optional;
|
|
71
|
+
or: typeof or;
|
|
72
|
+
rep0: typeof rep0;
|
|
73
|
+
rep1: typeof rep1;
|
|
74
|
+
first: typeof first;
|
|
75
|
+
second: typeof second;
|
|
76
|
+
word: typeof word;
|
|
77
|
+
};
|
|
78
|
+
export default _default;
|
package/lib/tuco.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// Parsers are functions `rest -> { value, rest } | { failed, pos, expected }`.
|
|
2
|
+
// Internally the remaining input is a cursor `{ str, pos }`, so no substring
|
|
3
|
+
// is ever copied while parsing. `__expose` converts the cursor back to a
|
|
4
|
+
// plain string only at the public boundary, which is O(n) once instead of
|
|
5
|
+
// O(n^2). A failed parse carries the position it stopped at and what it
|
|
6
|
+
// expected there, instead of a bare `null`.
|
|
7
|
+
function __isCursor(x) {
|
|
8
|
+
return x != null && typeof x === 'object' && __isString(x.str) && typeof x.pos === 'number';
|
|
9
|
+
}
|
|
10
|
+
function __toCursor(rest) {
|
|
11
|
+
if (__isCursor(rest) || rest == null)
|
|
12
|
+
return rest;
|
|
13
|
+
return { str: rest, pos: 0 };
|
|
14
|
+
}
|
|
15
|
+
function __materialize(result) {
|
|
16
|
+
if (result == null || __isFail(result))
|
|
17
|
+
return result;
|
|
18
|
+
return { value: result.value, rest: result.rest.str.slice(result.rest.pos) };
|
|
19
|
+
}
|
|
20
|
+
function __expose(parser) {
|
|
21
|
+
const exposed = (function (rest) {
|
|
22
|
+
if (__isCursor(rest))
|
|
23
|
+
return parser(rest);
|
|
24
|
+
return __materialize(parser(__toCursor(rest)));
|
|
25
|
+
});
|
|
26
|
+
exposed.map = function (projection) {
|
|
27
|
+
return __expose(__map(parser, projection));
|
|
28
|
+
};
|
|
29
|
+
return exposed;
|
|
30
|
+
}
|
|
31
|
+
function __map(parser, projection) {
|
|
32
|
+
__expect(__isFunction(projection), '`map` accepts projection function');
|
|
33
|
+
return function _map(cursor) {
|
|
34
|
+
const result = parser(cursor);
|
|
35
|
+
return __isFail(result) ? result : { value: projection(result.value), rest: result.rest };
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function __fail(pos, expected) {
|
|
39
|
+
return { failed: true, pos: pos, expected: __isArray(expected) ? expected : [expected] };
|
|
40
|
+
}
|
|
41
|
+
function __isFail(r) {
|
|
42
|
+
return r != null && r.failed === true;
|
|
43
|
+
}
|
|
44
|
+
function __expect(checkResult, msg) {
|
|
45
|
+
if (checkResult)
|
|
46
|
+
return;
|
|
47
|
+
throw new Error(msg);
|
|
48
|
+
}
|
|
49
|
+
/** Matches a single character not present in `chars`. */
|
|
50
|
+
export function charExcept(chars) {
|
|
51
|
+
__expect(__isString(chars), '`charExcept` accepts string');
|
|
52
|
+
return charMeets(function (ch) {
|
|
53
|
+
return chars.indexOf(ch) < 0;
|
|
54
|
+
}, 'char except "' + chars + '"');
|
|
55
|
+
}
|
|
56
|
+
/** Matches a single character present in `chars`. */
|
|
57
|
+
export function charOneOf(chars) {
|
|
58
|
+
__expect(__isString(chars), '`charOneOf` accepts string');
|
|
59
|
+
return charMeets(function (ch) {
|
|
60
|
+
return chars.indexOf(ch) > -1;
|
|
61
|
+
}, 'one of "' + chars + '"');
|
|
62
|
+
}
|
|
63
|
+
/** Matches the single character `chr`. */
|
|
64
|
+
export function charIs(chr) {
|
|
65
|
+
__expect(__isChar(chr), '`charIs` accepts single character');
|
|
66
|
+
return charMeets(function (ch) {
|
|
67
|
+
return ch == chr;
|
|
68
|
+
}, '"' + chr + '"');
|
|
69
|
+
}
|
|
70
|
+
/** Matches one character satisfying `predicate`; `expected` names it in errors. */
|
|
71
|
+
export function charMeets(predicate, expected) {
|
|
72
|
+
__expect(__isFunction(predicate), '`charMeets` accepts predicate');
|
|
73
|
+
return __expose(function (cursor) {
|
|
74
|
+
const result = __anyChar(cursor);
|
|
75
|
+
if (__isFail(result))
|
|
76
|
+
return result;
|
|
77
|
+
if (!predicate(result.value))
|
|
78
|
+
return __fail(cursor.pos, expected == null ? 'char matching predicate' : expected);
|
|
79
|
+
return result;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** Matches any single character. */
|
|
83
|
+
export function anyChar() {
|
|
84
|
+
return __expose(__anyChar);
|
|
85
|
+
}
|
|
86
|
+
function __anyChar(cursor) {
|
|
87
|
+
if (cursor == null || cursor.pos >= cursor.str.length)
|
|
88
|
+
return __fail(cursor == null ? 0 : cursor.pos, 'any character');
|
|
89
|
+
return { value: cursor.str.charAt(cursor.pos), rest: { str: cursor.str, pos: cursor.pos + 1 } };
|
|
90
|
+
}
|
|
91
|
+
/** Matches two or more combinators in order; value is the array of their values. */
|
|
92
|
+
export function all(...combinators) {
|
|
93
|
+
__expect(__areCombinators(combinators) && combinators.length >= 2, '`all` accepts at least two combinators');
|
|
94
|
+
return __expose(__all(combinators));
|
|
95
|
+
}
|
|
96
|
+
function __isChar(arg) {
|
|
97
|
+
return typeof (arg) == "string" && arg.length == 1;
|
|
98
|
+
}
|
|
99
|
+
function __isString(arg) {
|
|
100
|
+
return typeof (arg) == "string";
|
|
101
|
+
}
|
|
102
|
+
function __isFunction(arg) {
|
|
103
|
+
return typeof (arg) == "function";
|
|
104
|
+
}
|
|
105
|
+
function __areCombinators(array) {
|
|
106
|
+
return array.every(function (arg) {
|
|
107
|
+
return __isFunction(arg) || __isString(arg);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function __isArray(arg) {
|
|
111
|
+
return Object.prototype.toString.call(arg) == '[object Array]';
|
|
112
|
+
}
|
|
113
|
+
function __builtin(parsers) {
|
|
114
|
+
if (__isString(parsers))
|
|
115
|
+
return word(parsers);
|
|
116
|
+
if (!__isArray(parsers)) {
|
|
117
|
+
return parsers;
|
|
118
|
+
}
|
|
119
|
+
return parsers.map(function (parser) {
|
|
120
|
+
if (__isString(parser))
|
|
121
|
+
return word(parser);
|
|
122
|
+
return parser;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function __all(combinators, indexToTake) {
|
|
126
|
+
const parsers = __builtin(combinators);
|
|
127
|
+
// A single combinator is returned unwrapped, so the value is a scalar
|
|
128
|
+
// rather than an array. Hence `optional(a)` → scalar, `optional(a, b)` →
|
|
129
|
+
// [va, vb]; the same applies to rep1/rep0 (see DESIGN.md).
|
|
130
|
+
if (parsers.length == 1)
|
|
131
|
+
return parsers[0];
|
|
132
|
+
return function (cursor) {
|
|
133
|
+
const results = [];
|
|
134
|
+
let result;
|
|
135
|
+
let rest = cursor;
|
|
136
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
137
|
+
result = parsers[i](rest);
|
|
138
|
+
if (__isFail(result))
|
|
139
|
+
return result;
|
|
140
|
+
results.push(result.value);
|
|
141
|
+
rest = result.rest;
|
|
142
|
+
}
|
|
143
|
+
return { value: indexToTake == null ? results : results[indexToTake], rest: result.rest };
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** Matches `a` then `b`; returns `a`'s value. */
|
|
147
|
+
export function first(a, b) {
|
|
148
|
+
__expect(__areCombinators([a, b]), '`first` accepts two combinators');
|
|
149
|
+
return __expose(__all([a, b], 0));
|
|
150
|
+
}
|
|
151
|
+
/** Matches `a` then `b`; returns `b`'s value. */
|
|
152
|
+
export function second(a, b) {
|
|
153
|
+
__expect(__areCombinators([a, b]), '`second` accepts two combinators');
|
|
154
|
+
return __expose(__all([a, b], 1));
|
|
155
|
+
}
|
|
156
|
+
/** Matches `a`, `b`, `c` in order; returns `b`'s value. */
|
|
157
|
+
export function between(a, b, c) {
|
|
158
|
+
__expect(__areCombinators([a, b, c]), '`between` accepts three combinators');
|
|
159
|
+
return __expose(__all([a, b, c], 1));
|
|
160
|
+
}
|
|
161
|
+
/** Matches the literal string `text`. */
|
|
162
|
+
export function word(text) {
|
|
163
|
+
__expect(__isString(text) && text.length > 0, '`word` accepts non-empty string');
|
|
164
|
+
if (text.length == 1)
|
|
165
|
+
return charIs(text);
|
|
166
|
+
return __expose(__all(text.split(''))).map(function (value) {
|
|
167
|
+
return text;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function __rep1(parser) {
|
|
171
|
+
return function (cursor) {
|
|
172
|
+
const result1 = parser(cursor);
|
|
173
|
+
if (__isFail(result1))
|
|
174
|
+
return result1;
|
|
175
|
+
const result0 = __rep0(parser)(result1.rest);
|
|
176
|
+
const value = [result1.value].concat(result0.value == null ? [] : result0.value);
|
|
177
|
+
return { value: value, rest: result0.rest };
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/** One or more repetitions; a single combinator yields a flat array, several yield a list of pairs. */
|
|
181
|
+
export function rep1(...combinators) {
|
|
182
|
+
__expect(__areCombinators(combinators) && combinators.length >= 1, '`rep1` accepts at least one combinator');
|
|
183
|
+
return __expose(__rep1(__all(combinators)));
|
|
184
|
+
}
|
|
185
|
+
function __rep0(parser) {
|
|
186
|
+
return __optional(__rep1(parser));
|
|
187
|
+
}
|
|
188
|
+
/** Zero or more repetitions; a single combinator yields a flat array (or null), several yield a list of pairs. */
|
|
189
|
+
export function rep0(...combinators) {
|
|
190
|
+
__expect(__areCombinators(combinators) && combinators.length >= 1, '`rep0` accepts at least one combinator');
|
|
191
|
+
return __expose(__rep0(__all(combinators)));
|
|
192
|
+
}
|
|
193
|
+
function __optional(parser) {
|
|
194
|
+
return function (cursor) {
|
|
195
|
+
const result = parser(cursor);
|
|
196
|
+
return __isFail(result) ? { value: null, rest: cursor } : result;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/** Matches zero or one; a single combinator yields a scalar, several yield an array. */
|
|
200
|
+
export function optional(...combinators) {
|
|
201
|
+
__expect(__areCombinators(combinators) && combinators.length >= 1, '`optional` accepts at least one combinator');
|
|
202
|
+
return __expose(__optional(__all(combinators)));
|
|
203
|
+
}
|
|
204
|
+
function __or(parsers) {
|
|
205
|
+
return function (cursor) {
|
|
206
|
+
const failures = [];
|
|
207
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
208
|
+
const result = parsers[i](cursor);
|
|
209
|
+
if (!__isFail(result))
|
|
210
|
+
return result;
|
|
211
|
+
failures.push(result);
|
|
212
|
+
}
|
|
213
|
+
return __mergeFailures(failures);
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function __mergeFailures(failures) {
|
|
217
|
+
let best = failures[0];
|
|
218
|
+
for (let i = 1; i < failures.length; i++) {
|
|
219
|
+
const f = failures[i];
|
|
220
|
+
if (f.pos > best.pos)
|
|
221
|
+
best = f;
|
|
222
|
+
else if (f.pos === best.pos)
|
|
223
|
+
best = __fail(best.pos, __union(best.expected, f.expected));
|
|
224
|
+
}
|
|
225
|
+
return best;
|
|
226
|
+
}
|
|
227
|
+
function __union(a, b) {
|
|
228
|
+
const out = a.slice();
|
|
229
|
+
for (let i = 0; i < b.length; i++)
|
|
230
|
+
if (out.indexOf(b[i]) < 0)
|
|
231
|
+
out.push(b[i]);
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
234
|
+
/** Tries combinators in order; keeps the furthest failure. */
|
|
235
|
+
export function or(...combinators) {
|
|
236
|
+
__expect(__areCombinators(combinators) && combinators.length >= 2, '`or` accepts at least two combinators');
|
|
237
|
+
return __expose(__or(__builtin(combinators)));
|
|
238
|
+
}
|
|
239
|
+
// Parses `operand (operator operand)*`, returning `[head, pairs]`.
|
|
240
|
+
function __chain(operand, operator) {
|
|
241
|
+
__expect(__areCombinators([operand, operator]), 'accepts two combinators');
|
|
242
|
+
const o = __builtin(operand);
|
|
243
|
+
const p = __builtin(operator);
|
|
244
|
+
return __expose(__all([o, __rep0(__all([p, o]))]));
|
|
245
|
+
}
|
|
246
|
+
function __defaultApply(op, left, right) {
|
|
247
|
+
return [op, left, right];
|
|
248
|
+
}
|
|
249
|
+
// Left fold over a chain's `[head, pairs]`; default apply is `(op, a, b) => [op, a, b]`.
|
|
250
|
+
function __foldl(apply) {
|
|
251
|
+
__expect(apply == null || __isFunction(apply), 'accepts an optional apply function');
|
|
252
|
+
apply = apply || __defaultApply;
|
|
253
|
+
return function _foldl(v) {
|
|
254
|
+
let acc = v[0];
|
|
255
|
+
const pairs = v[1] == null ? [] : v[1];
|
|
256
|
+
for (let i = 0; i < pairs.length; i++)
|
|
257
|
+
acc = apply(pairs[i][0], acc, pairs[i][1]);
|
|
258
|
+
return acc;
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
// Right fold over a chain's `[head, pairs]`; default apply is `(op, a, b) => [op, a, b]`.
|
|
262
|
+
function __foldr(apply) {
|
|
263
|
+
__expect(apply == null || __isFunction(apply), 'accepts an optional apply function');
|
|
264
|
+
apply = apply || __defaultApply;
|
|
265
|
+
return function _foldr(v) {
|
|
266
|
+
const pairs = v[1] == null ? [] : v[1];
|
|
267
|
+
if (pairs.length == 0)
|
|
268
|
+
return v[0];
|
|
269
|
+
let acc = pairs[pairs.length - 1][1];
|
|
270
|
+
for (let i = pairs.length - 1; i >= 0; i--)
|
|
271
|
+
acc = apply(pairs[i][0], i == 0 ? v[0] : pairs[i - 1][1], acc);
|
|
272
|
+
return acc;
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
export function foldLeft(operand, operator, apply) {
|
|
276
|
+
return __chain(operand, operator).map(__foldl(apply));
|
|
277
|
+
}
|
|
278
|
+
export function foldRight(operand, operator, apply) {
|
|
279
|
+
return __chain(operand, operator).map(__foldr(apply));
|
|
280
|
+
}
|
|
281
|
+
export default { all, anyChar, between, charExcept, charIs, charMeets, charOneOf, foldLeft, foldRight, optional, or, rep0, rep1, first, second, word };
|
|
282
|
+
//# sourceMappingURL=tuco.js.map
|
package/lib/tuco.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tuco.js","sourceRoot":"","sources":["../src/tuco.ts"],"names":[],"mappings":"AAqBA,+EAA+E;AAC/E,6EAA6E;AAC7E,0EAA0E;AAC1E,0EAA0E;AAC1E,yEAAyE;AACzE,4CAA4C;AAE5C,SAAS,UAAU,CAAC,CAAM;IACtB,OAAO,CAAC,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG,KAAK,QAAQ,CAAC;AAChG,CAAC;AAED,SAAS,UAAU,CAAC,IAAS;IACzB,IAAG,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI;QAC/B,OAAO,IAAI,CAAC;IAChB,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;AACjC,CAAC;AAED,SAAS,aAAa,CAAC,MAAW;IAC9B,IAAG,MAAM,IAAI,IAAI,IAAI,QAAQ,CAAC,MAAM,CAAC;QACjC,OAAO,MAAM,CAAC;IAClB,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AACjF,CAAC;AAED,SAAS,QAAQ,CAAI,MAA+B;IAChD,MAAM,OAAO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OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1D,CAAC;AAQD,MAAM,UAAU,SAAS,CAAC,OAAY,EAAE,QAAa,EAAE,KAAW;IAC9D,OAAO,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,eAAe,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beeff/tuco",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0-rc0",
|
|
4
|
+
"description": "Minimalist library to use with simple query grammars, built on parser combinators.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/Pavel-Husakouski/tuco.js"
|
|
8
|
+
},
|
|
9
|
+
"author": {
|
|
10
|
+
"name": "Pavel Husakouski"
|
|
11
|
+
},
|
|
12
|
+
"main": "./lib/tuco.js",
|
|
13
|
+
"types": "./lib/tuco.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"lib",
|
|
16
|
+
"README.md",
|
|
17
|
+
"CHANGELOG.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"tags": [
|
|
22
|
+
"query",
|
|
23
|
+
"expression",
|
|
24
|
+
"grammar",
|
|
25
|
+
"parser",
|
|
26
|
+
"combinators"
|
|
27
|
+
],
|
|
28
|
+
"licenses": [
|
|
29
|
+
{
|
|
30
|
+
"type": "MIT",
|
|
31
|
+
"url": "https://raw.githubusercontent.com/hollander/tuco.js/master/LICENSE"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"test": "node --import tsx ./node_modules/mocha/bin/mocha.js",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"build": "tsc -p tsconfig.build.json"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@beeff/loose-match": "^1.0.0",
|
|
41
|
+
"@types/mocha": "^10.0.10",
|
|
42
|
+
"@types/node": "^26.6.11",
|
|
43
|
+
"mocha": "^12.0.3",
|
|
44
|
+
"tsx": "^4.23.15",
|
|
45
|
+
"typescript": "^7.0.2"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
}
|
|
50
|
+
}
|