securemark 0.258.2 → 0.258.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 (53) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/index.js +137 -143
  3. package/package.json +1 -1
  4. package/src/combinator/data/parser/context/memo.ts +6 -3
  5. package/src/combinator/data/parser/context.test.ts +3 -3
  6. package/src/combinator/data/parser/context.ts +15 -21
  7. package/src/combinator/data/parser/some.ts +4 -2
  8. package/src/combinator/data/parser.ts +1 -1
  9. package/src/parser/api/bind.ts +1 -1
  10. package/src/parser/api/parse.test.ts +4 -4
  11. package/src/parser/api/parse.ts +1 -1
  12. package/src/parser/block/blockquote.ts +4 -4
  13. package/src/parser/block/dlist.ts +3 -3
  14. package/src/parser/block/extension/table.ts +4 -4
  15. package/src/parser/block/ilist.ts +2 -2
  16. package/src/parser/block/olist.ts +2 -2
  17. package/src/parser/block/reply/cite.ts +2 -2
  18. package/src/parser/block/reply/quote.ts +2 -2
  19. package/src/parser/block/sidefence.ts +2 -2
  20. package/src/parser/block/table.ts +5 -5
  21. package/src/parser/block/ulist.ts +2 -2
  22. package/src/parser/block.ts +2 -2
  23. package/src/parser/context.ts +1 -1
  24. package/src/parser/inline/annotation.ts +6 -5
  25. package/src/parser/inline/autolink/email.ts +2 -2
  26. package/src/parser/inline/autolink/url.ts +2 -2
  27. package/src/parser/inline/autolink.ts +2 -2
  28. package/src/parser/inline/bracket.ts +8 -8
  29. package/src/parser/inline/code.ts +2 -2
  30. package/src/parser/inline/comment.ts +2 -2
  31. package/src/parser/inline/deletion.ts +5 -4
  32. package/src/parser/inline/emphasis.ts +5 -4
  33. package/src/parser/inline/emstrong.ts +5 -4
  34. package/src/parser/inline/extension/index.ts +8 -7
  35. package/src/parser/inline/extension/indexer.ts +2 -2
  36. package/src/parser/inline/extension/label.ts +2 -2
  37. package/src/parser/inline/extension/placeholder.ts +5 -4
  38. package/src/parser/inline/html.ts +2 -2
  39. package/src/parser/inline/htmlentity.ts +2 -2
  40. package/src/parser/inline/insertion.ts +5 -4
  41. package/src/parser/inline/link.ts +10 -8
  42. package/src/parser/inline/mark.ts +5 -4
  43. package/src/parser/inline/math.ts +3 -3
  44. package/src/parser/inline/media.ts +7 -6
  45. package/src/parser/inline/reference.ts +7 -6
  46. package/src/parser/inline/ruby.ts +4 -4
  47. package/src/parser/inline/strong.ts +5 -4
  48. package/src/parser/inline/template.ts +6 -6
  49. package/src/parser/inline.test.ts +2 -0
  50. package/src/parser/source/escapable.ts +2 -2
  51. package/src/parser/source/str.ts +5 -5
  52. package/src/parser/source/text.ts +2 -2
  53. package/src/parser/source/unescapable.ts +2 -2
@@ -2,17 +2,18 @@ import { DeletionParser } from '../inline';
2
2
  import { union, some, syntax, surround, open, lazy } from '../../combinator';
3
3
  import { inline } from '../inline';
4
4
  import { str } from '../source';
5
- import { Rule } from '../context';
5
+ import { Syntax } from '../context';
6
6
  import { blankWith } from '../visibility';
7
7
  import { html, defrag } from 'typed-dom/dom';
8
8
  import { unshift } from 'spica/array';
9
9
 
10
- export const deletion: DeletionParser = lazy(() => syntax(Rule.none, 1, surround(
10
+ export const deletion: DeletionParser = lazy(() => surround(
11
11
  str('~~'),
12
+ syntax(Syntax.none, 1, 1,
12
13
  some(union([
13
14
  some(inline, blankWith('\n', '~~')),
14
15
  open('\n', some(inline, '~'), true),
15
- ])),
16
+ ]))),
16
17
  str('~~'), false,
17
18
  ([, bs], rest) => [[html('del', defrag(bs))], rest],
18
- ([as, bs], rest) => [unshift(as, bs), rest])));
19
+ ([as, bs], rest) => [unshift(as, bs), rest]));
@@ -4,13 +4,14 @@ import { inline } from '../inline';
4
4
  import { emstrong } from './emstrong';
5
5
  import { strong } from './strong';
6
6
  import { str } from '../source';
7
- import { Rule } from '../context';
7
+ import { Syntax } from '../context';
8
8
  import { startTight, blankWith } from '../visibility';
9
9
  import { html, defrag } from 'typed-dom/dom';
10
10
  import { unshift } from 'spica/array';
11
11
 
12
- export const emphasis: EmphasisParser = lazy(() => syntax(Rule.none, 1, surround(
12
+ export const emphasis: EmphasisParser = lazy(() => surround(
13
13
  str('*'),
14
+ syntax(Syntax.none, 1, 1,
14
15
  startTight(some(union([
15
16
  strong,
16
17
  some(inline, blankWith('*')),
@@ -19,7 +20,7 @@ export const emphasis: EmphasisParser = lazy(() => syntax(Rule.none, 1, surround
19
20
  strong,
20
21
  emphasis,
21
22
  ])),
22
- ])), '*'),
23
+ ])), '*')),
23
24
  str('*'), false,
24
25
  ([, bs], rest) => [[html('em', defrag(bs))], rest],
25
- ([as, bs], rest) => [unshift(as, bs), rest])));
26
+ ([as, bs], rest) => [unshift(as, bs), rest]));
@@ -5,7 +5,7 @@ import { inline } from '../inline';
5
5
  import { strong } from './strong';
6
6
  import { emphasis } from './emphasis';
7
7
  import { str } from '../source';
8
- import { Rule } from '../context';
8
+ import { Syntax } from '../context';
9
9
  import { startTight, blankWith } from '../visibility';
10
10
  import { html, defrag } from 'typed-dom/dom';
11
11
  import { unshift } from 'spica/array';
@@ -27,12 +27,13 @@ const subemphasis: IntermediateParser<EmphasisParser> = lazy(() => some(union([
27
27
  ])),
28
28
  ])));
29
29
 
30
- export const emstrong: EmStrongParser = lazy(() => syntax(Rule.none, 1, surround(
30
+ export const emstrong: EmStrongParser = lazy(() => surround(
31
31
  str('***'),
32
+ syntax(Syntax.none, 1, 1,
32
33
  startTight(some(union([
33
34
  some(inline, blankWith('*')),
34
35
  open(some(inline, '*'), inline),
35
- ]))),
36
+ ])))),
36
37
  str(/^\*{1,3}/), false,
37
38
  ([, bs, cs], rest, context): Result<HTMLElement | string, typeof context> => {
38
39
  assert(cs.length === 1);
@@ -58,4 +59,4 @@ export const emstrong: EmStrongParser = lazy(() => syntax(Rule.none, 1, surround
58
59
  }
59
60
  assert(false);
60
61
  },
61
- ([as, bs], rest) => [unshift(as, bs), rest])));
62
+ ([as, bs], rest) => [unshift(as, bs), rest]));
@@ -1,24 +1,25 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { ExtensionParser } from '../../inline';
3
- import { union, some, syntax, creator, precedence, guard, state, validate, surround, open, lazy, fmap } from '../../../combinator';
3
+ import { union, some, syntax, creation, precedence, guard, state, validate, surround, open, lazy, fmap } from '../../../combinator';
4
4
  import { inline } from '../../inline';
5
5
  import { indexee, identity } from './indexee';
6
6
  import { txt, str, stropt } from '../../source';
7
- import { Rule, State } from '../../context';
7
+ import { Syntax, State } from '../../context';
8
8
  import { startTight, trimBlankEnd } from '../../visibility';
9
9
  import { html, define, defrag } from 'typed-dom/dom';
10
10
 
11
11
  import IndexParser = ExtensionParser.IndexParser;
12
12
 
13
- export const index: IndexParser = lazy(() => validate('[#', syntax(Rule.index, 2, fmap(indexee(surround(
13
+ export const index: IndexParser = lazy(() => validate('[#', fmap(indexee(surround(
14
14
  '[#',
15
15
  guard(context => ~context.state! & State.index,
16
+ syntax(Syntax.index, 2, 1,
16
17
  state(State.annotation | State.reference | State.index | State.label | State.link | State.media | State.autolink,
17
18
  startTight(
18
19
  open(stropt(/^\|?/), trimBlankEnd(some(union([
19
20
  signature,
20
21
  inline,
21
- ]), ']', [[/^\\?\n/, 9], [']', 2]])), true)))),
22
+ ]), ']', [[/^\\?\n/, 9], [']', 2]])), true))))),
22
23
  ']',
23
24
  false,
24
25
  ([, ns], rest) => [[html('a', defrag(ns))], rest])),
@@ -30,16 +31,16 @@ export const index: IndexParser = lazy(() => validate('[#', syntax(Rule.index, 2
30
31
  href: el.id ? `#${el.id}` : undefined,
31
32
  },
32
33
  el.childNodes),
33
- ]))));
34
+ ])));
34
35
 
35
- const signature: IndexParser.SignatureParser = lazy(() => creator(fmap(open(
36
+ const signature: IndexParser.SignatureParser = lazy(() => creation(fmap(open(
36
37
  '|#',
37
38
  startTight(some(union([bracket, txt]), ']'))),
38
39
  ns => [
39
40
  html('span', { class: 'indexer', 'data-index': identity(ns.join('')).slice(6) }),
40
41
  ])));
41
42
 
42
- const bracket: IndexParser.SignatureParser.BracketParser = lazy(() => creator(union([
43
+ const bracket: IndexParser.SignatureParser.BracketParser = lazy(() => creation(union([
43
44
  surround(str('('), some(union([bracket, txt]), ')'), str(')'), true),
44
45
  surround(str('['), some(union([bracket, txt]), ']'), str(']'), true),
45
46
  surround(str('{'), some(union([bracket, txt]), '}'), str('}'), true),
@@ -1,10 +1,10 @@
1
1
  import { ExtensionParser } from '../../inline';
2
- import { union, creator, state, verify, focus, surround, fmap } from '../../../combinator';
2
+ import { union, creation, state, verify, focus, surround, fmap } from '../../../combinator';
3
3
  import { index } from './index';
4
4
  import { State } from '../../context';
5
5
  import { html } from 'typed-dom/dom';
6
6
 
7
- export const indexer: ExtensionParser.IndexerParser = creator(fmap(verify(surround(
7
+ export const indexer: ExtensionParser.IndexerParser = creation(fmap(verify(surround(
8
8
  /^\s+(?=\[#\S)/,
9
9
  state(State.index, false,
10
10
  union([
@@ -1,6 +1,6 @@
1
1
  import { Array } from 'spica/global';
2
2
  import { ExtensionParser } from '../../inline';
3
- import { union, guard, creator, validate, surround, clear, fmap } from '../../../combinator';
3
+ import { union, guard, creation, validate, surround, clear, fmap } from '../../../combinator';
4
4
  import { str } from '../../source';
5
5
  import { State } from '../../context';
6
6
  import { html } from 'typed-dom/dom';
@@ -12,7 +12,7 @@ export const segment: ExtensionParser.LabelParser.SegmentParser = clear(validate
12
12
  body,
13
13
  ])));
14
14
 
15
- export const label: ExtensionParser.LabelParser = validate(['[$', '$'], creator(fmap(
15
+ export const label: ExtensionParser.LabelParser = validate(['[$', '$'], creation(fmap(
16
16
  guard(context => ~context.state! & State.label,
17
17
  union([
18
18
  surround('[', body, ']'),
@@ -2,7 +2,7 @@ import { ExtensionParser } from '../../inline';
2
2
  import { union, some, syntax, validate, surround, lazy } from '../../../combinator';
3
3
  import { inline } from '../../inline';
4
4
  import { str } from '../../source';
5
- import { Rule } from '../../context';
5
+ import { Syntax } from '../../context';
6
6
  import { startTight } from '../../visibility';
7
7
  import { html, defrag } from 'typed-dom/dom';
8
8
  import { unshift } from 'spica/array';
@@ -11,9 +11,10 @@ import { unshift } from 'spica/array';
11
11
 
12
12
  // All syntax surrounded by square brackets shouldn't contain line breaks.
13
13
 
14
- export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validate(['[:', '[^'], syntax(Rule.none, 2, surround(
14
+ export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validate(['[:', '[^'], surround(
15
15
  str(/^\[[:^]/),
16
- startTight(some(union([inline]), ']', [[/^\\?\n/, 9], [']', 2]])),
16
+ syntax(Syntax.none, 2, 1,
17
+ startTight(some(union([inline]), ']', [[/^\\?\n/, 9], [']', 2]]))),
17
18
  str(']'), false,
18
19
  ([as, bs], rest) => [[
19
20
  html('span', {
@@ -23,4 +24,4 @@ export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validat
23
24
  'data-invalid-message': `Reserved start symbol "${as[0][1]}" cannot be used in "[]"`,
24
25
  }, defrag(bs)),
25
26
  ], rest],
26
- ([as, bs], rest) => [unshift(as, bs), rest]))));
27
+ ([as, bs], rest) => [unshift(as, bs), rest])));
@@ -3,7 +3,7 @@ import { HTMLParser } from '../inline';
3
3
  import { union, subsequence, some, syntax, validate, focus, surround, open, match, lazy } from '../../combinator';
4
4
  import { inline } from '../inline';
5
5
  import { str } from '../source';
6
- import { Rule } from '../context';
6
+ import { Syntax } from '../context';
7
7
  import { isStartLooseNodes, blankWith } from '../visibility';
8
8
  import { html as h, defrag } from 'typed-dom/dom';
9
9
  import { memoize } from 'spica/memoize';
@@ -19,7 +19,7 @@ const attrspecs = {
19
19
  Object.setPrototypeOf(attrspecs, null);
20
20
  Object.values(attrspecs).forEach(o => Object.setPrototypeOf(o, null));
21
21
 
22
- export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/, syntax(Rule.none, 5, union([
22
+ export const html: HTMLParser = lazy(() => validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/, syntax(Syntax.none, 5, 1, union([
23
23
  focus(
24
24
  '<wbr>',
25
25
  () => [[h('wbr')], '']),
@@ -1,10 +1,10 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { HTMLEntityParser, UnsafeHTMLEntityParser } from '../inline';
3
- import { union, creator, validate, focus, fmap } from '../../combinator';
3
+ import { union, creation, validate, focus, fmap } from '../../combinator';
4
4
  import { html } from 'typed-dom/dom';
5
5
  import { reduce } from 'spica/memoize';
6
6
 
7
- export const unsafehtmlentity: UnsafeHTMLEntityParser = creator(validate('&', focus(
7
+ export const unsafehtmlentity: UnsafeHTMLEntityParser = creation(validate('&', focus(
8
8
  /^&[0-9A-Za-z]+;/,
9
9
  entity => [[parse(entity) ?? `\x1B${entity}`], ''])));
10
10
 
@@ -2,17 +2,18 @@ import { InsertionParser } from '../inline';
2
2
  import { union, some, syntax, surround, open, lazy } from '../../combinator';
3
3
  import { inline } from '../inline';
4
4
  import { str } from '../source';
5
- import { Rule } from '../context';
5
+ import { Syntax } from '../context';
6
6
  import { blankWith } from '../visibility';
7
7
  import { html, defrag } from 'typed-dom/dom';
8
8
  import { unshift } from 'spica/array';
9
9
 
10
- export const insertion: InsertionParser = lazy(() => syntax(Rule.none, 1, surround(
10
+ export const insertion: InsertionParser = lazy(() => surround(
11
11
  str('++'),
12
+ syntax(Syntax.none, 1, 1,
12
13
  some(union([
13
14
  some(inline, blankWith('\n', '++')),
14
15
  open('\n', some(inline, '+'), true),
15
- ])),
16
+ ]))),
16
17
  str('++'), false,
17
18
  ([, bs], rest) => [[html('ins', defrag(bs))], rest],
18
- ([as, bs], rest) => [unshift(as, bs), rest])));
19
+ ([as, bs], rest) => [unshift(as, bs), rest]));
@@ -1,12 +1,12 @@
1
1
  import { undefined, location, encodeURI, decodeURI, Location } from 'spica/global';
2
2
  import { LinkParser, TextLinkParser } from '../inline';
3
3
  import { Result, eval, exec } from '../../combinator/data/parser';
4
- import { union, inits, tails, subsequence, some, guard, syntax, state, validate, surround, open, dup, reverse, lazy, fmap, bind } from '../../combinator';
4
+ import { union, inits, tails, subsequence, some, guard, syntax, creation, precedence, state, validate, surround, open, dup, reverse, lazy, fmap, bind } from '../../combinator';
5
5
  import { inline, media, shortmedia } from '../inline';
6
6
  import { attributes } from './html';
7
7
  import { autolink } from '../autolink';
8
8
  import { unescsource, str } from '../source';
9
- import { Rule, State } from '../context';
9
+ import { Syntax, State } from '../context';
10
10
  import { trimNode } from '../visibility';
11
11
  import { stringify } from '../util';
12
12
  import { html, define, defrag } from 'typed-dom/dom';
@@ -17,8 +17,9 @@ const optspec = {
17
17
  } as const;
18
18
  Object.setPrototypeOf(optspec, null);
19
19
 
20
- export const link: LinkParser = lazy(() => validate(['[', '{'], syntax(Rule.link, 2, 10, bind(
20
+ export const link: LinkParser = lazy(() => validate(['[', '{'], bind(
21
21
  guard(context => ~context.state! & State.link,
22
+ syntax(Syntax.link, 2, 10,
22
23
  fmap(subsequence([
23
24
  state(State.link,
24
25
  dup(union([
@@ -35,7 +36,7 @@ export const link: LinkParser = lazy(() => validate(['[', '{'], syntax(Rule.link
35
36
  ]))),
36
37
  dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
37
38
  ], nodes => nodes[0][0] !== ''),
38
- ([as, bs = []]) => bs[0] === '\r' && bs.shift() ? [as, bs] : as[0] === '\r' && as.shift() ? [[], as] : [as, []])),
39
+ ([as, bs = []]) => bs[0] === '\r' && bs.shift() ? [as, bs] : as[0] === '\r' && as.shift() ? [[], as] : [as, []]))),
39
40
  ([content, params]: [(HTMLElement | string)[], string[]], rest, context) => {
40
41
  assert(content[0] !== '' || params.length === 0);
41
42
  if (content[0] === '') return [content, rest];
@@ -61,13 +62,14 @@ export const link: LinkParser = lazy(() => validate(['[', '{'], syntax(Rule.link
61
62
  if (el.classList.contains('invalid')) return [[el], rest];
62
63
  assert(el.classList.length === 0);
63
64
  return [[define(el, attributes('link', [], optspec, params))], rest];
64
- }))));
65
+ })));
65
66
 
66
- export const textlink: TextLinkParser = lazy(() => validate(['[', '{'], syntax(Rule.link, 2, 10, bind(
67
+ export const textlink: TextLinkParser = lazy(() => validate(['[', '{'], bind(
68
+ creation(10, precedence(2,
67
69
  reverse(tails([
68
70
  dup(surround('[', some(union([unescsource]), ']'), ']')),
69
71
  dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
70
- ])),
72
+ ])))),
71
73
  ([params, content = []], rest, context) => {
72
74
  assert(params[0] === '\r');
73
75
  params.shift();
@@ -86,7 +88,7 @@ export const textlink: TextLinkParser = lazy(() => validate(['[', '{'], syntax(R
86
88
  assert(!el.classList.contains('invalid'));
87
89
  assert(el.classList.length === 0);
88
90
  return [[define(el, attributes('link', [], optspec, params))], rest];
89
- }))));
91
+ })));
90
92
 
91
93
  export const uri: LinkParser.ParameterParser.UriParser = fmap(union([
92
94
  open(/^[^\S\n]+/, str(/^\S+/)),
@@ -3,16 +3,17 @@ import { union, some, syntax, surround, open, lazy } from '../../combinator';
3
3
  import { inline } from '../inline';
4
4
  import { str } from '../source';
5
5
  import { startTight, blankWith } from '../visibility';
6
- import { Rule } from '../context';
6
+ import { Syntax } from '../context';
7
7
  import { html, defrag } from 'typed-dom/dom';
8
8
  import { unshift } from 'spica/array';
9
9
 
10
- export const mark: MarkParser = lazy(() => syntax(Rule.none, 1, surround(
10
+ export const mark: MarkParser = lazy(() => surround(
11
11
  str('=='),
12
+ syntax(Syntax.none, 1, 1,
12
13
  startTight(some(union([
13
14
  some(inline, blankWith('==')),
14
15
  open(some(inline, '='), mark),
15
- ]))),
16
+ ])))),
16
17
  str('=='), false,
17
18
  ([, bs], rest) => [[html('mark', defrag(bs))], rest],
18
- ([as, bs], rest) => [unshift(as, bs), rest])));
19
+ ([as, bs], rest) => [unshift(as, bs), rest]));
@@ -1,11 +1,11 @@
1
1
  import { MathParser } from '../inline';
2
- import { union, some, creator, precedence, validate, focus, rewrite, surround, lazy } from '../../combinator';
2
+ import { union, some, creation, precedence, validate, focus, rewrite, surround, lazy } from '../../combinator';
3
3
  import { escsource, unescsource } from '../source';
4
4
  import { html } from 'typed-dom/dom';
5
5
 
6
6
  const forbiddenCommand = /\\(?:begin|tiny|huge|large)(?![a-z])/i;
7
7
 
8
- export const math: MathParser = lazy(() => validate('$', creator(rewrite(
8
+ export const math: MathParser = lazy(() => validate('$', creation(rewrite(
9
9
  union([
10
10
  surround('$', precedence(6, bracket), '$'),
11
11
  surround(
@@ -31,7 +31,7 @@ export const math: MathParser = lazy(() => validate('$', creator(rewrite(
31
31
  source)
32
32
  ], '']))));
33
33
 
34
- const bracket: MathParser.BracketParser = lazy(() => creator(surround(
34
+ const bracket: MathParser.BracketParser = lazy(() => creation(surround(
35
35
  '{',
36
36
  some(union([
37
37
  bracket,
@@ -1,11 +1,11 @@
1
1
  import { undefined, location } from 'spica/global';
2
2
  import { MediaParser } from '../inline';
3
- import { union, inits, tails, some, creator, precedence, guard, syntax, validate, verify, surround, open, dup, lazy, fmap, bind } from '../../combinator';
3
+ import { union, inits, tails, some, creation, precedence, guard, syntax, validate, verify, surround, open, dup, lazy, fmap, bind } from '../../combinator';
4
4
  import { textlink, uri, option as linkoption, resolve } from './link';
5
5
  import { attributes } from './html';
6
6
  import { unsafehtmlentity } from './htmlentity';
7
7
  import { txt, str } from '../source';
8
- import { Rule, State } from '../context';
8
+ import { Syntax, State } from '../context';
9
9
  import { html, define } from 'typed-dom/dom';
10
10
  import { ReadonlyURL } from 'spica/url';
11
11
  import { unshift, shift, push } from 'spica/array';
@@ -18,9 +18,10 @@ const optspec = {
18
18
  } as const;
19
19
  Object.setPrototypeOf(optspec, null);
20
20
 
21
- export const media: MediaParser = lazy(() => validate(['![', '!{'], syntax(Rule.media, 2, 10, bind(verify(fmap(open(
21
+ export const media: MediaParser = lazy(() => validate(['![', '!{'], bind(verify(fmap(open(
22
22
  '!',
23
23
  guard(context => ~context.state! & State.media,
24
+ syntax(Syntax.media, 2, 10,
24
25
  tails([
25
26
  dup(surround(
26
27
  '[',
@@ -28,7 +29,7 @@ export const media: MediaParser = lazy(() => validate(['![', '!{'], syntax(Rule.
28
29
  ']',
29
30
  true)),
30
31
  dup(surround(/^{(?![{}])/, inits([uri, some(option)]), /^[^\S\n]*}/)),
31
- ]))),
32
+ ])))),
32
33
  ([as, bs]) => bs ? [[as.join('').trim() || as.join('')], shift(bs)[1]] : [[''], shift(as)[1]]),
33
34
  ([[text]]) => text === '' || text.trim() !== ''),
34
35
  ([[text], params], rest, context) => {
@@ -58,9 +59,9 @@ export const media: MediaParser = lazy(() => validate(['![', '!{'], syntax(Rule.
58
59
  textlink as MediaParser,
59
60
  ([link]) => [define(link, { target: '_blank' }, [el])])
60
61
  (`{ ${INSECURE_URI}${params.join('')} }${rest}`, context);
61
- }))));
62
+ })));
62
63
 
63
- const bracket: MediaParser.TextParser.BracketParser = lazy(() => creator(union([
64
+ const bracket: MediaParser.TextParser.BracketParser = lazy(() => creation(union([
64
65
  surround(str('('), some(union([unsafehtmlentity, bracket, txt]), ')'), str(')'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
65
66
  surround(str('['), some(union([unsafehtmlentity, bracket, txt]), ']'), str(']'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
66
67
  surround(str('{'), some(union([unsafehtmlentity, bracket, txt]), '}'), str('}'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
@@ -1,17 +1,18 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { ReferenceParser } from '../inline';
3
- import { union, subsequence, some, context, creator, guard, syntax, state, validate, surround, open, lazy, bind } from '../../combinator';
3
+ import { union, subsequence, some, context, creation, guard, syntax, state, surround, open, lazy, bind } from '../../combinator';
4
4
  import { inline } from '../inline';
5
5
  import { optimize } from './link';
6
6
  import { str, stropt } from '../source';
7
- import { Rule, State } from '../context';
7
+ import { Syntax, State } from '../context';
8
8
  import { regBlankStart, startLoose, trimNode } from '../visibility';
9
9
  import { stringify } from '../util';
10
10
  import { html, defrag } from 'typed-dom/dom';
11
11
 
12
- export const reference: ReferenceParser = lazy(() => validate('[[', syntax(Rule.reference, 6, surround(
12
+ export const reference: ReferenceParser = lazy(() => surround(
13
13
  '[[',
14
14
  guard(context => ~context.state! & State.reference,
15
+ syntax(Syntax.reference, 6, 1,
15
16
  state(State.annotation | State.reference | State.media,
16
17
  startLoose(
17
18
  context({ delimiters: undefined },
@@ -19,13 +20,13 @@ export const reference: ReferenceParser = lazy(() => validate('[[', syntax(Rule.
19
20
  abbr,
20
21
  open(stropt(/^(?=\^)/), some(inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]])),
21
22
  some(inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]]),
22
- ])), ']'))),
23
+ ])), ']')))),
23
24
  ']]',
24
25
  false,
25
26
  ([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNode(defrag(ns)))])], rest],
26
- ([, ns, rest], next) => next[0] === ']' ? undefined : optimize('[[', ns, rest, next)))));
27
+ ([, ns, rest], next) => next[0] === ']' ? undefined : optimize('[[', ns, rest, next)));
27
28
 
28
- const abbr: ReferenceParser.AbbrParser = creator(bind(surround(
29
+ const abbr: ReferenceParser.AbbrParser = creation(bind(surround(
29
30
  '^',
30
31
  union([str(/^(?![0-9]+\s?[|\]])[0-9A-Za-z]+(?:(?:-|(?=\W)(?!'\d)'?(?!\.\d)\.?(?!,\S),? ?)[0-9A-Za-z]+)*(?:-|'?\.?,? ?)?/)]),
31
32
  /^\|?(?=]])|^\|[^\S\n]*/),
@@ -1,15 +1,15 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { RubyParser } from '../inline';
3
3
  import { eval, exec } from '../../combinator/data/parser';
4
- import { sequence, syntax, creator, validate, verify, focus, surround, lazy, fmap } from '../../combinator';
4
+ import { sequence, syntax, creation, validate, verify, focus, surround, lazy, fmap } from '../../combinator';
5
5
  import { unsafehtmlentity } from './htmlentity';
6
6
  import { text as txt } from '../source';
7
- import { Rule } from '../context';
7
+ import { Syntax } from '../context';
8
8
  import { isStartTightNodes } from '../visibility';
9
9
  import { html, defrag } from 'typed-dom/dom';
10
10
  import { unshift, push } from 'spica/array';
11
11
 
12
- export const ruby: RubyParser = lazy(() => validate('[', syntax(Rule.none, 2, fmap(verify(
12
+ export const ruby: RubyParser = lazy(() => validate('[', syntax(Syntax.none, 2, 1, fmap(verify(
13
13
  sequence([
14
14
  surround('[', focus(/^(?:\\[^\n]|[^\\[\](){}"\n])+(?=]\()/, text), ']'),
15
15
  surround('(', focus(/^(?:\\[^\n]|[^\\[\](){}"\n])+(?=\))/, text), ')'),
@@ -48,7 +48,7 @@ export const ruby: RubyParser = lazy(() => validate('[', syntax(Rule.none, 2, fm
48
48
  }
49
49
  }))));
50
50
 
51
- const text: RubyParser.TextParser = creator((source, context) => {
51
+ const text: RubyParser.TextParser = creation((source, context) => {
52
52
  const acc = [''];
53
53
  while (source !== '') {
54
54
  assert(source[0] !== '\n');
@@ -3,20 +3,21 @@ import { union, some, syntax, surround, open, lazy } from '../../combinator';
3
3
  import { inline } from '../inline';
4
4
  import { emstrong } from './emstrong';
5
5
  import { str } from '../source';
6
- import { Rule } from '../context';
6
+ import { Syntax } from '../context';
7
7
  import { startTight, blankWith } from '../visibility';
8
8
  import { html, defrag } from 'typed-dom/dom';
9
9
  import { unshift } from 'spica/array';
10
10
 
11
- export const strong: StrongParser = lazy(() => syntax(Rule.none, 1, surround(
11
+ export const strong: StrongParser = lazy(() => surround(
12
12
  str('**'),
13
+ syntax(Syntax.none, 1, 1,
13
14
  startTight(some(union([
14
15
  some(inline, blankWith('**')),
15
16
  open(some(inline, '*'), union([
16
17
  emstrong,
17
18
  strong,
18
19
  ])),
19
- ])), '*'),
20
+ ])), '*')),
20
21
  str('**'), false,
21
22
  ([, bs], rest) => [[html('strong', defrag(bs))], rest],
22
- ([as, bs], rest) => [unshift(as, bs), rest])));
23
+ ([as, bs], rest) => [unshift(as, bs), rest]));
@@ -1,18 +1,18 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { TemplateParser } from '../inline';
3
- import { union, some, syntax, creator, precedence, surround, lazy } from '../../combinator';
3
+ import { union, some, syntax, creation, precedence, surround, lazy } from '../../combinator';
4
4
  import { optimize } from './link';
5
5
  import { escsource, str } from '../source';
6
- import { Rule } from '../context';
6
+ import { Syntax } from '../context';
7
7
  import { html } from 'typed-dom/dom';
8
8
  import { unshift } from 'spica/array';
9
9
 
10
- export const template: TemplateParser = lazy(() => syntax(Rule.none, 2, surround(
11
- '{{', some(union([bracket, escsource]), '}'), '}}', true,
10
+ export const template: TemplateParser = lazy(() => surround(
11
+ '{{', syntax(Syntax.none, 2, 1, some(union([bracket, escsource]), '}')), '}}', true,
12
12
  ([, ns = []], rest) => [[html('span', { class: 'template' }, `{{${ns.join('').replace(/\x1B/g, '')}}}`)], rest],
13
- ([, ns = [], rest], next) => next[0] === '}' ? undefined : optimize('{{', ns, rest, next))));
13
+ ([, ns = [], rest], next) => next[0] === '}' ? undefined : optimize('{{', ns, rest, next)));
14
14
 
15
- const bracket: TemplateParser.BracketParser = lazy(() => creator(union([
15
+ const bracket: TemplateParser.BracketParser = lazy(() => creation(union([
16
16
  surround(str('('), some(union([bracket, escsource]), ')'), str(')'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
17
17
  surround(str('['), some(union([bracket, escsource]), ']'), str(']'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
18
18
  surround(str('{'), some(union([bracket, escsource]), '}'), str('}'), true, undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
@@ -168,6 +168,8 @@ describe('Unit: parser/inline', () => {
168
168
  assert.deepStrictEqual(inspect(parser('[^a@b')), [['[^', '<a class="email" href="mailto:a@b">a@b</a>'], '']);
169
169
  assert.deepStrictEqual(inspect(parser('[#a*b\nc*]')), [['[', '<a href="/hashtags/a" class="hashtag">#a</a>', '<em>b<br>c</em>', ']'], '']);
170
170
  assert.deepStrictEqual(inspect(parser('[*a\nb*]{/}')), [['[', '<em>a<br>b</em>', ']', '<a href="/">/</a>'], '']);
171
+ assert.deepStrictEqual(inspect(parser('[*a\nb]*')), [['[', '*', 'a', '<br>', 'b', ']', '*'], '']);
172
+ assert.deepStrictEqual(inspect(parser('[*[a\nb*]')), [['', '[', '*', '[', 'a', '<br>', 'b', '*', ']'], '']);
171
173
  assert.deepStrictEqual(inspect(parser('[[*a\nb*]]')), [['[', '[', '<em>a<br>b</em>', ']', ']'], '']);
172
174
  assert.deepStrictEqual(inspect(parser('"[% *"*"*')), [['"', '[%', ' ', '*', '"', '*', '"', '*'], '']);
173
175
  assert.deepStrictEqual(inspect(parser('"[% "*"* %]')), [['"', '[%', ' ', '"', '*', '"', '*', ' ', '%', ']'], '']);
@@ -1,10 +1,10 @@
1
1
  import { EscapableSourceParser } from '../source';
2
- import { creator } from '../../combinator';
2
+ import { creation } from '../../combinator';
3
3
  import { nonWhitespace } from './text';
4
4
 
5
5
  const delimiter = /[\s\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]/;
6
6
 
7
- export const escsource: EscapableSourceParser = creator(source => {
7
+ export const escsource: EscapableSourceParser = creation(source => {
8
8
  if (source === '') return;
9
9
  const i = source.search(delimiter);
10
10
  switch (i) {
@@ -1,19 +1,19 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { StrParser } from '../source';
3
3
  import { Parser, Context } from '../../combinator/data/parser';
4
- import { creator } from '../../combinator';
4
+ import { creation } from '../../combinator';
5
5
 
6
6
  export function str(pattern: string | RegExp): StrParser;
7
7
  export function str(pattern: string | RegExp): Parser<string, Context<StrParser>, []> {
8
8
  assert(pattern);
9
9
  return typeof pattern === 'string'
10
- ? creator(source => {
10
+ ? creation(source => {
11
11
  if (source === '') return;
12
12
  return source.slice(0, pattern.length) === pattern
13
13
  ? [[pattern], source.slice(pattern.length)]
14
14
  : undefined;
15
15
  })
16
- : creator(source => {
16
+ : creation(source => {
17
17
  if (source === '') return;
18
18
  const m = source.match(pattern);
19
19
  return m && m[0].length > 0
@@ -26,13 +26,13 @@ export function stropt(pattern: string | RegExp): StrParser;
26
26
  export function stropt(pattern: string | RegExp): Parser<string, Context<StrParser>, []> {
27
27
  assert(pattern);
28
28
  return typeof pattern === 'string'
29
- ? creator(source => {
29
+ ? creation(source => {
30
30
  if (source === '') return;
31
31
  return source.slice(0, pattern.length) === pattern
32
32
  ? [[pattern], source.slice(pattern.length)]
33
33
  : undefined;
34
34
  })
35
- : creator(source => {
35
+ : creation(source => {
36
36
  if (source === '') return;
37
37
  const m = source.match(pattern);
38
38
  return m
@@ -1,6 +1,6 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { TextParser, TxtParser, LinebreakParser } from '../source';
3
- import { union, creator, focus } from '../../combinator';
3
+ import { union, creation, focus } from '../../combinator';
4
4
  import { str } from './str';
5
5
  import { html } from 'typed-dom/dom';
6
6
 
@@ -9,7 +9,7 @@ export const nonWhitespace = /[\S\n]|$/;
9
9
  export const nonAlphanumeric = /[^0-9A-Za-z]|\S#|$/;
10
10
  const repeat = str(/^(.)\1*/);
11
11
 
12
- export const text: TextParser = creator((source, context) => {
12
+ export const text: TextParser = creation((source, context) => {
13
13
  if (source === '') return;
14
14
  const i = source.search(delimiter);
15
15
  switch (i) {
@@ -1,8 +1,8 @@
1
1
  import { UnescapableSourceParser } from '../source';
2
- import { creator } from '../../combinator';
2
+ import { creation } from '../../combinator';
3
3
  import { delimiter, nonWhitespace, nonAlphanumeric, isAlphanumeric } from './text';
4
4
 
5
- export const unescsource: UnescapableSourceParser = creator(source => {
5
+ export const unescsource: UnescapableSourceParser = creation(source => {
6
6
  assert(source[0] !== '\x1B');
7
7
  if (source === '') return;
8
8
  const i = source.search(delimiter);