Debian Codegraph @

node/@bufbuild/protobuf/dist/commonjs/txtpb/reader.d.ts

raw
1 /**
2 * A lexical token of the protobuf text format.
3 *
4 * This is a discriminated union keyed by `type`: punctuation tokens carry no
5 * payload, identifiers carry their text, string tokens carry their decoded
6 * bytes (the same bytes back both string and bytes fields, and bytes fields may
7 * hold sequences that are not valid UTF-8), and numbers carry their literal
8 * text plus enough classification for the parser to accept or reject them per
9 * field type.
10 *
11 * The minus sign before a number is its own token rather than part of the
12 * number, which keeps numeric sign handling in one place in the parser and,
13 * because whitespace and comments between tokens are insignificant, makes
14 * `- 42` mean `-42`, matching protobuf-go (decode_number.go). A minus glued to
15 * a letter is instead folded into a negative identifier (`-inf`/`-infinity`),
16 * because protobuf-go requires the sign glued for those literals — `- inf` is
17 * an error there, not negative infinity.
18 */
19 export type Token = {
20 readonly type: Structural | "eof";
21 } | {
22 readonly type: "identifier";
23 readonly value: string;
24 } | {
25 readonly type: "string";
26 readonly value: Uint8Array;
27 } | {
28 readonly type: "int";
29 readonly text: string;
30 readonly base: 8 | 10 | 16;
31 } | {
32 readonly type: "float";
33 readonly text: string;
34 };
35 /**
36 * The structural tokens, each the literal source character it represents.
37 */
38 type Structural = "{" | "}" | "<" | ">" | "[" | "]" | ":" | "," | ";" | "-";
39 /**
40 * A tokenizer for the protobuf text format.
41 *
42 * The parser drives it with `peek()` and `next()` (one-token lookahead) and,
43 * once it knows it is in a field-name position, asks for the contents of a
44 * bracketed name with `readTypeName()` — the `[...]` syntax for extensions and
45 * Any type URLs is ambiguous with the list syntax at the lexical level. The
46 * structure is modeled on the graphql-js lexer: a single scan position and a
47 * per-token reader that returns the decoded value.
48 */
49 export declare class Reader {
50 private readonly input;
51 private readonly length;
52 private pos;
53 private lookahead;
54 constructor(input: string);
55 /**
56 * Return the next token without consuming it.
57 */
58 peek(): Token;
59 /**
60 * Consume and return the next token.
61 */
62 next(): Token;
63 /**
64 * Read the contents of a bracketed name, used for extension fields and the
65 * expanded form of google.protobuf.Any. The opening `[` must already have
66 * been consumed with `next()`. Whitespace and comments inside the brackets
67 * are insignificant. Returns the inner name with the brackets removed, e.g.
68 * "pkg.Message.field" or "type.googleapis.com/pkg.Message".
69 *
70 * The text format grammar for this is incomplete, so we follow protobuf-go's
71 * parseTypeName: the prefix may contain URL characters, `/` separators, and
72 * well-formed percent-escapes, and the type name after the last `/` must be a
73 * dotted identifier.
74 */
75 readTypeName(): string;
76 private scan;
77 private skipSpace;
78 private scanIdentifier;
79 /**
80 * Scan a numeric literal. The sign is a separate token, so a number never
81 * starts with `-`. The literal must end at a delimiter, so `10f` is a float
82 * but `10bar`, `1.2.3`, `09`, and `0xZ` are errors.
83 */
84 private scanNumber;
85 private expectDelimiter;
86 private scanString;
87 private scanEscape;
88 private takeWhile;
89 private charAt;
90 }
91 export {};