Skip to content

Commit

Permalink
Parse source code with old parser for LSP
Browse files Browse the repository at this point in the history
  • Loading branch information
siefkenj committed Nov 30, 2023
1 parent 4d70a3b commit ef6b016
Show file tree
Hide file tree
Showing 9 changed files with 464 additions and 6 deletions.
13 changes: 10 additions & 3 deletions packages/lsp-tools/src/doenet-source-object/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
DastElement,
DastFunctionMacro,
DastFunctionMacroV6,
DastMacroV6,
DastNodes,
DastRoot,
LezerSyntaxNodeName,
Expand Down Expand Up @@ -397,19 +399,24 @@ export type OffsetToPositionMap = {
* Returns `true` if the macro is an "old-style" macro with slashes
* in its path.
*/
export function isOldMacro(macro: DastMacro | DastFunctionMacro): boolean {
export function isOldMacro(
macro: DastMacro | DastFunctionMacro | DastMacroV6 | DastFunctionMacroV6,
): boolean {
if (!("version" in macro) || macro.version !== "0.6") {
return false;
}
switch (macro.type) {
case "macro": {
if (macro.path.length !== 1) {
return true;
}
if (macro.accessedProp) {
if ("accessedProp" in macro && macro.accessedProp) {
return isOldMacro(macro.accessedProp);
}
return false;
}
case "function": {
return isOldMacro(macro.macro);
return "macro" in macro && isOldMacro(macro.macro);
}
}
}
3 changes: 2 additions & 1 deletion packages/lsp-tools/src/doenet-source-object/initializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
DastNodes,
DastRoot,
lezerToDast,
lezerToDastV6,
stringToLezer,
toXml,
visit,
Expand Down Expand Up @@ -41,7 +42,7 @@ export function initLezerCursor(this: DoenetSourceObject): TreeCursor {
}

export function initDast(this: DoenetSourceObject) {
return lezerToDast(this._lezer(), this.source);
return lezerToDastV6(this._lezer(), this.source);
}

export function initParentMap(this: DoenetSourceObject) {
Expand Down
1 change: 1 addition & 0 deletions packages/parser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export * from "./types";
export { visit } from "./pretty-printer/normalize/utils/visit";
export { toXml } from "./dast-to-xml/dast-util-to-xml";
export { lezerToDast, stringToLezer } from "./lezer-to-dast/lezer-to-dast";
export { lezerToDastV6 } from "./lezer-to-dast";
export { prettyPrint } from "./pretty-printer";
export { filterPositionInfo } from "./dast-to-xml/utils";
1 change: 1 addition & 0 deletions packages/parser/src/lezer-to-dast/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { lezerToDast } from "./lezer-to-dast";
export { lezerToDastV6 } from "./lezer-to-dast-v6";
Loading

0 comments on commit ef6b016

Please sign in to comment.