securemark 0.298.6 → 0.298.7
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 +4 -0
- package/dist/index.js +195 -201
- package/package.json +1 -1
- package/src/parser/api/parse.test.ts +3 -21
- package/src/parser/context.ts +0 -2
- package/src/parser/inline/annotation.test.ts +6 -10
- package/src/parser/inline/annotation.ts +31 -113
- package/src/parser/inline/deletion.ts +5 -4
- package/src/parser/inline/emstrong.ts +11 -4
- package/src/parser/inline/extension/placeholder.ts +1 -1
- package/src/parser/inline/insertion.ts +5 -4
- package/src/parser/inline/italic.ts +5 -4
- package/src/parser/inline/mark.ts +7 -6
- package/src/parser/inline.test.ts +2 -2
- package/src/parser/repeat.ts +133 -0
- package/src/parser/util.ts +1 -70
package/src/parser/util.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { tester } from '../combinator/data/delimiter';
|
|
3
|
-
import { Context, Command } from './context';
|
|
4
|
-
import { min } from 'spica/alias';
|
|
1
|
+
import { List, Node } from '../combinator/data/parser';
|
|
5
2
|
import { rnd0Z } from 'spica/random';
|
|
6
3
|
import { define } from 'typed-dom/dom';
|
|
7
4
|
|
|
@@ -12,72 +9,6 @@ export function* unwrap<N>(nodes: List<Node<N>> | undefined): Iterable<N> {
|
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
11
|
|
|
15
|
-
export function repeat<P extends Parser<HTMLElement | string, Context>>(symbol: string, after: string | RegExp, parser: P, cons: (nodes: List<Node<Parser.Node<P>>>, context: Parser.Context<P>, nest: boolean) => List<Node<Parser.Node<P>>>, termination?: (acc: List<Node<Parser.Node<P>>>, context: Context, prefix: number, postfix: number, state: boolean) => Result<string | Parser.Node<P>>): P;
|
|
16
|
-
export function repeat<N extends HTMLElement | string>(symbol: string, after: string | RegExp, parser: Parser<N>, cons: (nodes: List<Node<N>>, context: Context, nest: boolean) => List<Node<N>>, termination: (acc: List<Node<N>>, context: Context, prefix: number, postfix: number, state: boolean) => Result<string | N, Context> = (nodes, context, prefix, postfix) => {
|
|
17
|
-
const acc = new List<Node<string | N>>();
|
|
18
|
-
if (prefix > 0) {
|
|
19
|
-
acc.push(new Node(symbol[0].repeat(prefix)));
|
|
20
|
-
}
|
|
21
|
-
acc.import(nodes);
|
|
22
|
-
if (postfix > 0) {
|
|
23
|
-
const { source, position } = context;
|
|
24
|
-
acc.push(new Node(source.slice(position, position + postfix)));
|
|
25
|
-
context.position += postfix;
|
|
26
|
-
}
|
|
27
|
-
return acc;
|
|
28
|
-
}): Parser<string | N, Context> {
|
|
29
|
-
const test = tester(after, false);
|
|
30
|
-
return failsafe(input => {
|
|
31
|
-
const context = input;
|
|
32
|
-
const { source, position } = context;
|
|
33
|
-
if (!source.startsWith(symbol, context.position)) return;
|
|
34
|
-
let nodes = new List<Node<N>>();
|
|
35
|
-
let i = symbol.length;
|
|
36
|
-
for (; source[context.position + i] === source[context.position];) ++i;
|
|
37
|
-
context.position += i;
|
|
38
|
-
if (test(input) === undefined) return;
|
|
39
|
-
let state = false;
|
|
40
|
-
for (; i >= symbol.length; i -= symbol.length) {
|
|
41
|
-
if (nodes.length > 0 && source.startsWith(symbol, context.position)) {
|
|
42
|
-
nodes = cons(nodes, context, i > symbol.length);
|
|
43
|
-
context.position += symbol.length;
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
const buf = context.buffer;
|
|
47
|
-
context.buffer = nodes;
|
|
48
|
-
const result = parser(input);
|
|
49
|
-
context.buffer = buf;
|
|
50
|
-
if (result === undefined) break;
|
|
51
|
-
nodes = result;
|
|
52
|
-
switch (nodes.last?.value) {
|
|
53
|
-
case Command.Cancel:
|
|
54
|
-
assert(!source.startsWith(symbol, context.position));
|
|
55
|
-
nodes.pop();
|
|
56
|
-
state = false;
|
|
57
|
-
break;
|
|
58
|
-
case Command.Separator:
|
|
59
|
-
assert(!source.startsWith(symbol, context.position));
|
|
60
|
-
nodes.pop();
|
|
61
|
-
state = true;
|
|
62
|
-
continue;
|
|
63
|
-
default:
|
|
64
|
-
nodes = cons(nodes, context, i > symbol.length);
|
|
65
|
-
state = true;
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
const prefix = i;
|
|
71
|
-
i = 0;
|
|
72
|
-
for (let len = min(prefix, source.length - context.position); i < len && source[context.position + i] === symbol[0];) {
|
|
73
|
-
++i;
|
|
74
|
-
}
|
|
75
|
-
const postfix = i;
|
|
76
|
-
context.range = context.position - position;
|
|
77
|
-
return termination(nodes, context, prefix, postfix, state);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
12
|
export function invalid(
|
|
82
13
|
syntax: string,
|
|
83
14
|
type: string,
|