lisette-stdlib 0.1.13

Little language inspired by Rust that compiles to Go
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
// Generated by Lisette bindgen
// Source: text/template/parse (Go stdlib)
// Go: 1.25.5
// Lisette: 0.1.12

pub enum NodeType: int {
  NodeAction = 1,
  NodeBool = 2,
  NodeBreak = 21,
  NodeChain = 3,
  NodeCommand = 4,
  NodeComment = 20,
  NodeContinue = 22,
  NodeDot = 5,
  NodeField = 8,
  NodeIdentifier = 9,
  NodeIf = 10,
  NodeList = 11,
  NodeNil = 12,
  NodeNumber = 13,
  NodePipe = 14,
  NodeRange = 15,
  NodeString = 16,
  NodeTemplate = 17,
  NodeText = 0,
  NodeVariable = 18,
  NodeWith = 19,
}

pub const NodeAction: NodeType = 1

pub const NodeBool: NodeType = 2

pub const NodeBreak: NodeType = 21

pub const NodeChain: NodeType = 3

pub const NodeCommand: NodeType = 4

pub const NodeComment: NodeType = 20

pub const NodeContinue: NodeType = 22

pub const NodeDot: NodeType = 5

pub const NodeField: NodeType = 8

pub const NodeIdentifier: NodeType = 9

pub const NodeIf: NodeType = 10

pub const NodeList: NodeType = 11

pub const NodeNil: NodeType = 12

pub const NodeNumber: NodeType = 13

pub const NodePipe: NodeType = 14

pub const NodeRange: NodeType = 15

pub const NodeString: NodeType = 16

pub const NodeTemplate: NodeType = 17

pub const NodeText: NodeType = 0

pub const NodeVariable: NodeType = 18

pub const NodeWith: NodeType = 19

/// IsEmptyTree reports whether this tree (node) is empty of everything but space or comments.
pub fn IsEmptyTree(n: Node) -> bool

pub fn New(name: string, funcs: VarArgs<Map<string, Unknown>>) -> Ref<Tree>

pub fn NewIdentifier(ident: string) -> Ref<IdentifierNode>

/// Parse returns a map from template name to [Tree], created by parsing the
/// templates described in the argument string. The top-level template will be
/// given the specified name. If an error is encountered, parsing stops and an
/// empty map is returned with the error.
pub fn Parse(
  name: string,
  text: string,
  leftDelim: string,
  rightDelim: string,
  funcs: VarArgs<Map<string, Unknown>>,
) -> Result<Map<string, Ref<Tree>>, error>

/// ActionNode holds an action (something bounded by delimiters).
/// Control actions have their own nodes; ActionNode represents simple
/// ones such as field evaluations and parenthesized pipelines.
pub struct ActionNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Line: int,
  pub Pipe: Option<Ref<PipeNode>>,
}

/// BoolNode holds a boolean constant.
pub struct BoolNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub True: bool,
}

/// BranchNode is the common representation of if, range, and with.
pub struct BranchNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Line: int,
  pub Pipe: Option<Ref<PipeNode>>,
  pub List: Option<Ref<ListNode>>,
  pub ElseList: Option<Ref<ListNode>>,
}

/// BreakNode represents a {{break}} action.
pub struct BreakNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Line: int,
}

/// ChainNode holds a term followed by a chain of field accesses (identifier starting with '.').
/// The names may be chained ('.x.y').
/// The periods are dropped from each ident.
pub struct ChainNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Node: Option<Node>,
  pub Field: Slice<string>,
}

/// CommandNode holds a command (a pipeline inside an evaluating action).
pub struct CommandNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Args: Slice<Option<Node>>,
}

/// CommentNode holds a comment.
pub struct CommentNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Text: string,
}

/// ContinueNode represents a {{continue}} action.
pub struct ContinueNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Line: int,
}

/// DotNode holds the special identifier '.'.
pub struct DotNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
}

/// FieldNode holds a field (identifier starting with '.').
/// The names may be chained ('.x.y').
/// The period is dropped from each ident.
pub struct FieldNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Ident: Slice<string>,
}

/// IdentifierNode holds an identifier.
pub struct IdentifierNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Ident: string,
}

/// IfNode represents an {{if}} action and its commands.
pub struct IfNode {
  pub BranchNode: BranchNode,
}

/// ListNode holds a sequence of nodes.
pub struct ListNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Nodes: Slice<Option<Node>>,
}

/// A mode value is a set of flags (or 0). Modes control parser behavior.
pub struct Mode(uint)

/// NilNode holds the special identifier 'nil' representing an untyped nil constant.
pub struct NilNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
}

/// A Node is an element in the parse tree. The interface is trivial.
/// The interface contains an unexported method so that only
/// types local to this package can satisfy it.
pub interface Node {
  fn Copy() -> Node
  fn Position() -> Pos
  fn String() -> string
  fn Type() -> NodeType
}

/// NumberNode holds a number: signed or unsigned integer, float, or complex.
/// The value is parsed and stored under all the types that can represent the value.
/// This simulates in a small amount of code the behavior of Go's ideal constants.
pub struct NumberNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub IsInt: bool,
  pub IsUint: bool,
  pub IsFloat: bool,
  pub IsComplex: bool,
  pub Int64: int64,
  pub Uint64: uint64,
  pub Float64: float64,
  pub Complex128: complex128,
  pub Text: string,
}

/// PipeNode holds a pipeline with optional declaration
pub struct PipeNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Line: int,
  pub IsAssign: bool,
  pub Decl: Slice<Option<Ref<VariableNode>>>,
  pub Cmds: Slice<Option<Ref<CommandNode>>>,
}

/// Pos represents a byte position in the original input text from which
/// this template was parsed.
pub struct Pos(int)

/// RangeNode represents a {{range}} action and its commands.
pub struct RangeNode {
  pub BranchNode: BranchNode,
}

/// StringNode holds a string constant. The value has been "unquoted".
pub struct StringNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Quoted: string,
  pub Text: string,
}

/// TemplateNode represents a {{template}} action.
pub struct TemplateNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Line: int,
  pub Name: string,
  pub Pipe: Option<Ref<PipeNode>>,
}

/// TextNode holds plain text.
pub struct TextNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Text: Slice<uint8>,
}

/// Tree is the representation of a single parsed template.
pub struct Tree {
  pub Name: string,
  pub ParseName: string,
  pub Root: Option<Ref<ListNode>>,
  pub Mode: Mode,
}

/// VariableNode holds a list of variable names, possibly with chained field
/// accesses. The dollar sign is part of the (first) name.
pub struct VariableNode {
  pub NodeType: NodeType,
  pub Pos: Pos,
  pub Ident: Slice<string>,
}

/// WithNode represents a {{with}} action and its commands.
pub struct WithNode {
  pub BranchNode: BranchNode,
}

const ParseComments: Mode = 1

const SkipFuncCheck: Mode = 2

impl ActionNode {
  fn Copy(self: Ref<ActionNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<ActionNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl BoolNode {
  fn Copy(self: Ref<BoolNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<BoolNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl BranchNode {
  fn Copy(self: Ref<BranchNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<BranchNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl BreakNode {
  fn Copy(self: Ref<BreakNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<BreakNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl ChainNode {
  /// Add adds the named field (which should start with a period) to the end of the chain.
  fn Add(self: Ref<ChainNode>, field: string)

  fn Copy(self: Ref<ChainNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<ChainNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl CommandNode {
  fn Copy(self: Ref<CommandNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<CommandNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl CommentNode {
  fn Copy(self: Ref<CommentNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<CommentNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl ContinueNode {
  fn Copy(self: Ref<ContinueNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<ContinueNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl DotNode {
  fn Copy(self: Ref<DotNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<DotNode>) -> string

  fn Type(self: Ref<DotNode>) -> NodeType
}

impl FieldNode {
  fn Copy(self: Ref<FieldNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<FieldNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl IdentifierNode {
  fn Copy(self: Ref<IdentifierNode>) -> Node

  fn Position(self) -> Pos

  /// SetPos sets the position. [NewIdentifier] is a public method so we can't modify its signature.
  /// Chained for convenience.
  /// TODO: fix one day?
  fn SetPos(self: Ref<IdentifierNode>, pos: Pos) -> Ref<IdentifierNode>

  /// SetTree sets the parent tree for the node. [NewIdentifier] is a public method so we can't modify its signature.
  /// Chained for convenience.
  /// TODO: fix one day?
  fn SetTree(self: Ref<IdentifierNode>, t: Ref<Tree>) -> Ref<IdentifierNode>

  fn String(self: Ref<IdentifierNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl IfNode {
  fn Copy(self: Ref<IfNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<IfNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl ListNode {
  fn Copy(self: Ref<ListNode>) -> Node

  fn CopyList(self: Ref<ListNode>) -> Ref<ListNode>

  fn Position(self) -> Pos

  fn String(self: Ref<ListNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl NilNode {
  fn Copy(self: Ref<NilNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<NilNode>) -> string

  fn Type(self: Ref<NilNode>) -> NodeType
}

impl NodeType {
  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl NumberNode {
  fn Copy(self: Ref<NumberNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<NumberNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl PipeNode {
  fn Copy(self: Ref<PipeNode>) -> Node

  fn CopyPipe(self: Ref<PipeNode>) -> Ref<PipeNode>

  fn Position(self) -> Pos

  fn String(self: Ref<PipeNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl Pos {
  fn Position(self) -> Pos
}

impl RangeNode {
  fn Copy(self: Ref<RangeNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<RangeNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl StringNode {
  fn Copy(self: Ref<StringNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<StringNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl TemplateNode {
  fn Copy(self: Ref<TemplateNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<TemplateNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl TextNode {
  fn Copy(self: Ref<TextNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<TextNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl Tree {
  /// Copy returns a copy of the [Tree]. Any parsing state is discarded.
  fn Copy(self: Ref<Tree>) -> Ref<Tree>

  /// ErrorContext returns a textual representation of the location of the node in the input text.
  /// The receiver is only used when the node does not have a pointer to the tree inside,
  /// which can occur in old code.
  fn ErrorContext(self: Ref<Tree>, n: Node) -> (string, string)

  /// Parse parses the template definition string to construct a representation of
  /// the template for execution. If either action delimiter string is empty, the
  /// default ("{{" or "}}") is used. Embedded template definitions are added to
  /// the treeSet map.
  fn Parse(
    self: Ref<Tree>,
    text: string,
    leftDelim: string,
    rightDelim: string,
    treeSet: Map<string, Ref<Tree>>,
    funcs: VarArgs<Map<string, Unknown>>,
  ) -> Result<Ref<Tree>, error>
}

impl VariableNode {
  fn Copy(self: Ref<VariableNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<VariableNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}

impl WithNode {
  fn Copy(self: Ref<WithNode>) -> Node

  fn Position(self) -> Pos

  fn String(self: Ref<WithNode>) -> string

  /// Type returns itself and provides an easy default implementation
  /// for embedding in a Node. Embedded in all non-trivial Nodes.
  fn Type(self) -> NodeType
}