mirror of
https://github.com/We-Dont-Byte/Mind_Reader.git
synced 2024-11-15 03:35:59 +00:00
887f88eba6
* Update parser Implied nodes caused ambiguity when querying for context. Now every line is considered, even blank lines, to make the process much, *much* easier. * Update pylex tests * Add runCursorContext
69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
import * as vscode from 'vscode';
|
|
import { LineToken, PylexSymbol, LexNode} from '../pylex';
|
|
|
|
/**
|
|
* TODO: Eliminate need for me.
|
|
* Recursively deparents a LexNode tree. Needed
|
|
* because I wasn't able to iterate the circular parent-child
|
|
* relationship by hand
|
|
*/
|
|
function deparent(root: null): null;
|
|
function deparent(root: LexNode): LexNode;
|
|
function deparent(root: any): any {
|
|
if (root === null) {
|
|
return root;
|
|
} else {
|
|
if (root.children() !== null) {
|
|
return new LexNode(
|
|
root.label,
|
|
root.collapsibleState,
|
|
root.token,
|
|
root.children()!.map(deparent),
|
|
);
|
|
} else {
|
|
return new LexNode(
|
|
root.label,
|
|
root.collapsibleState,
|
|
root.token,
|
|
null,
|
|
null
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* "Roots" a list of lexNodes to match the parser
|
|
*
|
|
* Required to properly test the output of the parser,
|
|
* since the parent child-relationship can't be modeled
|
|
* exhaustively otherwise
|
|
*/
|
|
function root(nodes: LexNode[] | null): LexNode {
|
|
return new LexNode(
|
|
"root",
|
|
vscode.TreeItemCollapsibleState.None,
|
|
null,
|
|
nodes,
|
|
null
|
|
);
|
|
}
|
|
|
|
/* short hand for returning an indentation token for a certain line and indentation */
|
|
function indent(linenr: number, indentLevel: number): LexNode {
|
|
return new LexNode('INDENT', 0, new LineToken(PylexSymbol.INDENT, linenr, indentLevel));
|
|
}
|
|
|
|
/* short hand for returning an empty token for a certain line*/
|
|
function empty(linenr: number): LexNode {
|
|
return new LexNode('EMPTY', 0, new LineToken(PylexSymbol.EMPTY, linenr, 999999));
|
|
}
|
|
|
|
|
|
export {
|
|
deparent,
|
|
root,
|
|
indent,
|
|
empty
|
|
};
|