securemark 0.294.0 → 0.294.2

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 (47) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/design.md +27 -39
  3. package/dist/index.js +208 -180
  4. package/package.json +2 -2
  5. package/src/combinator/control/constraint/contract.ts +2 -2
  6. package/src/combinator/control/constraint/line.ts +2 -2
  7. package/src/combinator/control/manipulation/clear.ts +2 -2
  8. package/src/combinator/control/manipulation/indent.ts +3 -7
  9. package/src/combinator/control/manipulation/lazy.ts +1 -3
  10. package/src/combinator/control/manipulation/scope.ts +4 -6
  11. package/src/combinator/control/manipulation/surround.ts +5 -8
  12. package/src/combinator/control/monad/bind.ts +2 -3
  13. package/src/combinator/data/data.ts +38 -32
  14. package/src/combinator/data/parser/context.test.ts +4 -4
  15. package/src/combinator/data/parser/inits.ts +6 -8
  16. package/src/combinator/data/parser/sequence.test.ts +2 -2
  17. package/src/combinator/data/parser/sequence.ts +5 -7
  18. package/src/combinator/data/parser/some.test.ts +2 -2
  19. package/src/combinator/data/parser/some.ts +5 -7
  20. package/src/combinator/data/parser/subsequence.test.ts +2 -2
  21. package/src/combinator/data/parser/subsequence.ts +2 -2
  22. package/src/combinator/data/parser/tails.ts +2 -2
  23. package/src/combinator/data/parser/union.test.ts +2 -2
  24. package/src/combinator/data/parser/union.ts +2 -2
  25. package/src/combinator/data/parser.ts +36 -39
  26. package/src/debug.test.ts +2 -2
  27. package/src/parser/api/bind.ts +6 -6
  28. package/src/parser/api/header.ts +2 -2
  29. package/src/parser/api/normalize.ts +2 -2
  30. package/src/parser/api/parse.ts +11 -11
  31. package/src/parser/block/codeblock.ts +2 -2
  32. package/src/parser/block/extension/example.ts +2 -2
  33. package/src/parser/block/extension/figure.ts +1 -1
  34. package/src/parser/block/extension/message.ts +2 -2
  35. package/src/parser/block/extension/table.ts +2 -2
  36. package/src/parser/block.ts +5 -1
  37. package/src/parser/inline/autolink/url.test.ts +71 -72
  38. package/src/parser/inline/autolink/url.ts +4 -4
  39. package/src/parser/inline/emstrong.ts +5 -5
  40. package/src/parser/inline/reference.ts +2 -2
  41. package/src/parser/inline/ruby.ts +4 -4
  42. package/src/parser/processor/note.ts +2 -2
  43. package/src/parser/segment.ts +6 -12
  44. package/src/parser/source/line.ts +5 -0
  45. package/src/parser/source/str.ts +1 -1
  46. package/src/parser/util.ts +5 -4
  47. package/src/parser/visibility.ts +2 -2
@@ -1,6 +1,6 @@
1
1
  import { EmStrongParser, EmphasisParser, StrongParser } from '../inline';
2
2
  import { Recursion, Command } from '../context';
3
- import { Result, List, Data, Node, Context, IntermediateParser, eval } from '../../combinator/data/parser';
3
+ import { Result, List, Data, Node, Context, IntermediateParser } from '../../combinator/data/parser';
4
4
  import { union, some, recursion, precedence, validate, surround, open, lazy, bind } from '../../combinator';
5
5
  import { inline } from '../inline';
6
6
  import { strong } from './strong';
@@ -105,7 +105,7 @@ export const emstrong: EmStrongParser = lazy(() => validate('***',
105
105
  case 0:
106
106
  break;
107
107
  case 1:
108
- nodes = eval(bind<EmphasisParser>(
108
+ nodes = bind<EmphasisParser>(
109
109
  subemphasis,
110
110
  ds => {
111
111
  const { source } = context;
@@ -117,11 +117,11 @@ export const emstrong: EmStrongParser = lazy(() => validate('***',
117
117
  return prepend('*', nodes.import(ds));
118
118
  }
119
119
  })
120
- ({ context })) ?? prepend('*', nodes);
120
+ ({ context }) ?? prepend('*', nodes);
121
121
  prefix -= 1;
122
122
  break;
123
123
  case 2:
124
- nodes = eval(bind<StrongParser>(
124
+ nodes = bind<StrongParser>(
125
125
  substrong,
126
126
  ds => {
127
127
  const { source } = context;
@@ -133,7 +133,7 @@ export const emstrong: EmStrongParser = lazy(() => validate('***',
133
133
  return prepend('**', nodes.import(ds));
134
134
  }
135
135
  })
136
- ({ context })) ?? prepend('**', nodes);
136
+ ({ context }) ?? prepend('**', nodes);
137
137
  prefix -= 2;
138
138
  break;
139
139
  }
@@ -1,6 +1,6 @@
1
1
  import { ReferenceParser } from '../inline';
2
2
  import { State, Backtrack, Command } from '../context';
3
- import { List, Data, eval } from '../../combinator/data/parser';
3
+ import { List, Data } from '../../combinator/data/parser';
4
4
  import { union, subsequence, some, precedence, state, constraint, surround, isBacktrack, setBacktrack, lazy } from '../../combinator';
5
5
  import { inline } from '../inline';
6
6
  import { textlink } from './link';
@@ -78,7 +78,7 @@ export const reference: ReferenceParser = lazy(() => constraint(State.reference,
78
78
  })
79
79
  ({ context });
80
80
  if (state & State.annotation && next) {
81
- return (as as List<Data<string | HTMLElement>>).import(bs).import(eval(result!)).import(eval(next));
81
+ return (as as List<Data<string | HTMLElement>>).import(bs).import(result).import(next);
82
82
  }
83
83
  }
84
84
  context.position = position;
@@ -1,6 +1,6 @@
1
1
  import { RubyParser } from '../inline';
2
2
  import { Backtrack } from '../context';
3
- import { List, Data, eval } from '../../combinator/data/parser';
3
+ import { List, Data } from '../../combinator/data/parser';
4
4
  import { inits, surround, setBacktrack, dup, lazy, bind } from '../../combinator';
5
5
  import { unsafehtmlentity } from './htmlentity';
6
6
  import { txt } from '../source';
@@ -76,7 +76,7 @@ const text: RubyParser.TextParser = input => {
76
76
  case '&': {
77
77
  const result = unsafehtmlentity(input) ?? txt(input)!;
78
78
  assert(result);
79
- acc.last!.value += eval(result).head!.value;
79
+ acc.last!.value += result.head!.value;
80
80
  continue;
81
81
  }
82
82
  default: {
@@ -88,7 +88,7 @@ const text: RubyParser.TextParser = input => {
88
88
  }
89
89
  const result = txt(input)!;
90
90
  assert(result);
91
- acc.last!.value += eval(result).head?.value ?? '';
91
+ acc.last!.value += result.head?.value ?? '';
92
92
  continue;
93
93
  }
94
94
  }
@@ -103,7 +103,7 @@ const text: RubyParser.TextParser = input => {
103
103
  function* zip<N extends List.Node>(a: List<N>, b: List<N>): Iterable<[N | undefined, N | undefined]> {
104
104
  const ia = a[Symbol.iterator]();
105
105
  const ib = b[Symbol.iterator]();
106
- while (true) {
106
+ for (; ;) {
107
107
  const ra = ia.next();
108
108
  const rb = ib.next();
109
109
  if (ra.done) break;
@@ -191,7 +191,7 @@ function* proc(defs: Map<string, HTMLLIElement>, note: HTMLOListElement): Genera
191
191
  for (const [key, def] of defs) {
192
192
  defs.delete(key);
193
193
  ++count;
194
- while (length > size) {
194
+ for (; length > size;) {
195
195
  const node = children[count - 1] as HTMLLIElement;
196
196
  if (equal(node, def)) continue I;
197
197
  yield note.removeChild(node);
@@ -207,7 +207,7 @@ function* proc(defs: Map<string, HTMLLIElement>, note: HTMLOListElement): Genera
207
207
  ++length;
208
208
  assert(children.length === length);
209
209
  }
210
- while (length > size) {
210
+ for (; length > size;) {
211
211
  yield note.removeChild(children[size] as HTMLLIElement);
212
212
  --length;
213
213
  assert(children.length === length);
@@ -1,6 +1,5 @@
1
1
  import { MarkdownParser } from '../../markdown';
2
2
  import { Command } from './context';
3
- import { clean, eval } from '../combinator/data/parser';
4
3
  import { union, some } from '../combinator';
5
4
  import { segment as heading } from './block/heading';
6
5
  import { segment as codeblock } from './block/codeblock';
@@ -43,18 +42,13 @@ const parser: SegmentParser = union([
43
42
  export function* segment(source: string): Generator<string, undefined, undefined> {
44
43
  if (!validate(source, MAX_INPUT_SIZE)) return yield `${Command.Error}Too large input over ${MAX_INPUT_SIZE.toLocaleString('en')} bytes.\n${source.slice(0, 1001)}`;
45
44
  assert(source.length < Number.MAX_SAFE_INTEGER);
46
- const context = {
47
- source,
48
- position: 0,
49
- };
50
- const input = { context };
51
- while (context.position < source.length) {
52
- const { position } = context;
53
- const result = parser(input)!;
45
+ for (let position = 0; position < source.length;) {
46
+ const context = { source, position };
47
+ const result = parser({ context })!;
54
48
  assert(result);
55
49
  assert(context.position > position);
56
- const segs = eval(result).length > 0
57
- ? eval(result).foldl<string[]>((acc, { value }) => void acc.push(value) || acc, [])
50
+ const segs = result.length > 0
51
+ ? result.foldl<string[]>((acc, { value }) => void acc.push(value) || acc, [])
58
52
  : [source.slice(position, context.position)];
59
53
  assert(segs.join('') === source.slice(position, context.position));
60
54
  for (let i = 0; i < segs.length; ++i) {
@@ -63,7 +57,7 @@ export function* segment(source: string): Generator<string, undefined, undefined
63
57
  ? yield seg
64
58
  : yield `${Command.Error}Too large segment over ${MAX_SEGMENT_SIZE.toLocaleString('en')} bytes.\n${seg}`
65
59
  }
66
- clean(context);
60
+ position = context.position;
67
61
  }
68
62
  }
69
63
 
@@ -4,6 +4,7 @@ import { List } from '../../combinator/data/parser';
4
4
  export const anyline: AnyLineParser = input => {
5
5
  const { context } = input;
6
6
  const { source, position } = context;
7
+ if (position === source.length) return;
7
8
  context.position = source.indexOf('\n', position) + 1 || source.length;
8
9
  return new List();
9
10
  };
@@ -11,6 +12,8 @@ const regEmptyline = /[^\S\n]*(?:$|\n)/y;
11
12
  export const emptyline: EmptyLineParser = input => {
12
13
  const { context } = input;
13
14
  const { source, position } = context;
15
+ if (position === source.length) return;
16
+ if (source[position] === '\n') return ++context.position, new List();
14
17
  regEmptyline.lastIndex = position;
15
18
  regEmptyline.test(source);
16
19
  const i = regEmptyline.lastIndex;
@@ -22,6 +25,8 @@ const regContentline = /[^\S\n]*\S[^\n]*(?:$|\n)/y;
22
25
  export const contentline: ContentLineParser = input => {
23
26
  const { context } = input;
24
27
  const { source, position } = context;
28
+ if (position === source.length) return;
29
+ if (source[position] === '\n') return;
25
30
  regContentline.lastIndex = position;
26
31
  regContentline.test(source);
27
32
  const i = regContentline.lastIndex;
@@ -13,7 +13,7 @@ export function strs(pattern: string): Parser<string> {
13
13
  return ({ context }) => {
14
14
  const { source } = context;
15
15
  let acc = '';
16
- while (context.position < source.length && source.startsWith(pattern, context.position)) {
16
+ for (; context.position < source.length && source.startsWith(pattern, context.position);) {
17
17
  acc += pattern;
18
18
  context.position += pattern.length;
19
19
  }
@@ -1,10 +1,11 @@
1
1
  import { min } from 'spica/alias';
2
2
  import { MarkdownParser } from '../../markdown';
3
3
  import { Command } from './context';
4
- import { Parser, Result, List, Data, Ctx, Node, Context, eval, failsafe } from '../combinator/data/parser';
4
+ import { Parser, Result, List, Data, Ctx, Node, Context, failsafe } from '../combinator/data/parser';
5
5
  import { define } from 'typed-dom/dom';
6
6
 
7
- export function* unwrap<N>(nodes: List<Data<N>>): Iterable<N> {
7
+ export function* unwrap<N>(nodes: List<Data<N>> | undefined): Iterable<N> {
8
+ if (nodes === undefined) return;
8
9
  for (const node of nodes) {
9
10
  yield node.value;
10
11
  }
@@ -30,7 +31,7 @@ export function repeat<N extends HTMLElement | string>(symbol: string, parser: P
30
31
  assert(source.startsWith(symbol, context.position));
31
32
  let nodes = new List<Data<N>>();
32
33
  let i = symbol.length;
33
- while (source[context.position + i] === source[context.position]) ++i;
34
+ for (; source[context.position + i] === source[context.position];) ++i;
34
35
  context.position += i;
35
36
  let state = false;
36
37
  for (; i >= symbol.length; i -= symbol.length) {
@@ -44,7 +45,7 @@ export function repeat<N extends HTMLElement | string>(symbol: string, parser: P
44
45
  const result = parser(input);
45
46
  context.buffer = buf;
46
47
  if (result === undefined) break;
47
- nodes = eval(result);
48
+ nodes = result;
48
49
  switch (nodes.last?.value) {
49
50
  case Command.Cancel:
50
51
  assert(!source.startsWith(symbol, context.position));
@@ -1,6 +1,6 @@
1
1
  import { MarkdownParser } from '../../markdown';
2
2
  import { Command } from './context';
3
- import { Parser, Input, List, Data, eval, failsafe } from '../combinator/data/parser';
3
+ import { Parser, Input, List, Data, failsafe } from '../combinator/data/parser';
4
4
  import { convert, fmap } from '../combinator';
5
5
  import { unsafehtmlentity } from './inline/htmlentity';
6
6
  import { invisibleHTMLEntityNames } from './api/normalize';
@@ -93,7 +93,7 @@ function isTightStart(input: Input<MarkdownParser.Context>, except?: string): bo
93
93
  switch (true) {
94
94
  case source.length - position > 2
95
95
  && source[position + 1] !== ' '
96
- && eval(unsafehtmlentity(input))?.head?.value.trimStart() === '':
96
+ && unsafehtmlentity(input)?.head?.value.trimStart() === '':
97
97
  context.position = position;
98
98
  return false;
99
99
  }