@yozora/tokenizer-delete 1.2.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
@@ -15,59 +15,68 @@ class DeleteTokenizer extends coreTokenizer.BaseInlineTokenizer {
15
15
  name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
16
16
  priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.CONTAINING_INLINE,
17
17
  });
18
- }
19
- _findDelimiter(startIndex, endIndex, nodePoints) {
20
- for (let i = startIndex; i < endIndex; ++i) {
21
- const c = nodePoints[i].codePoint;
22
- switch (c) {
23
- case character.AsciiCodePoint.BACKSLASH:
24
- i += 1;
25
- break;
26
- case character.AsciiCodePoint.TILDE: {
27
- const _startIndex = i;
28
- i = coreTokenizer.eatOptionalCharacters(nodePoints, i + 1, endIndex, c) - 1;
29
- if (i - _startIndex !== 1)
30
- break;
31
- let delimiterType = 'both';
32
- const preceding = _startIndex === startIndex ? null : nodePoints[_startIndex - 1];
33
- if (preceding != null && character.isWhitespaceCharacter(preceding.codePoint)) {
34
- delimiterType = 'opener';
35
- }
36
- const following = i + 1 === endIndex ? null : nodePoints[i + 1];
37
- if (following != null && character.isWhitespaceCharacter(following.codePoint)) {
38
- if (delimiterType !== 'both')
18
+ this.match = api => {
19
+ return {
20
+ findDelimiter: () => coreTokenizer.genFindDelimiter(_findDelimiter),
21
+ processDelimiterPair,
22
+ };
23
+ function _findDelimiter(startIndex, endIndex) {
24
+ const nodePoints = api.getNodePoints();
25
+ for (let i = startIndex; i < endIndex; ++i) {
26
+ const c = nodePoints[i].codePoint;
27
+ switch (c) {
28
+ case character.AsciiCodePoint.BACKSLASH:
29
+ i += 1;
39
30
  break;
40
- delimiterType = 'closer';
31
+ case character.AsciiCodePoint.TILDE: {
32
+ const _startIndex = i;
33
+ i = coreTokenizer.eatOptionalCharacters(nodePoints, i + 1, endIndex, c) - 1;
34
+ if (i - _startIndex !== 1)
35
+ break;
36
+ let delimiterType = 'both';
37
+ const preceding = _startIndex === startIndex ? null : nodePoints[_startIndex - 1];
38
+ if (preceding != null && character.isWhitespaceCharacter(preceding.codePoint)) {
39
+ delimiterType = 'opener';
40
+ }
41
+ const following = i + 1 === endIndex ? null : nodePoints[i + 1];
42
+ if (following != null && character.isWhitespaceCharacter(following.codePoint)) {
43
+ if (delimiterType !== 'both')
44
+ break;
45
+ delimiterType = 'closer';
46
+ }
47
+ return {
48
+ type: delimiterType,
49
+ startIndex: _startIndex,
50
+ endIndex: i + 1,
51
+ };
52
+ }
41
53
  }
42
- return {
43
- type: delimiterType,
44
- startIndex: _startIndex,
45
- endIndex: i + 1,
46
- };
47
54
  }
55
+ return null;
56
+ }
57
+ function processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
58
+ internalTokens = api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex);
59
+ const token = {
60
+ nodeType: ast.DeleteType,
61
+ startIndex: openerDelimiter.startIndex,
62
+ endIndex: closerDelimiter.endIndex,
63
+ children: internalTokens,
64
+ };
65
+ return { tokens: [token] };
48
66
  }
49
- }
50
- return null;
51
- }
52
- processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, nodePoints, api) {
53
- internalTokens = api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex, nodePoints);
54
- const token = {
55
- nodeType: ast.DeleteType,
56
- startIndex: openerDelimiter.startIndex,
57
- endIndex: closerDelimiter.endIndex,
58
- children: internalTokens,
59
- };
60
- return { tokens: [token] };
61
- }
62
- processToken(token, children) {
63
- const result = {
64
- type: ast.DeleteType,
65
- children: children !== null && children !== void 0 ? children : [],
66
67
  };
67
- return result;
68
+ this.parse = () => ({
69
+ parse: (token, children) => {
70
+ const result = {
71
+ type: ast.DeleteType,
72
+ children,
73
+ };
74
+ return result;
75
+ },
76
+ });
68
77
  }
69
78
  }
70
79
 
71
80
  exports.DeleteTokenizer = DeleteTokenizer;
72
81
  exports.DeleteTokenizerName = uniqueName;
73
- exports['default'] = DeleteTokenizer;
82
+ exports["default"] = DeleteTokenizer;
package/lib/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DeleteType } from '@yozora/ast';
2
2
  import { AsciiCodePoint, isWhitespaceCharacter } from '@yozora/character';
3
- import { BaseInlineTokenizer, TokenizerPriority, eatOptionalCharacters } from '@yozora/core-tokenizer';
3
+ import { BaseInlineTokenizer, TokenizerPriority, genFindDelimiter, eatOptionalCharacters } from '@yozora/core-tokenizer';
4
4
 
5
5
  const uniqueName = '@yozora/tokenizer-delete';
6
6
 
@@ -11,56 +11,65 @@ class DeleteTokenizer extends BaseInlineTokenizer {
11
11
  name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
12
12
  priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.CONTAINING_INLINE,
13
13
  });
14
- }
15
- _findDelimiter(startIndex, endIndex, nodePoints) {
16
- for (let i = startIndex; i < endIndex; ++i) {
17
- const c = nodePoints[i].codePoint;
18
- switch (c) {
19
- case AsciiCodePoint.BACKSLASH:
20
- i += 1;
21
- break;
22
- case AsciiCodePoint.TILDE: {
23
- const _startIndex = i;
24
- i = eatOptionalCharacters(nodePoints, i + 1, endIndex, c) - 1;
25
- if (i - _startIndex !== 1)
26
- break;
27
- let delimiterType = 'both';
28
- const preceding = _startIndex === startIndex ? null : nodePoints[_startIndex - 1];
29
- if (preceding != null && isWhitespaceCharacter(preceding.codePoint)) {
30
- delimiterType = 'opener';
31
- }
32
- const following = i + 1 === endIndex ? null : nodePoints[i + 1];
33
- if (following != null && isWhitespaceCharacter(following.codePoint)) {
34
- if (delimiterType !== 'both')
14
+ this.match = api => {
15
+ return {
16
+ findDelimiter: () => genFindDelimiter(_findDelimiter),
17
+ processDelimiterPair,
18
+ };
19
+ function _findDelimiter(startIndex, endIndex) {
20
+ const nodePoints = api.getNodePoints();
21
+ for (let i = startIndex; i < endIndex; ++i) {
22
+ const c = nodePoints[i].codePoint;
23
+ switch (c) {
24
+ case AsciiCodePoint.BACKSLASH:
25
+ i += 1;
35
26
  break;
36
- delimiterType = 'closer';
27
+ case AsciiCodePoint.TILDE: {
28
+ const _startIndex = i;
29
+ i = eatOptionalCharacters(nodePoints, i + 1, endIndex, c) - 1;
30
+ if (i - _startIndex !== 1)
31
+ break;
32
+ let delimiterType = 'both';
33
+ const preceding = _startIndex === startIndex ? null : nodePoints[_startIndex - 1];
34
+ if (preceding != null && isWhitespaceCharacter(preceding.codePoint)) {
35
+ delimiterType = 'opener';
36
+ }
37
+ const following = i + 1 === endIndex ? null : nodePoints[i + 1];
38
+ if (following != null && isWhitespaceCharacter(following.codePoint)) {
39
+ if (delimiterType !== 'both')
40
+ break;
41
+ delimiterType = 'closer';
42
+ }
43
+ return {
44
+ type: delimiterType,
45
+ startIndex: _startIndex,
46
+ endIndex: i + 1,
47
+ };
48
+ }
37
49
  }
38
- return {
39
- type: delimiterType,
40
- startIndex: _startIndex,
41
- endIndex: i + 1,
42
- };
43
50
  }
51
+ return null;
52
+ }
53
+ function processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
54
+ internalTokens = api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex);
55
+ const token = {
56
+ nodeType: DeleteType,
57
+ startIndex: openerDelimiter.startIndex,
58
+ endIndex: closerDelimiter.endIndex,
59
+ children: internalTokens,
60
+ };
61
+ return { tokens: [token] };
44
62
  }
45
- }
46
- return null;
47
- }
48
- processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, nodePoints, api) {
49
- internalTokens = api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex, nodePoints);
50
- const token = {
51
- nodeType: DeleteType,
52
- startIndex: openerDelimiter.startIndex,
53
- endIndex: closerDelimiter.endIndex,
54
- children: internalTokens,
55
- };
56
- return { tokens: [token] };
57
- }
58
- processToken(token, children) {
59
- const result = {
60
- type: DeleteType,
61
- children: children !== null && children !== void 0 ? children : [],
62
63
  };
63
- return result;
64
+ this.parse = () => ({
65
+ parse: (token, children) => {
66
+ const result = {
67
+ type: DeleteType,
68
+ children,
69
+ };
70
+ return result;
71
+ },
72
+ });
64
73
  }
65
74
  }
66
75
 
@@ -1,5 +1,3 @@
1
- import { DeleteTokenizer } from './tokenizer';
2
- export { DeleteTokenizer } from './tokenizer';
1
+ export { DeleteTokenizer, DeleteTokenizer as default } from './tokenizer';
3
2
  export { uniqueName as DeleteTokenizerName } from './types';
4
- export type { Token as DeleteToken, TokenizerProps as DeleteTokenizerProps, } from './types';
5
- export default DeleteTokenizer;
3
+ export type { IToken as IDeleteToken, ITokenizerProps as IDeleteTokenizerProps } from './types';
@@ -1,8 +1,6 @@
1
- import type { YastNode } from '@yozora/ast';
2
- import type { NodePoint } from '@yozora/character';
3
- import type { MatchInlinePhaseApi, ResultOfProcessDelimiterPair, Tokenizer, TokenizerMatchInlineHook, TokenizerParseInlineHook, YastInlineToken } from '@yozora/core-tokenizer';
1
+ import type { IInlineTokenizer, IMatchInlineHookCreator, IParseInlineHookCreator } from '@yozora/core-tokenizer';
4
2
  import { BaseInlineTokenizer } from '@yozora/core-tokenizer';
5
- import type { Delimiter, Node, T, Token, TokenizerProps } from './types';
3
+ import type { IDelimiter, INode, IToken, ITokenizerProps, T } from './types';
6
4
  /**
7
5
  * Lexical Analyzer for Delete.
8
6
  *
@@ -11,21 +9,8 @@ import type { Delimiter, Node, T, Token, TokenizerProps } from './types';
11
9
  * @see https://github.com/syntax-tree/mdast#delete
12
10
  * @see https://github.github.com/gfm/#strikethrough-extension-
13
11
  */
14
- export declare class DeleteTokenizer extends BaseInlineTokenizer<Delimiter> implements Tokenizer, TokenizerMatchInlineHook<T, Delimiter, Token>, TokenizerParseInlineHook<T, Token, Node> {
15
- constructor(props?: TokenizerProps);
16
- /**
17
- * @override
18
- * @see BaseInlineTokenizer
19
- */
20
- protected _findDelimiter(startIndex: number, endIndex: number, nodePoints: ReadonlyArray<NodePoint>): Delimiter | null;
21
- /**
22
- * @override
23
- * @see TokenizerMatchInlineHook
24
- */
25
- processDelimiterPair(openerDelimiter: Delimiter, closerDelimiter: Delimiter, internalTokens: ReadonlyArray<YastInlineToken>, nodePoints: ReadonlyArray<NodePoint>, api: Readonly<MatchInlinePhaseApi>): ResultOfProcessDelimiterPair<T, Token, Delimiter>;
26
- /**
27
- * @override
28
- * @see TokenizerParseInlineHook
29
- */
30
- processToken(token: Token, children?: YastNode[]): Node;
12
+ export declare class DeleteTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode> implements IInlineTokenizer<T, IDelimiter, IToken, INode> {
13
+ constructor(props?: ITokenizerProps);
14
+ readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken>;
15
+ readonly parse: IParseInlineHookCreator<T, IToken, INode>;
31
16
  }
@@ -1,8 +1,8 @@
1
- import type { Delete, DeleteType } from '@yozora/ast';
2
- import type { BaseInlineTokenizerProps, PartialYastInlineToken, YastTokenDelimiter } from '@yozora/core-tokenizer';
1
+ import type { DeleteType, IDelete } from '@yozora/ast';
2
+ import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, IYastTokenDelimiter } from '@yozora/core-tokenizer';
3
3
  export declare type T = DeleteType;
4
- export declare type Node = Delete;
4
+ export declare type INode = IDelete;
5
5
  export declare const uniqueName = "@yozora/tokenizer-delete";
6
- export declare type Token = PartialYastInlineToken<T>;
7
- export declare type Delimiter = YastTokenDelimiter;
8
- export declare type TokenizerProps = Partial<BaseInlineTokenizerProps>;
6
+ export declare type IToken = IPartialYastInlineToken<T>;
7
+ export declare type IDelimiter = IYastTokenDelimiter;
8
+ export declare type ITokenizerProps = Partial<IBaseInlineTokenizerProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yozora/tokenizer-delete",
3
- "version": "1.2.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.2.0",
39
- "@yozora/character": "^1.2.0",
40
- "@yozora/core-tokenizer": "^1.2.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": "86da40e50d2fe9acace68695288e15e012e6cd0d"
42
+ "gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
43
43
  }