Skip to content

Commit

Permalink
fix: Post-parser processing no longer crashes on error
Browse files Browse the repository at this point in the history
Closes #99
  • Loading branch information
adam-coster committed Jun 20, 2023
1 parent 378c497 commit 9803aa5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions packages/parser/src/project.visitGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
IdentifierAccessorCstChildren,
MacroStatementCstChildren,
} from '../gml-cst.js';
import { logger } from './logger.js';
import { GmlVisitorBase, identifierFrom } from './parser.js';
import type { Code } from './project.code.js';
import { Position, Range } from './project.location.js';
Expand All @@ -16,9 +17,13 @@ import { PrimitiveName } from './types.primitives.js';
import { assert } from './util.js';

export function processGlobalSymbols(file: Code) {
const processor = new GlobalDeclarationsProcessor(file);
const visitor = new GmlGlobalDeclarationsVisitor(processor);
visitor.extractGlobalDeclarations(file.cst);
try {
const processor = new GlobalDeclarationsProcessor(file);
const visitor = new GmlGlobalDeclarationsVisitor(processor);
visitor.extractGlobalDeclarations(file.cst);
} catch (err) {
logger.error(err);
}
}

class GlobalDeclarationsProcessor {
Expand Down
11 changes: 8 additions & 3 deletions packages/parser/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
WithStatementCstChildren,
} from '../gml-cst.js';
import { JsdocSummary, parseJsdoc } from './jsdoc.js';
import { logger } from './logger.js';
import {
GmlVisitorBase,
VisitorContext,
Expand All @@ -44,9 +45,13 @@ import { visitIdentifierAccessor } from './visitor.identifierAccessor.js';
import { SymbolProcessor } from './visitor.processor.js';

export function processSymbols(file: Code) {
const processor = new SymbolProcessor(file);
const visitor = new GmlSymbolVisitor(processor);
visitor.FIND_SYMBOLS(file.cst);
try {
const processor = new SymbolProcessor(file);
const visitor = new GmlSymbolVisitor(processor);
visitor.FIND_SYMBOLS(file.cst);
} catch (error) {
logger.error(error);
}
}

export class GmlSymbolVisitor extends GmlVisitorBase {
Expand Down

0 comments on commit 9803aa5

Please sign in to comment.