@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 +57 -52
- package/lib/esm/index.js +57 -52
- package/lib/types/index.d.ts +2 -4
- package/lib/types/tokenizer.d.ts +6 -19
- package/lib/types/types.d.ts +6 -6
- package/package.json +5 -5
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
let
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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 (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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[
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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 (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const result = { type: BreakType };
|
|
75
|
-
return result;
|
|
78
|
+
this.parse = () => ({
|
|
79
|
+
parse: () => ({ type: BreakType }),
|
|
80
|
+
});
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export { BreakTokenizer } from './tokenizer';
|
|
1
|
+
export { BreakTokenizer, BreakTokenizer as default } from './tokenizer';
|
|
3
2
|
export { uniqueName as BreakTokenizerName } from './types';
|
|
4
|
-
export type {
|
|
5
|
-
export default BreakTokenizer;
|
|
3
|
+
export type { IToken as IBreakToken, ITokenizerProps as IBreakTokenizerProps } from './types';
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IInlineTokenizer, IMatchInlineHookCreator, IParseInlineHookCreator } from '@yozora/core-tokenizer';
|
|
2
2
|
import { BaseInlineTokenizer } from '@yozora/core-tokenizer';
|
|
3
|
-
import type {
|
|
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<
|
|
21
|
-
constructor(props?:
|
|
22
|
-
|
|
23
|
-
|
|
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
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
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
|
|
4
|
+
export declare type INode = IBreak;
|
|
5
5
|
export declare const uniqueName = "@yozora/tokenizer-break";
|
|
6
|
-
export declare type
|
|
7
|
-
export interface
|
|
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
|
|
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": "
|
|
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": "^
|
|
39
|
-
"@yozora/character": "^
|
|
40
|
-
"@yozora/core-tokenizer": "^
|
|
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": "
|
|
42
|
+
"gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
|
|
43
43
|
}
|