@xaendar/compiler 0.0.4 → 0.1.6
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/package.json +21 -11
- package/xaendar-compiler.es.d.ts +199 -0
- package/xaendar-compiler.es.js +505 -0
- package/xaendar-compiler.es.js.map +1 -0
- package/src/costants/chars.constants.ts +0 -188
- package/src/costants/tags/base-tags.constants.ts +0 -106
- package/src/costants/tags/not-alllowed-tags.constants.ts +0 -13
- package/src/costants/tags/not-allowed-chars.constants.ts +0 -24
- package/src/lexer/lexer.ts +0 -91
- package/src/lexer/models/current-char.type.ts +0 -17
- package/src/lexer/models/current-position.type.ts +0 -13
- package/src/lexer/models/lexer-cursor.model.ts +0 -192
- package/src/lexer/models/lexer-state.enum.ts +0 -13
- package/src/lexer/models/token-type.enum.ts +0 -17
- package/src/lexer/models/token.type.ts +0 -62
- package/src/lexer/models/transition-function/transition-function-context.type.ts +0 -27
- package/src/lexer/models/transition-function/transition-function-return-type.type.ts +0 -48
- package/src/lexer/models/transition-function/transition-function.type.ts +0 -36
- package/src/lexer/states/attribute.state.ts +0 -47
- package/src/lexer/states/event.state.ts +0 -38
- package/src/lexer/states/interpolation-expression.state.ts +0 -68
- package/src/lexer/states/interpolation-literal.state.ts +0 -71
- package/src/lexer/states/interpolation.state.ts +0 -31
- package/src/lexer/states/tag-body.state.ts +0 -43
- package/src/lexer/states/tag-close.state.ts +0 -46
- package/src/lexer/states/tag-open-end.state.ts +0 -40
- package/src/lexer/states/tag-open-name.state.ts +0 -50
- package/src/lexer/states/text.state.ts +0 -61
- package/src/parser/models/ast.type.ts +0 -34
- package/src/parser/models/current-token.type.ts +0 -6
- package/src/parser/models/node.enum.ts +0 -5
- package/src/parser/models/parser-cursor.model.ts +0 -133
- package/src/parser/parser.ts +0 -225
- package/src/public-api.ts +0 -3
- package/src/render-generator/render-generator.model.ts +0 -73
- package/src/utils/chars.utils.ts +0 -70
- package/src/utils/tags.utils.ts +0 -36
- package/tsconfig.json +0 -3
- package/vite.config.ts +0 -4
package/package.json
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@xaendar/compiler",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@xaendar/compiler",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "A library containing compiler engine",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./xaendar-compiler.es.js",
|
|
7
|
+
"module": "./xaendar-compiler.es.js",
|
|
8
|
+
"types": "./xaendar-compiler.es.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./xaendar-compiler.es.d.ts",
|
|
13
|
+
"default": "./xaendar-compiler.es.js"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@xaendar/common": "0.1.6"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
declare type ASTNode = ElementNode | TextNode | InterpolationNode;
|
|
2
|
+
|
|
3
|
+
declare enum ASTNodeType {
|
|
4
|
+
Element = 0,
|
|
5
|
+
Text = 1,
|
|
6
|
+
Interpolation = 2
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare type AttributeNode = {
|
|
10
|
+
name: string;
|
|
11
|
+
value: string | InterpolationNode;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
declare type AttributeToken = {
|
|
15
|
+
type: TokenType.ATTRIBUTE;
|
|
16
|
+
parts: [string];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
declare type ElementNode = {
|
|
20
|
+
type: ASTNodeType.Element;
|
|
21
|
+
tagName: string;
|
|
22
|
+
attributes: AttributeNode[];
|
|
23
|
+
events: EventNode[];
|
|
24
|
+
children: ASTNode[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare type EOFToken = {
|
|
28
|
+
type: TokenType.EOF;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
declare type EventNode = {
|
|
32
|
+
name: string;
|
|
33
|
+
handler: string | InterpolationNode;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
declare type EventToken = {
|
|
37
|
+
type: TokenType.EVENT;
|
|
38
|
+
parts: [string];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Genera il codice TypeScript della funzione render
|
|
43
|
+
* @param ast L'albero AST del template
|
|
44
|
+
* @param componentVar Nome della variabile 'this' del componente (di solito `this`)
|
|
45
|
+
* @returns Stringa contenente il corpo della funzione render
|
|
46
|
+
*/
|
|
47
|
+
export declare function generateRenderFunction(ast: ASTNode[], componentVar?: string): string;
|
|
48
|
+
|
|
49
|
+
declare type InterpolationExpressionToken = {
|
|
50
|
+
type: TokenType.INTERPOLATION_EXPRESSION;
|
|
51
|
+
parts: [string];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
declare type InterpolationLiteralToken = {
|
|
55
|
+
type: TokenType.INTERPOLATION_LITERAL;
|
|
56
|
+
parts: [string];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
declare type InterpolationNode = {
|
|
60
|
+
type: ASTNodeType.Interpolation;
|
|
61
|
+
expression: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Utility class that emulates a cursor navigating through a template string.
|
|
66
|
+
*
|
|
67
|
+
* The cursor keeps track of the current character, its absolute position
|
|
68
|
+
* within the text, and its logical position expressed as row and column.
|
|
69
|
+
* This is useful when parsing or analyzing template content character by character.
|
|
70
|
+
*/
|
|
71
|
+
export declare class Lexer {
|
|
72
|
+
input: string;
|
|
73
|
+
private readonly _cursor;
|
|
74
|
+
private _state;
|
|
75
|
+
private _stack;
|
|
76
|
+
private readonly _tokens;
|
|
77
|
+
private readonly _states;
|
|
78
|
+
/**
|
|
79
|
+
* Creates a new Cursor instance for the given template content.
|
|
80
|
+
*
|
|
81
|
+
* @param input The full template text that the cursor will navigate.
|
|
82
|
+
*/
|
|
83
|
+
constructor(input: string);
|
|
84
|
+
tokenize(): Token[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Parser class that transforms a stream of tokens (from the Lexer)
|
|
89
|
+
* into an Abstract Syntax Tree (AST) representing the template structure.
|
|
90
|
+
*
|
|
91
|
+
* Responsibilities:
|
|
92
|
+
* - Parse text nodes, elements, attributes, events, and interpolations
|
|
93
|
+
* - Maintain cursor state for sequential token consumption
|
|
94
|
+
* - Detect tag boundaries and nested structures
|
|
95
|
+
*
|
|
96
|
+
* The parser assumes that the token stream is syntactically valid according
|
|
97
|
+
* to the Lexer rules. Parsing errors are thrown as exceptions.
|
|
98
|
+
*/
|
|
99
|
+
export declare class Parser {
|
|
100
|
+
private readonly tokens;
|
|
101
|
+
/** Internal cursor for navigating tokens */
|
|
102
|
+
private readonly _cursor;
|
|
103
|
+
/**
|
|
104
|
+
* Creates a new Parser instance.
|
|
105
|
+
*
|
|
106
|
+
* @param tokens Array of tokens produced by the Lexer
|
|
107
|
+
*/
|
|
108
|
+
constructor(tokens: Token[]);
|
|
109
|
+
/**
|
|
110
|
+
* Entry point for parsing the token stream into AST nodes.
|
|
111
|
+
*
|
|
112
|
+
* @returns Array of top-level AST nodes
|
|
113
|
+
*/
|
|
114
|
+
parse(): ASTNode[];
|
|
115
|
+
/**
|
|
116
|
+
* Parses the next AST node based on the current token.
|
|
117
|
+
*
|
|
118
|
+
* @returns Parsed AST node
|
|
119
|
+
* @throws Error if an unexpected token is encountered
|
|
120
|
+
*/
|
|
121
|
+
private parseNode;
|
|
122
|
+
/**
|
|
123
|
+
* Parses a text token into a TextNode.
|
|
124
|
+
*/
|
|
125
|
+
private parseText;
|
|
126
|
+
/**
|
|
127
|
+
* Parses an interpolation token into an InterpolationNode.
|
|
128
|
+
*/
|
|
129
|
+
private parseInterpolation;
|
|
130
|
+
/**
|
|
131
|
+
* Parses an element starting from a TAG_OPEN_NAME token.
|
|
132
|
+
* Handles attributes, events, children, and tag closure.
|
|
133
|
+
*/
|
|
134
|
+
private parseElement;
|
|
135
|
+
/**
|
|
136
|
+
* Parses an attribute token into an AttributeNode.
|
|
137
|
+
* Supports literal values and interpolations as attribute values.
|
|
138
|
+
*/
|
|
139
|
+
private parseAttribute;
|
|
140
|
+
/**
|
|
141
|
+
* Parses an event token into an EventNode.
|
|
142
|
+
*/
|
|
143
|
+
private parseEvent;
|
|
144
|
+
/**
|
|
145
|
+
* Checks whether the next token is a closing tag matching the given name.
|
|
146
|
+
*/
|
|
147
|
+
private isTagClose;
|
|
148
|
+
/**
|
|
149
|
+
* Creates a parser error with a consistent prefix.
|
|
150
|
+
*/
|
|
151
|
+
private error;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
declare type TagCloseNameToken = {
|
|
155
|
+
type: TokenType.TAG_CLOSE_NAME;
|
|
156
|
+
parts: [string];
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
declare type TagCloseToken = {
|
|
160
|
+
type: TokenType.TAG_OPEN_END;
|
|
161
|
+
parts: [];
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
declare type TagOpenNameToken = {
|
|
165
|
+
type: TokenType.TAG_OPEN_NAME;
|
|
166
|
+
parts: [string];
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
declare type TagSelfCloseToken = {
|
|
170
|
+
type: TokenType.TAG_SELF_CLOSE;
|
|
171
|
+
parts: [];
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
declare type TextNode = {
|
|
175
|
+
type: ASTNodeType.Text;
|
|
176
|
+
value: string;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
declare type TextToken = {
|
|
180
|
+
type: TokenType.TEXT;
|
|
181
|
+
parts: [string];
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
declare type Token = TagOpenNameToken | TagSelfCloseToken | TagCloseToken | TagCloseNameToken | AttributeToken | EventToken | TextToken | InterpolationExpressionToken | InterpolationLiteralToken | EOFToken;
|
|
185
|
+
|
|
186
|
+
declare enum TokenType {
|
|
187
|
+
TEXT = 0,
|
|
188
|
+
TAG_OPEN_NAME = 1,// <div
|
|
189
|
+
TAG_SELF_CLOSE = 2,// />
|
|
190
|
+
TAG_OPEN_END = 3,
|
|
191
|
+
TAG_CLOSE_NAME = 4,// </div
|
|
192
|
+
ATTRIBUTE = 5,
|
|
193
|
+
EVENT = 6,
|
|
194
|
+
INTERPOLATION_LITERAL = 7,
|
|
195
|
+
INTERPOLATION_EXPRESSION = 8,
|
|
196
|
+
EOF = 9
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export { }
|