@yozora/tokenizer-break 1.3.0 → 2.0.0-alpha.0

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/lib/cjs/index.js CHANGED
@@ -20,66 +20,71 @@ class BreakTokenizer extends coreTokenizer.BaseInlineTokenizer {
20
20
  name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
21
21
  priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.SOFT_INLINE,
22
22
  });
23
- }
24
- _findDelimiter(startIndex, endIndex, api) {
25
- const nodePoints = api.getNodePoints();
26
- for (let i = startIndex + 1; i < endIndex; ++i) {
27
- if (nodePoints[i].codePoint !== character.VirtualCodePoint.LINE_END)
28
- continue;
29
- const c = nodePoints[i - 1].codePoint;
30
- let _start = null;
31
- let markerType = null;
32
- switch (c) {
33
- case character.AsciiCodePoint.BACKSLASH: {
34
- let x = i - 2;
35
- for (; x >= startIndex; x -= 1) {
36
- if (nodePoints[x].codePoint !== character.AsciiCodePoint.BACKSLASH)
23
+ this.match = api => {
24
+ return {
25
+ findDelimiter: () => coreTokenizer.genFindDelimiter(_findDelimiter),
26
+ processSingleDelimiter,
27
+ };
28
+ function _findDelimiter(startIndex, endIndex) {
29
+ const nodePoints = api.getNodePoints();
30
+ for (let i = startIndex + 1; i < endIndex; ++i) {
31
+ if (nodePoints[i].codePoint !== character.VirtualCodePoint.LINE_END)
32
+ continue;
33
+ const c = nodePoints[i - 1].codePoint;
34
+ let _start = null;
35
+ let markerType = null;
36
+ switch (c) {
37
+ case character.AsciiCodePoint.BACKSLASH: {
38
+ let x = i - 2;
39
+ for (; x >= startIndex; x -= 1) {
40
+ if (nodePoints[x].codePoint !== character.AsciiCodePoint.BACKSLASH)
41
+ break;
42
+ }
43
+ if (((i - x) & 1) === 0) {
44
+ _start = i - 1;
45
+ markerType = BreakTokenMarkerType.BACKSLASH;
46
+ }
37
47
  break;
38
- }
39
- if (((i - x) & 1) === 0) {
40
- _start = i - 1;
41
- markerType = BreakTokenMarkerType.BACKSLASH;
42
- }
43
- break;
44
- }
45
- case character.AsciiCodePoint.SPACE: {
46
- let x = i - 2;
47
- for (; x >= startIndex; x -= 1) {
48
- if (nodePoints[x].codePoint !== character.AsciiCodePoint.SPACE)
48
+ }
49
+ case character.AsciiCodePoint.SPACE: {
50
+ let x = i - 2;
51
+ for (; x >= startIndex; x -= 1) {
52
+ if (nodePoints[x].codePoint !== character.AsciiCodePoint.SPACE)
53
+ break;
54
+ }
55
+ if (i - x > 2) {
56
+ _start = x + 1;
57
+ markerType = BreakTokenMarkerType.MORE_THAN_TWO_SPACES;
58
+ }
49
59
  break;
60
+ }
50
61
  }
51
- if (i - x > 2) {
52
- _start = x + 1;
53
- markerType = BreakTokenMarkerType.MORE_THAN_TWO_SPACES;
54
- }
55
- break;
62
+ if (_start == null || markerType == null)
63
+ continue;
64
+ return {
65
+ type: 'full',
66
+ markerType,
67
+ startIndex: _start,
68
+ endIndex: i,
69
+ };
56
70
  }
71
+ return null;
72
+ }
73
+ function processSingleDelimiter(delimiter) {
74
+ const token = {
75
+ nodeType: ast.BreakType,
76
+ startIndex: delimiter.startIndex,
77
+ endIndex: delimiter.endIndex,
78
+ };
79
+ return [token];
57
80
  }
58
- if (_start == null || markerType == null)
59
- continue;
60
- return {
61
- type: 'full',
62
- markerType,
63
- startIndex: _start,
64
- endIndex: i,
65
- };
66
- }
67
- return null;
68
- }
69
- processSingleDelimiter(delimiter) {
70
- const token = {
71
- nodeType: ast.BreakType,
72
- startIndex: delimiter.startIndex,
73
- endIndex: delimiter.endIndex,
74
81
  };
75
- return [token];
76
- }
77
- parseInline() {
78
- const result = { type: ast.BreakType };
79
- return result;
82
+ this.parse = () => ({
83
+ parse: () => ({ type: ast.BreakType }),
84
+ });
80
85
  }
81
86
  }
82
87
 
83
88
  exports.BreakTokenizer = BreakTokenizer;
84
89
  exports.BreakTokenizerName = uniqueName;
85
- exports['default'] = BreakTokenizer;
90
+ exports["default"] = BreakTokenizer;
package/lib/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BreakType } from '@yozora/ast';
2
2
  import { VirtualCodePoint, AsciiCodePoint } from '@yozora/character';
3
- import { BaseInlineTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
3
+ import { BaseInlineTokenizer, TokenizerPriority, genFindDelimiter } from '@yozora/core-tokenizer';
4
4
 
5
5
  const uniqueName = '@yozora/tokenizer-break';
6
6
  var BreakTokenMarkerType;
@@ -16,63 +16,68 @@ class BreakTokenizer extends BaseInlineTokenizer {
16
16
  name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
17
17
  priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.SOFT_INLINE,
18
18
  });
19
- }
20
- _findDelimiter(startIndex, endIndex, api) {
21
- const nodePoints = api.getNodePoints();
22
- for (let i = startIndex + 1; i < endIndex; ++i) {
23
- if (nodePoints[i].codePoint !== VirtualCodePoint.LINE_END)
24
- continue;
25
- const c = nodePoints[i - 1].codePoint;
26
- let _start = null;
27
- let markerType = null;
28
- switch (c) {
29
- case AsciiCodePoint.BACKSLASH: {
30
- let x = i - 2;
31
- for (; x >= startIndex; x -= 1) {
32
- if (nodePoints[x].codePoint !== AsciiCodePoint.BACKSLASH)
19
+ this.match = api => {
20
+ return {
21
+ findDelimiter: () => genFindDelimiter(_findDelimiter),
22
+ processSingleDelimiter,
23
+ };
24
+ function _findDelimiter(startIndex, endIndex) {
25
+ const nodePoints = api.getNodePoints();
26
+ for (let i = startIndex + 1; i < endIndex; ++i) {
27
+ if (nodePoints[i].codePoint !== VirtualCodePoint.LINE_END)
28
+ continue;
29
+ const c = nodePoints[i - 1].codePoint;
30
+ let _start = null;
31
+ let markerType = null;
32
+ switch (c) {
33
+ case AsciiCodePoint.BACKSLASH: {
34
+ let x = i - 2;
35
+ for (; x >= startIndex; x -= 1) {
36
+ if (nodePoints[x].codePoint !== AsciiCodePoint.BACKSLASH)
37
+ break;
38
+ }
39
+ if (((i - x) & 1) === 0) {
40
+ _start = i - 1;
41
+ markerType = BreakTokenMarkerType.BACKSLASH;
42
+ }
33
43
  break;
34
- }
35
- if (((i - x) & 1) === 0) {
36
- _start = i - 1;
37
- markerType = BreakTokenMarkerType.BACKSLASH;
38
- }
39
- break;
40
- }
41
- case AsciiCodePoint.SPACE: {
42
- let x = i - 2;
43
- for (; x >= startIndex; x -= 1) {
44
- if (nodePoints[x].codePoint !== AsciiCodePoint.SPACE)
44
+ }
45
+ case AsciiCodePoint.SPACE: {
46
+ let x = i - 2;
47
+ for (; x >= startIndex; x -= 1) {
48
+ if (nodePoints[x].codePoint !== AsciiCodePoint.SPACE)
49
+ break;
50
+ }
51
+ if (i - x > 2) {
52
+ _start = x + 1;
53
+ markerType = BreakTokenMarkerType.MORE_THAN_TWO_SPACES;
54
+ }
45
55
  break;
56
+ }
46
57
  }
47
- if (i - x > 2) {
48
- _start = x + 1;
49
- markerType = BreakTokenMarkerType.MORE_THAN_TWO_SPACES;
50
- }
51
- break;
58
+ if (_start == null || markerType == null)
59
+ continue;
60
+ return {
61
+ type: 'full',
62
+ markerType,
63
+ startIndex: _start,
64
+ endIndex: i,
65
+ };
52
66
  }
67
+ return null;
68
+ }
69
+ function processSingleDelimiter(delimiter) {
70
+ const token = {
71
+ nodeType: BreakType,
72
+ startIndex: delimiter.startIndex,
73
+ endIndex: delimiter.endIndex,
74
+ };
75
+ return [token];
53
76
  }
54
- if (_start == null || markerType == null)
55
- continue;
56
- return {
57
- type: 'full',
58
- markerType,
59
- startIndex: _start,
60
- endIndex: i,
61
- };
62
- }
63
- return null;
64
- }
65
- processSingleDelimiter(delimiter) {
66
- const token = {
67
- nodeType: BreakType,
68
- startIndex: delimiter.startIndex,
69
- endIndex: delimiter.endIndex,
70
77
  };
71
- return [token];
72
- }
73
- parseInline() {
74
- const result = { type: BreakType };
75
- return result;
78
+ this.parse = () => ({
79
+ parse: () => ({ type: BreakType }),
80
+ });
76
81
  }
77
82
  }
78
83
 
@@ -1,5 +1,3 @@
1
- import { BreakTokenizer } from './tokenizer';
2
- export { BreakTokenizer } from './tokenizer';
1
+ export { BreakTokenizer, BreakTokenizer as default } from './tokenizer';
3
2
  export { uniqueName as BreakTokenizerName } from './types';
4
- export type { Token as BreakToken, TokenizerProps as BreakTokenizerProps, } from './types';
5
- export default BreakTokenizer;
3
+ export type { IToken as IBreakToken, ITokenizerProps as IBreakTokenizerProps } from './types';
@@ -1,6 +1,6 @@
1
- import type { MatchInlinePhaseApi, ResultOfProcessSingleDelimiter, Tokenizer, TokenizerMatchInlineHook, TokenizerParseInlineHook } from '@yozora/core-tokenizer';
1
+ import type { IInlineTokenizer, IMatchInlineHookCreator, IParseInlineHookCreator } from '@yozora/core-tokenizer';
2
2
  import { BaseInlineTokenizer } from '@yozora/core-tokenizer';
3
- import type { Delimiter, Node, T, Token, TokenizerProps } from './types';
3
+ import type { IDelimiter, INode, IToken, ITokenizerProps, T } from './types';
4
4
  /**
5
5
  * Lexical Analyzer for a line break.
6
6
  *
@@ -17,21 +17,8 @@ import type { Delimiter, Node, T, Token, TokenizerProps } from './types';
17
17
  *
18
18
  * @see https://github.com/syntax-tree/mdast#break
19
19
  */
20
- export declare class BreakTokenizer extends BaseInlineTokenizer<Delimiter> implements Tokenizer, TokenizerMatchInlineHook<T, Delimiter, Token>, TokenizerParseInlineHook<T, Token, Node> {
21
- constructor(props?: TokenizerProps);
22
- /**
23
- * @override
24
- * @see BaseInlineTokenizer
25
- */
26
- protected _findDelimiter(startIndex: number, endIndex: number, api: Readonly<MatchInlinePhaseApi>): Delimiter | null;
27
- /**
28
- * @override
29
- * @see TokenizerMatchInlineHook
30
- */
31
- processSingleDelimiter(delimiter: Delimiter): ResultOfProcessSingleDelimiter<T, Token>;
32
- /**
33
- * @override
34
- * @see TokenizerParseInlineHook
35
- */
36
- parseInline(): Node;
20
+ export declare class BreakTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode> implements IInlineTokenizer<T, IDelimiter, IToken, INode> {
21
+ constructor(props?: ITokenizerProps);
22
+ readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken>;
23
+ readonly parse: IParseInlineHookCreator<T, IToken, INode>;
37
24
  }
@@ -1,17 +1,17 @@
1
- import type { Break, BreakType } from '@yozora/ast';
2
- import type { BaseInlineTokenizerProps, PartialYastInlineToken, YastTokenDelimiter } from '@yozora/core-tokenizer';
1
+ import type { BreakType, IBreak } from '@yozora/ast';
2
+ import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, IYastTokenDelimiter } from '@yozora/core-tokenizer';
3
3
  export declare type T = BreakType;
4
- export declare type Node = Break;
4
+ export declare type INode = IBreak;
5
5
  export declare const uniqueName = "@yozora/tokenizer-break";
6
- export declare type Token = PartialYastInlineToken<T>;
7
- export interface Delimiter extends YastTokenDelimiter {
6
+ export declare type IToken = IPartialYastInlineToken<T>;
7
+ export interface IDelimiter extends IYastTokenDelimiter {
8
8
  type: 'full';
9
9
  /**
10
10
  * Line break marker type.
11
11
  */
12
12
  markerType: BreakTokenMarkerType;
13
13
  }
14
- export declare type TokenizerProps = Partial<BaseInlineTokenizerProps>;
14
+ export declare type ITokenizerProps = Partial<IBaseInlineTokenizerProps>;
15
15
  /**
16
16
  * Line break marker type.
17
17
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yozora/tokenizer-break",
3
- "version": "1.3.0",
3
+ "version": "2.0.0-alpha.0",
4
4
  "author": {
5
5
  "name": "guanghechen",
6
6
  "url": "https://github.com/guanghechen/"
@@ -35,9 +35,9 @@
35
35
  "test": "cross-env TS_NODE_FILES=true jest --config ../../jest.config.js --rootDir ."
36
36
  },
37
37
  "dependencies": {
38
- "@yozora/ast": "^1.3.0",
39
- "@yozora/character": "^1.3.0",
40
- "@yozora/core-tokenizer": "^1.3.0"
38
+ "@yozora/ast": "^2.0.0-alpha.0",
39
+ "@yozora/character": "^2.0.0-alpha.0",
40
+ "@yozora/core-tokenizer": "^2.0.0-alpha.0"
41
41
  },
42
- "gitHead": "18c9b167004ad97718b2f94f25139f80598cbf7a"
42
+ "gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
43
43
  }