bobe 0.0.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.
@@ -0,0 +1,138 @@
1
+ import { Queue } from '../../shared/util';
2
+ export declare enum TokenType {
3
+ NewLine = 0,
4
+ Indent = 1,
5
+ Dedent = 2,
6
+ Identifier = 3,
7
+ Assign = 4,
8
+ Pipe = 5,
9
+ Eof = 6
10
+ }
11
+ export type BaseType = string | number | boolean | undefined | null;
12
+ export type Token = {
13
+ type: TokenType;
14
+ typeName: string;
15
+ value: BaseType;
16
+ };
17
+ export type HookProps = {
18
+ /** 通过哪个 HookId 进入的 */
19
+ HookId: string;
20
+ /** 第几个 hook */
21
+ i: number;
22
+ /** 父节点 */
23
+ parentNode?: any;
24
+ };
25
+ export type Hook = (props: HookProps) => any;
26
+ export declare class Compiler {
27
+ i: number;
28
+ get char(): string;
29
+ get prev(): string;
30
+ get after(): string;
31
+ at(i: number): string;
32
+ next(): [prev: string, curr: string];
33
+ token: Token;
34
+ tokenIs: (...types: TokenType[]) => boolean;
35
+ isEof: () => boolean;
36
+ setToken: (type: TokenType, value: BaseType) => void;
37
+ TabSize: number;
38
+ Tab: string;
39
+ IdExp: RegExp;
40
+ EofId: string;
41
+ testId: (value: string) => boolean;
42
+ /** 记录历史缩进的长度,相对于行首 */
43
+ dentStack: number[];
44
+ needIndent: boolean;
45
+ isFirstToken: boolean;
46
+ /**
47
+ * 有些标识符能产生多个 token
48
+ * 例如 dedent
49
+ * parent1
50
+ * child
51
+ * subChild
52
+ * parent2 <- 产生两个 dedent
53
+ */
54
+ waitingTokens: Queue<Token>;
55
+ nextToken(): Token;
56
+ private consume;
57
+ tokenize(): void;
58
+ tokenCreator: {
59
+ assignment: () => void;
60
+ pipe: () => void;
61
+ dynamic: (char: string) => boolean;
62
+ newLine: () => void;
63
+ dent: () => boolean;
64
+ identifier: (char: string) => void;
65
+ str: (char: string) => void;
66
+ number: (char: string) => void;
67
+ eof: () => void;
68
+ };
69
+ HookId: string;
70
+ data: Record<any, any>;
71
+ code: string;
72
+ constructor();
73
+ preprocess(): void;
74
+ /**
75
+ * 根节点:
76
+ * 是 一个节点列表
77
+ * <program> ::= <nodeList>
78
+ */
79
+ program(): any[];
80
+ /**
81
+ * 节点列表:
82
+ * 可以是一个节点,也可以跟随更多节点
83
+ * <nodeList> ::= <node> <nodeList> <EOF|Dedent>
84
+ * |
85
+ */
86
+ nodeList(): any[];
87
+ /**
88
+ * 单个节点:
89
+ * 由声明部分和(可选的)子节点块组成
90
+ * <node> ::= <declaration> <childrenBlockOpt>
91
+ * */
92
+ node(): any;
93
+ /**
94
+ * 声明部分:
95
+ * 包含首行定义和(可选的)多行属性扩展
96
+ * <declaration> ::= <tagName=token> <headerLine> <extensionLines>
97
+ * */
98
+ declaration(): any;
99
+ /**
100
+ * <extensionLines> ::= PIPE <attributeList> NEWLINE <extensionLines>
101
+ * | ε
102
+ */
103
+ extensionLines(_node: any): void;
104
+ /**
105
+ * 首行:
106
+ * 节点名称 + 属性列表 + 换行
107
+ * <headerLine> ::= <attributeList> NEWLINE
108
+ */
109
+ headerLine(_node: any): void;
110
+ /**
111
+ * 属性列表:
112
+ * 可以是空的,或者包含多个属性
113
+ * <attributeList> ::= <attribute> <attributeList>
114
+ * | ε
115
+ *
116
+ * <attribute> ::= <key> <=> <value or dataKey> <=> <value>
117
+ */
118
+ attributeList(_node: any): void;
119
+ config(opt: Partial<Pick<Compiler, 'createNode' | 'setProp' | 'hook' | 'HookId'>>): void;
120
+ createData(data: Record<any, any>): Record<any, any>;
121
+ setDataProp(data: Record<any, any>, key: any, value: any): any;
122
+ createNode(name: string): {
123
+ name: string;
124
+ props: {};
125
+ };
126
+ setProp(node: any, key: string, value: any, hookI?: number): void;
127
+ init(fragments: string | string[]): void;
128
+ hook: Hook;
129
+ _hook: (props: Partial<HookProps>) => [boolean, any];
130
+ hookI: number;
131
+ /** 子节点块:
132
+ * 必须被缩进包裹
133
+ * <childrenBlockOpt> ::= INDENT <nodeList>
134
+ * | ε /* 空(表示叶子节点,没有孩子)
135
+ * */
136
+ childrenBlockOpt(): any[];
137
+ }
138
+ export declare function bobe(fragments: TemplateStringsArray, ...values: any[]): any;
@@ -0,0 +1,22 @@
1
+ type QueueItem<T> = {
2
+ v: T;
3
+ prev?: QueueItem<T>;
4
+ next?: QueueItem<T>;
5
+ };
6
+ export declare class Queue<T> {
7
+ _first?: QueueItem<T>;
8
+ get first(): T;
9
+ _last?: QueueItem<T>;
10
+ get last(): T;
11
+ len: number;
12
+ push(it: T): void;
13
+ shift(): T;
14
+ }
15
+ export declare function isNum(char: string): char is "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
16
+ export declare const genKey: (v: string | number) => number;
17
+ export declare class SortMap<T> {
18
+ data: Record<string | symbol, T[]>;
19
+ clear(): void;
20
+ add(key: string | symbol, value: T): void;
21
+ }
22
+ export {};
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "bobe",
3
+ "version": "0.0.3",
4
+ "main": "dist/bobe.cjs.js",
5
+ "module": "dist/bobe.esm.js",
6
+ "browser": "dist/bobe.umd.js",
7
+ "types": "dist/index.d.ts",
8
+ "devDependencies": {},
9
+ "scripts": {
10
+ "ini": "node scripts/init.js",
11
+ "build": "rm -rf ./dist && rollup -c",
12
+ "pub": "node scripts/publish.js",
13
+ "dev": "rollup -c -w",
14
+ "t": "jest",
15
+ "tw": "jest --coverage --watch"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "license": "MIT",
21
+ "keywords": [
22
+ "bobe",
23
+ "new-me",
24
+ "smooth",
25
+ "cat"
26
+ ],
27
+ "author": "smooth-cat",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+git@github.com:smooth-cat/bobe.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/smooth-cat/bobe/issues"
34
+ },
35
+ "homepage": "https://github.com/smooth-cat/bobe#readme",
36
+ "description": "a bobe template runtime compiler"
37
+ }