lisette-stdlib 0.2.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
// Generated by Lisette bindgen
// Source: go/token (Go stdlib)
// Go: 1.25.10
// Lisette: 0.2.1

pub enum Token: int {
  ADD = 12,
  ADD_ASSIGN = 23,
  AND = 17,
  AND_ASSIGN = 28,
  AND_NOT = 22,
  AND_NOT_ASSIGN = 33,
  ARROW = 36,
  ASSIGN = 42,
  BREAK = 61,
  CASE = 62,
  CHAN = 63,
  CHAR = 8,
  COLON = 58,
  COMMA = 52,
  COMMENT = 2,
  CONST = 64,
  CONTINUE = 65,
  DEC = 38,
  DEFAULT = 66,
  DEFER = 67,
  DEFINE = 47,
  ELLIPSIS = 48,
  ELSE = 68,
  EOF = 1,
  EQL = 39,
  FALLTHROUGH = 69,
  FLOAT = 6,
  FOR = 70,
  FUNC = 71,
  GEQ = 46,
  GO = 72,
  GOTO = 73,
  GTR = 41,
  IDENT = 4,
  IF = 74,
  ILLEGAL = 0,
  IMAG = 7,
  IMPORT = 75,
  INC = 37,
  INT = 5,
  INTERFACE = 76,
  LAND = 34,
  LBRACE = 51,
  LBRACK = 50,
  LEQ = 45,
  LOR = 35,
  LPAREN = 49,
  LSS = 40,
  MAP = 77,
  MUL = 14,
  MUL_ASSIGN = 25,
  NEQ = 44,
  NOT = 43,
  OR = 18,
  OR_ASSIGN = 29,
  PACKAGE = 78,
  PERIOD = 53,
  QUO = 15,
  QUO_ASSIGN = 26,
  RANGE = 79,
  RBRACE = 56,
  RBRACK = 55,
  REM = 16,
  REM_ASSIGN = 27,
  RETURN = 80,
  RPAREN = 54,
  SELECT = 81,
  SEMICOLON = 57,
  SHL = 20,
  SHL_ASSIGN = 31,
  SHR = 21,
  SHR_ASSIGN = 32,
  STRING = 9,
  STRUCT = 82,
  SUB = 13,
  SUB_ASSIGN = 24,
  SWITCH = 83,
  TILDE = 88,
  TYPE = 84,
  VAR = 85,
  XOR = 19,
  XOR_ASSIGN = 30,
}

pub const ADD: Token = 12

pub const ADD_ASSIGN: Token = 23

pub const AND: Token = 17

pub const AND_ASSIGN: Token = 28

pub const AND_NOT: Token = 22

pub const AND_NOT_ASSIGN: Token = 33

pub const ARROW: Token = 36

pub const ASSIGN: Token = 42

pub const BREAK: Token = 61

pub const CASE: Token = 62

pub const CHAN: Token = 63

pub const CHAR: Token = 8

pub const COLON: Token = 58

pub const COMMA: Token = 52

pub const COMMENT: Token = 2

pub const CONST: Token = 64

pub const CONTINUE: Token = 65

pub const DEC: Token = 38

pub const DEFAULT: Token = 66

pub const DEFER: Token = 67

pub const DEFINE: Token = 47

pub const ELLIPSIS: Token = 48

pub const ELSE: Token = 68

pub const EOF: Token = 1

pub const EQL: Token = 39

pub const FALLTHROUGH: Token = 69

pub const FLOAT: Token = 6

pub const FOR: Token = 70

pub const FUNC: Token = 71

pub const GEQ: Token = 46

pub const GO: Token = 72

pub const GOTO: Token = 73

pub const GTR: Token = 41

pub const IDENT: Token = 4

pub const IF: Token = 74

pub const ILLEGAL: Token = 0

pub const IMAG: Token = 7

pub const IMPORT: Token = 75

pub const INC: Token = 37

pub const INT: Token = 5

pub const INTERFACE: Token = 76

pub const LAND: Token = 34

pub const LBRACE: Token = 51

pub const LBRACK: Token = 50

pub const LEQ: Token = 45

pub const LOR: Token = 35

pub const LPAREN: Token = 49

pub const LSS: Token = 40

pub const MAP: Token = 77

pub const MUL: Token = 14

pub const MUL_ASSIGN: Token = 25

pub const NEQ: Token = 44

pub const NOT: Token = 43

pub const OR: Token = 18

pub const OR_ASSIGN: Token = 29

pub const PACKAGE: Token = 78

pub const PERIOD: Token = 53

pub const QUO: Token = 15

pub const QUO_ASSIGN: Token = 26

pub const RANGE: Token = 79

pub const RBRACE: Token = 56

pub const RBRACK: Token = 55

pub const REM: Token = 16

pub const REM_ASSIGN: Token = 27

pub const RETURN: Token = 80

pub const RPAREN: Token = 54

pub const SELECT: Token = 81

pub const SEMICOLON: Token = 57

pub const SHL: Token = 20

pub const SHL_ASSIGN: Token = 31

pub const SHR: Token = 21

pub const SHR_ASSIGN: Token = 32

pub const STRING: Token = 9

pub const STRUCT: Token = 82

pub const SUB: Token = 13

pub const SUB_ASSIGN: Token = 24

pub const SWITCH: Token = 83

pub const TILDE: Token = 88

pub const TYPE: Token = 84

pub const VAR: Token = 85

pub const XOR: Token = 19

pub const XOR_ASSIGN: Token = 30

/// IsExported reports whether name starts with an upper-case letter.
pub fn IsExported(name: string) -> bool

/// IsIdentifier reports whether name is a Go identifier, that is, a non-empty
/// string made up of letters, digits, and underscores, where the first character
/// is not a digit. Keywords are not identifiers.
pub fn IsIdentifier(name: string) -> bool

/// IsKeyword reports whether name is a Go keyword, such as "func" or "return".
pub fn IsKeyword(name: string) -> bool

/// Lookup maps an identifier to its keyword token or [IDENT] (if not a keyword).
pub fn Lookup(ident: string) -> Token

/// NewFileSet creates a new file set.
pub fn NewFileSet() -> Ref<FileSet>

/// A File is a handle for a file belonging to a [FileSet].
/// A File has a name, size, and line offset table.
/// 
/// Use [FileSet.AddFile] to create a File.
/// A File may belong to more than one FileSet; see [FileSet.AddExistingFiles].
pub type File

/// A FileSet represents a set of source files.
/// Methods of file sets are synchronized; multiple goroutines
/// may invoke them concurrently.
/// 
/// The byte offsets for each file in a file set are mapped into
/// distinct (integer) intervals, one interval [base, base+size]
/// per file. [FileSet.Base] represents the first byte in the file, and size
/// is the corresponding file size. A [Pos] value is a value in such
/// an interval. By determining the interval a [Pos] value belongs
/// to, the file, its file base, and thus the byte offset (position)
/// the [Pos] value is representing can be computed.
/// 
/// When adding a new file, a file base must be provided. That can
/// be any integer value that is past the end of any interval of any
/// file already in the file set. For convenience, [FileSet.Base] provides
/// such a value, which is simply the end of the Pos interval of the most
/// recently added file, plus one. Unless there is a need to extend an
/// interval later, using the [FileSet.Base] should be used as argument
/// for [FileSet.AddFile].
/// 
/// A [File] may be removed from a FileSet when it is no longer needed.
/// This may reduce memory usage in a long-running application.
pub type FileSet

/// Pos is a compact encoding of a source position within a file set.
/// It can be converted into a [Position] for a more convenient, but much
/// larger, representation.
/// 
/// The Pos value for a given file is a number in the range [base, base+size],
/// where base and size are specified when a file is added to the file set.
/// The difference between a Pos value and the corresponding file base
/// corresponds to the byte offset of that position (represented by the Pos value)
/// from the beginning of the file. Thus, the file base offset is the Pos value
/// representing the first byte in the file.
/// 
/// To create the Pos value for a specific source offset (measured in bytes),
/// first add the respective file to the current file set using [FileSet.AddFile]
/// and then call [File.Pos](offset) for that file. Given a Pos value p
/// for a specific file set fset, the corresponding [Position] value is
/// obtained by calling fset.Position(p).
/// 
/// Pos values can be compared directly with the usual comparison operators:
/// If two Pos values p and q are in the same file, comparing p and q is
/// equivalent to comparing the respective source file offsets. If p and q
/// are in different files, p < q is true if the file implied by p was added
/// to the respective file set before the file implied by q.
pub struct Pos(int)

/// Position describes an arbitrary source position
/// including the file, line, and column location.
/// A Position is valid if the line number is > 0.
pub struct Position {
  pub Filename: string,
  pub Offset: int,
  pub Line: int,
  pub Column: int,
}

/// A set of constants for precedence-based expression parsing.
/// Non-operators have lowest precedence, followed by operators
/// starting with precedence 1 up to unary operators. The highest
/// precedence serves as "catch-all" precedence for selector,
/// indexing, and other operator and delimiter tokens.
pub const HighestPrec = 7

/// A set of constants for precedence-based expression parsing.
/// Non-operators have lowest precedence, followed by operators
/// starting with precedence 1 up to unary operators. The highest
/// precedence serves as "catch-all" precedence for selector,
/// indexing, and other operator and delimiter tokens.
pub const LowestPrec = 0

pub const NoPos: Pos = 0

/// A set of constants for precedence-based expression parsing.
/// Non-operators have lowest precedence, followed by operators
/// starting with precedence 1 up to unary operators. The highest
/// precedence serves as "catch-all" precedence for selector,
/// indexing, and other operator and delimiter tokens.
pub const UnaryPrec = 6

impl File {
  /// AddLine adds the line offset for a new line.
  /// The line offset must be larger than the offset for the previous line
  /// and smaller than the file size; otherwise the line offset is ignored.
  fn AddLine(self: Ref<File>, offset: int)

  /// AddLineColumnInfo adds alternative file, line, and column number
  /// information for a given file offset. The offset must be larger
  /// than the offset for the previously added alternative line info
  /// and smaller than the file size; otherwise the information is
  /// ignored.
  /// 
  /// AddLineColumnInfo is typically used to register alternative position
  /// information for line directives such as //line filename:line:column.
  fn AddLineColumnInfo(
    self: Ref<File>,
    offset: int,
    filename: string,
    line: int,
    column: int,
  )

  /// AddLineInfo is like [File.AddLineColumnInfo] with a column = 1 argument.
  /// It is here for backward-compatibility for code prior to Go 1.11.
  fn AddLineInfo(self: Ref<File>, offset: int, filename: string, line: int)

  /// Base returns the base offset of file f as registered with AddFile.
  fn Base(self: Ref<File>) -> int

  /// Line returns the line number for the given file position p;
  /// p must be a [Pos] value in that file or [NoPos].
  fn Line(self: Ref<File>, p: Pos) -> int

  /// LineCount returns the number of lines in file f.
  fn LineCount(self: Ref<File>) -> int

  /// LineStart returns the [Pos] value of the start of the specified line.
  /// It ignores any alternative positions set using [File.AddLineColumnInfo].
  /// LineStart panics if the 1-based line number is invalid.
  fn LineStart(self: Ref<File>, line: int) -> Pos

  /// Lines returns the effective line offset table of the form described by [File.SetLines].
  /// Callers must not mutate the result.
  fn Lines(self: Ref<File>) -> Slice<int>

  /// MergeLine merges a line with the following line. It is akin to replacing
  /// the newline character at the end of the line with a space (to not change the
  /// remaining offsets). To obtain the line number, consult e.g. [Position.Line].
  /// MergeLine will panic if given an invalid line number.
  fn MergeLine(self: Ref<File>, line: int)

  /// Name returns the file name of file f as registered with AddFile.
  fn Name(self: Ref<File>) -> string

  /// Offset returns the offset for the given file position p.
  /// 
  /// If p is before the file's start position (or if p is NoPos),
  /// the result is 0; if p is past the file's end position,
  /// the result is the file size (see also go.dev/issue/57490).
  /// 
  /// The following invariant, though not true for offset values
  /// in general, holds for the result offset:
  /// f.Offset(f.Pos(offset)) == offset
  fn Offset(self: Ref<File>, p: Pos) -> int

  /// Pos returns the Pos value for the given file offset.
  /// 
  /// If offset is negative, the result is the file's start
  /// position; if the offset is too large, the result is
  /// the file's end position (see also go.dev/issue/57490).
  /// 
  /// The following invariant, though not true for Pos values
  /// in general, holds for the result p:
  /// f.Pos(f.Offset(p)) == p.
  fn Pos(self: Ref<File>, offset: int) -> Pos

  /// Position returns the Position value for the given file position p.
  /// If p is out of bounds, it is adjusted to match the File.Offset behavior.
  /// Calling f.Position(p) is equivalent to calling f.PositionFor(p, true).
  fn Position(self: Ref<File>, p: Pos) -> Position

  /// PositionFor returns the Position value for the given file position p.
  /// If p is out of bounds, it is adjusted to match the File.Offset behavior.
  /// If adjusted is set, the position may be adjusted by position-altering
  /// //line comments; otherwise those comments are ignored.
  /// p must be a Pos value in f or NoPos.
  fn PositionFor(self: Ref<File>, p: Pos, adjusted: bool) -> Position

  /// SetLines sets the line offsets for a file and reports whether it succeeded.
  /// The line offsets are the offsets of the first character of each line;
  /// for instance for the content "ab\nc\n" the line offsets are {0, 3}.
  /// An empty file has an empty line offset table.
  /// Each line offset must be larger than the offset for the previous line
  /// and smaller than the file size; otherwise SetLines fails and returns
  /// false.
  /// Callers must not mutate the provided slice after SetLines returns.
  fn SetLines(self: Ref<File>, lines: Slice<int>) -> bool

  /// SetLinesForContent sets the line offsets for the given file content.
  /// It ignores position-altering //line comments.
  fn SetLinesForContent(self: Ref<File>, content: Slice<byte>)

  /// Size returns the size of file f as registered with AddFile.
  fn Size(self: Ref<File>) -> int
}

impl FileSet {
  /// AddExistingFiles adds the specified files to the
  /// FileSet if they are not already present.
  /// The caller must ensure that no pair of Files that
  /// would appear in the resulting FileSet overlap.
  fn AddExistingFiles(self: Ref<FileSet>, files: VarArgs<Ref<File>>)

  /// AddFile adds a new file with a given filename, base offset, and file size
  /// to the file set s and returns the file. Multiple files may have the same
  /// name. The base offset must not be smaller than the [FileSet.Base], and
  /// size must not be negative. As a special case, if a negative base is provided,
  /// the current value of the [FileSet.Base] is used instead.
  /// 
  /// Adding the file will set the file set's [FileSet.Base] value to base + size + 1
  /// as the minimum base value for the next file. The following relationship
  /// exists between a [Pos] value p for a given file offset offs:
  /// 
  /// 	int(p) = base + offs
  /// 
  /// with offs in the range [0, size] and thus p in the range [base, base+size].
  /// For convenience, [File.Pos] may be used to create file-specific position
  /// values from a file offset.
  fn AddFile(self: Ref<FileSet>, filename: string, base: int, size: int) -> Ref<File>

  /// Base returns the minimum base offset that must be provided to
  /// [FileSet.AddFile] when adding the next file.
  fn Base(self: Ref<FileSet>) -> int

  /// File returns the file that contains the position p.
  /// If no such file is found (for instance for p == [NoPos]),
  /// the result is nil.
  fn File(self: Ref<FileSet>, p: Pos) -> Option<Ref<File>>

  /// Iterate calls yield for the files in the file set in ascending Base
  /// order until yield returns false.
  fn Iterate(self: Ref<FileSet>, yield: fn(Ref<File>) -> bool)

  /// Position converts a [Pos] p in the fileset into a Position value.
  /// Calling s.Position(p) is equivalent to calling s.PositionFor(p, true).
  fn Position(self: Ref<FileSet>, p: Pos) -> Position

  /// PositionFor converts a [Pos] p in the fileset into a [Position] value.
  /// If adjusted is set, the position may be adjusted by position-altering
  /// //line comments; otherwise those comments are ignored.
  /// p must be a [Pos] value in s or [NoPos].
  fn PositionFor(self: Ref<FileSet>, p: Pos, adjusted: bool) -> Position

  /// Read calls decode to deserialize a file set into s; s must not be nil.
  fn Read(self: Ref<FileSet>, decode: fn(Unknown) -> Result<(), error>) -> Result<(), error>

  /// RemoveFile removes a file from the [FileSet] so that subsequent
  /// queries for its [Pos] interval yield a negative result.
  /// This reduces the memory usage of a long-lived [FileSet] that
  /// encounters an unbounded stream of files.
  /// 
  /// Removing a file that does not belong to the set has no effect.
  fn RemoveFile(self: Ref<FileSet>, file: Ref<File>)

  /// Write calls encode to serialize the file set s.
  fn Write(self: Ref<FileSet>, encode: fn(Unknown) -> Result<(), error>) -> Result<(), error>
}

impl Pos {
  /// IsValid reports whether the position is valid.
  fn IsValid(self) -> bool
}

impl Position {
  /// IsValid reports whether the position is valid.
  fn IsValid(self: Ref<Position>) -> bool

  /// String returns a string in one of several forms:
  /// 
  /// 	file:line:column    valid position with file name
  /// 	file:line           valid position with file name but no column (column == 0)
  /// 	line:column         valid position without file name
  /// 	line                valid position without file name and no column (column == 0)
  /// 	file                invalid position with file name
  /// 	-                   invalid position without file name
  fn String(self) -> string
}

impl Token {
  /// IsKeyword returns true for tokens corresponding to keywords;
  /// it returns false otherwise.
  fn IsKeyword(self) -> bool

  /// IsLiteral returns true for tokens corresponding to identifiers
  /// and basic type literals; it returns false otherwise.
  fn IsLiteral(self) -> bool

  /// IsOperator returns true for tokens corresponding to operators and
  /// delimiters; it returns false otherwise.
  fn IsOperator(self) -> bool

  /// Precedence returns the operator precedence of the binary
  /// operator op. If op is not a binary operator, the result
  /// is LowestPrecedence.
  fn Precedence(self) -> int

  /// String returns the string corresponding to the token tok.
  /// For operators, delimiters, and keywords the string is the actual
  /// token character sequence (e.g., for the token [ADD], the string is
  /// "+"). For all other tokens the string corresponds to the token
  /// constant name (e.g. for the token [IDENT], the string is "IDENT").
  fn String(self) -> string
}