Skip to content

Commit

Permalink
annotate type for TexNode::type field
Browse files Browse the repository at this point in the history
  • Loading branch information
qwinsi committed Sep 7, 2024
1 parent 741b877 commit d14c51c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const BINARY_COMMANDS = [
'tbinom',
]

const EMPTY_NODE = { 'type': 'empty', 'content': '' }
const EMPTY_NODE: TexNode = { type: 'empty', content: '' };

function assert(condition: boolean, message: string = ''): void {
if (!condition) {
Expand Down Expand Up @@ -586,12 +586,12 @@ export class LatexParser {

const exprInside = tokens.slice(exprInsideStart, exprInsideEnd);
const body = this.parse(exprInside);
const args = [
const args: TexNode[] = [
{ type: 'element', content: leftDelimiter.value },
body,
{ type: 'element', content: rightDelimiter.value }
]
const res = { type: 'leftright', content: '', args: args };
const res: TexNode = { type: 'leftright', content: '', args: args };
return [res, pos];
}

Expand Down Expand Up @@ -630,7 +630,7 @@ export class LatexParser {
exprInside.pop();
}
const body = this.parseAligned(exprInside);
const res = { type: 'beginend', content: envName, data: body };
const res: TexNode = { type: 'beginend', content: envName, data: body };
return [res, pos];
}

Expand Down
5 changes: 3 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export type TexSqrtData = TexNode;
export type TexArrayData = TexNode[][];

export interface TexNode {
type: string;
type: 'element' | 'text' | 'comment' | 'whitespace' | 'newline' | 'control' | 'ordgroup' | 'supsub'
| 'unaryFunc' | 'binaryFunc' | 'leftright' | 'beginend' | 'symbol' | 'empty' | 'unknownMacro';
content: string;
args?: TexNode[];
// position?: Position;
Expand All @@ -20,7 +21,7 @@ export interface TexNode {
}

export interface TypstNode {
type: 'atom' | 'symbol' | 'text' | 'softSpace' | 'comment' | 'newline',
type: 'atom' | 'symbol' | 'text' | 'softSpace' | 'comment' | 'newline';
content: string;
args?: TypstNode[];
}
Expand Down
3 changes: 1 addition & 2 deletions src/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const TYPST_INTRINSIC_SYMBOLS = [
];

export class TypstWriterError extends Error {
node: TexNode;
node: TexNode | TypstNode;

constructor(message: string, node: TexNode | TypstNode) {
super(message);
Expand Down Expand Up @@ -273,7 +273,6 @@ export class TypstWriter {
this.queue.push({ type: 'atom', content: ')'});
this.insideFunctionDepth --;
}
} else if (node.type === 'matrix') {
} else if (node.type === 'unknownMacro') {
if (this.nonStrict) {
this.queue.push({ type: 'symbol', content: node.content });
Expand Down

0 comments on commit d14c51c

Please sign in to comment.