tex2typst 0.3.2 → 0.3.3

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.
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Adapted from jslex - A lexer in JavaScript. https://github.com/jimbojw/jslex
3
+ * Licensed under MIT license
4
+ */
5
+ interface ILexSpec<T> {
6
+ start: Map<string, (arg0: Scanner<T>) => T | T[]>;
7
+ }
8
+ interface IRule<T> {
9
+ re: RegExp;
10
+ action: (a: Scanner<T>) => T | T[];
11
+ }
12
+ export declare class Scanner<T> {
13
+ private _input;
14
+ private _lexer;
15
+ private _pos;
16
+ private _line;
17
+ private _col;
18
+ private _offset;
19
+ private _less;
20
+ private _go;
21
+ private _newstate;
22
+ private _state;
23
+ private _text;
24
+ private _leng;
25
+ constructor(input: string, lexer: JSLex<T>);
26
+ /**
27
+ * Analogous to yytext and yyleng in lex - will be set during scan.
28
+ */
29
+ text(): string | null;
30
+ leng(): number | null;
31
+ /**
32
+ * Position of in stream, line number and column number of match.
33
+ */
34
+ pos(): number;
35
+ line(): number;
36
+ column(): number;
37
+ /**
38
+ * Analogous to input() in lex.
39
+ * @return {string} The next character in the stream.
40
+ */
41
+ input(): string;
42
+ /**
43
+ * Similar to unput() in lex, but does not allow modifying the stream.
44
+ * @return {int} The offset position after the operation.
45
+ */
46
+ unput(): number;
47
+ /**
48
+ * Analogous to yyless(n) in lex - retains the first n characters from this pattern, and returns
49
+ * the rest to the input stream, such that they will be used in the next pattern-matching operation.
50
+ * @param {int} n Number of characters to retain.
51
+ * @return {int} Length of the stream after the operation has completed.
52
+ */
53
+ less(n: number): number;
54
+ /**
55
+ * Like less(), but instead of retaining the first n characters, it chops off the last n.
56
+ * @param {int} n Number of characters to chop.
57
+ * @return {int} Length of the stream after the operation has completed.
58
+ */
59
+ pushback(n: number): number;
60
+ /**
61
+ * Similar to REJECT in lex, except it doesn't break the current execution context.
62
+ * TIP: reject() should be the last instruction in a spec callback.
63
+ */
64
+ reject(): void;
65
+ /**
66
+ * Analogous to BEGIN in lex - sets the named state (start condition).
67
+ * @param {string|int} state Name of state to switch to, or ordinal number (0 is first, etc).
68
+ * @return {string} The new state on successful switch, throws exception on failure.
69
+ */
70
+ begin(state: string | number): string;
71
+ /**
72
+ * Simple accessor for reading in the current state.
73
+ * @return {string} The current state.
74
+ */
75
+ state(): string;
76
+ /**
77
+ * Scan method to be returned to caller - grabs the next token and fires appropriate calback.
78
+ * @return {T} The next token extracted from the stream.
79
+ */
80
+ scan(): T | T[];
81
+ }
82
+ export declare class JSLex<T> {
83
+ states: string[];
84
+ specification: Record<string, IRule<T>[]>;
85
+ constructor(spec: ILexSpec<T>);
86
+ /**
87
+ * Scanner function - makes a new scanner object which is used to get tokens one at a time.
88
+ * @param {string} input Input text to tokenize.
89
+ * @return {function} Scanner function.
90
+ */
91
+ scanner(input: string): Scanner<T>;
92
+ /**
93
+ * Similar to lex's yylex() function, consumes all input, calling calback for each token.
94
+ * @param {string} input Text to lex.
95
+ * @param {function} callback Function to execute for each token.
96
+ */
97
+ lex(input: string, callback: (arg0: T | T[]) => void): void;
98
+ /**
99
+ * Consumes all input, collecting tokens along the way.
100
+ * @param {string} input Text to lex.
101
+ * @return {array} List of tokens, may contain an Error at the end.
102
+ */
103
+ collect(input: string): T[];
104
+ }
105
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { TexNode, TexToken } from "./types";
2
- export declare function tokenize(latex: string): TexToken[];
2
+ export declare function tokenize_tex(input: string): TexToken[];
3
3
  export declare class LatexParserError extends Error {
4
4
  constructor(message: string);
5
5
  }