@nova-lang/cli 0.1.1 → 0.2.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/src/types.zig DELETED
@@ -1,235 +0,0 @@
1
- const std = @import("std");
2
-
3
- pub const TokenType = enum {
4
- command,
5
- ident,
6
- lparen,
7
- rparen,
8
- lbrace,
9
- rbrace,
10
- lbracket,
11
- rbracket,
12
- colon,
13
- comma,
14
- dash,
15
- star,
16
- plus,
17
- pipe,
18
- string,
19
- number,
20
- bool,
21
- null,
22
- text,
23
- indent,
24
- dedent,
25
- newline,
26
- math_inline,
27
- math_display,
28
- interp_start,
29
- interp_end,
30
- at,
31
- equals,
32
- dot,
33
- hash,
34
- question,
35
- lt,
36
- gt,
37
- eof,
38
- };
39
-
40
- pub const Token = struct {
41
- type: TokenType,
42
- value: []const u8 = "",
43
- line: u32 = 0,
44
- col: u32 = 0,
45
- };
46
-
47
- pub const Node = struct {
48
- tag: Tag,
49
- data: Data,
50
-
51
- pub const Tag = enum {
52
- document,
53
- text,
54
- math_inline,
55
- math_display,
56
- interpolation,
57
- block,
58
- inline_block,
59
- list_block,
60
- table_block,
61
- macro_def,
62
- field_def,
63
- schema_def,
64
- method_def,
65
- service_def,
66
- biblio_entry,
67
- if_block,
68
- for_block,
69
- use_block,
70
- meta_block,
71
- };
72
-
73
- pub const Data = union {
74
- document: Document,
75
- text: Text,
76
- math_inline: MathInline,
77
- math_display: MathDisplay,
78
- interpolation: Interpolation,
79
- block: Block,
80
- inline_block: InlineBlock,
81
- list_block: ListBlock,
82
- table_block: TableBlock,
83
- macro_def: MacroDef,
84
- field_def: FieldDef,
85
- schema_def: SchemaDef,
86
- method_def: MethodDef,
87
- service_def: ServiceDef,
88
- biblio_entry: BiblioEntry,
89
- if_block: IfBlock,
90
- for_block: ForBlock,
91
- use_block: UseBlock,
92
- meta_block: MetaBlock,
93
- };
94
-
95
- pub fn init(tag: Tag, data: Data) Node {
96
- return .{ .tag = tag, .data = data };
97
- }
98
- };
99
-
100
- pub const Text = struct {
101
- value: []const u8,
102
- };
103
-
104
- pub const MathInline = struct {
105
- source: []const u8,
106
- };
107
-
108
- pub const MathDisplay = struct {
109
- source: []const u8,
110
- };
111
-
112
- pub const Interpolation = struct {
113
- expression: []const u8,
114
- };
115
-
116
- pub const Block = struct {
117
- name: []const u8,
118
- attrs: std.StringHashMap([]const u8),
119
- inline_content: std.ArrayList(Node),
120
- children: std.ArrayList(Node),
121
- };
122
-
123
- pub const InlineBlock = struct {
124
- name: []const u8,
125
- attrs: std.StringHashMap([]const u8),
126
- content: std.ArrayList(Node),
127
- };
128
-
129
- pub const ListBlock = struct {
130
- ordered: bool,
131
- items: std.ArrayList(Node),
132
- };
133
-
134
- pub const TableBlock = struct {
135
- headers: ?std.ArrayList([]const u8),
136
- rows: std.ArrayList(std.ArrayList([]const u8)),
137
- src: ?[]const u8,
138
- caption: ?[]const u8,
139
- data: ?std.ArrayList(std.ArrayList([]const u8)),
140
- };
141
-
142
- pub const MacroDef = struct {
143
- name: []const u8,
144
- params: std.ArrayList([]const u8),
145
- kwargs: std.StringHashMap([]const u8),
146
- has_block_param: bool,
147
- block_param_name: []const u8,
148
- body: std.ArrayList(Node),
149
- };
150
-
151
- pub const FieldDef = struct {
152
- name: []const u8,
153
- type_name: []const u8,
154
- tag: u32,
155
- optional: bool,
156
- default: ?[]const u8,
157
- };
158
-
159
- pub const SchemaDef = struct {
160
- name: []const u8,
161
- fields: std.ArrayList(FieldDef),
162
- };
163
-
164
- pub const MethodDef = struct {
165
- name: []const u8,
166
- params: std.ArrayList(struct { name: []const u8, type_name: []const u8 }),
167
- returns: ?[]const u8,
168
- };
169
-
170
- pub const ServiceDef = struct {
171
- name: []const u8,
172
- methods: std.ArrayList(MethodDef),
173
- };
174
-
175
- pub const BiblioEntry = struct {
176
- key: []const u8,
177
- attrs: std.StringHashMap([]const u8),
178
- };
179
-
180
- pub const IfBlock = struct {
181
- condition: []const u8,
182
- then_body: std.ArrayList(Node),
183
- else_body: std.ArrayList(Node),
184
- };
185
-
186
- pub const ForBlock = struct {
187
- var_name: []const u8,
188
- iterable: []const u8,
189
- body: std.ArrayList(Node),
190
- };
191
-
192
- pub const UseBlock = struct {
193
- path: []const u8,
194
- };
195
-
196
- pub const MetaBlock = struct {
197
- pairs: std.StringHashMap([]const u8),
198
- };
199
-
200
- pub const Document = struct {
201
- children: std.ArrayList(Node),
202
- meta: std.StringHashMap([]const u8),
203
- };
204
-
205
- pub const AstPool = struct {
206
- allocator: std.mem.Allocator,
207
- nodes: std.ArrayList(Node),
208
- string_pool: std.ArrayList([]const u8),
209
-
210
- pub fn init(allocator: std.mem.Allocator) AstPool {
211
- return .{
212
- .allocator = allocator,
213
- .nodes = std.ArrayList(Node).init(allocator),
214
- .string_pool = std.ArrayList([]const u8).init(allocator),
215
- };
216
- }
217
-
218
- pub fn deinit(self: *AstPool) void {
219
- self.nodes.deinit();
220
- self.string_pool.deinit();
221
- }
222
-
223
- pub fn dupString(self: *AstPool, s: []const u8) ![]const u8 {
224
- const copy = try self.allocator.alloc(u8, s.len);
225
- @memcpy(copy, s);
226
- try self.string_pool.append(copy);
227
- return copy;
228
- }
229
-
230
- pub fn allocNode(self: *AstPool, node: Node) !*Node {
231
- const ptr = try self.allocator.create(Node);
232
- ptr.* = node;
233
- return ptr;
234
- }
235
- };