Skip to content

Commit

Permalink
refactor: change long imports for AST to * as A imports (#1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
i582 authored Jan 21, 2025
1 parent c0a3a5a commit 8dbe087
Show file tree
Hide file tree
Showing 8 changed files with 467 additions and 529 deletions.
33 changes: 15 additions & 18 deletions src/context/store.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
AstModule,
AstConstantDef,
AstFunctionDef,
AstNativeFunctionDecl,
AstTypeDecl,
AstAsmFunctionDef,
} from "../ast/ast";
import * as A from "../ast/ast";
import { throwInternalCompilerError } from "../error/errors";
import { CompilerContext, createContextStore } from "./context";
import { ItemOrigin } from "../grammar/src-info";
Expand All @@ -26,9 +19,13 @@ export type TactSource = { code: string; path: string; origin: ItemOrigin };
export type AstStore = {
sources: TactSource[];
funcSources: { code: string; path: string }[];
functions: (AstFunctionDef | AstNativeFunctionDecl | AstAsmFunctionDef)[];
constants: AstConstantDef[];
types: AstTypeDecl[];
functions: (
| A.AstFunctionDef
| A.AstNativeFunctionDecl
| A.AstAsmFunctionDef
)[];
constants: A.AstConstantDef[];
types: A.AstTypeDecl[];
};

const store = createContextStore<AstStore>();
Expand All @@ -55,7 +52,7 @@ export function getRawAST(ctx: CompilerContext): AstStore {
export function parseModules(
sources: TactSource[],
parser: Parser,
): AstModule[] {
): A.AstModule[] {
return sources.map((source) =>
parser.parse(source.code, source.path, source.origin),
);
Expand All @@ -73,18 +70,18 @@ export function openContext(
sources: TactSource[],
funcSources: { code: string; path: string }[],
parser: Parser,
parsedModules?: AstModule[],
parsedModules?: A.AstModule[],
): CompilerContext {
const modules = parsedModules
? parsedModules
: parseModules(sources, parser);
const types: AstTypeDecl[] = [];
const types: A.AstTypeDecl[] = [];
const functions: (
| AstNativeFunctionDecl
| AstFunctionDef
| AstAsmFunctionDef
| A.AstNativeFunctionDecl
| A.AstFunctionDef
| A.AstAsmFunctionDef
)[] = [];
const constants: AstConstantDef[] = [];
const constants: A.AstConstantDef[] = [];
for (const module of modules) {
for (const item of module.items) {
switch (item.kind) {
Expand Down
13 changes: 8 additions & 5 deletions src/grammar/grammar.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { getParser as getParserNext } from "./next";

import { AstExpression, AstImport, AstModule, FactoryAst } from "../ast/ast";
import * as A from "../ast/ast";

import { getParser as getParserPrev } from "./prev/grammar";
import { ItemOrigin } from "./src-info";

export type Parser = {
parse: (src: string, path: string, origin: ItemOrigin) => AstModule;
parseExpression: (sourceCode: string) => AstExpression;
parse: (src: string, path: string, origin: ItemOrigin) => A.AstModule;
parseExpression: (sourceCode: string) => A.AstExpression;
parseImports: (
src: string,
path: string,
origin: ItemOrigin,
) => AstImport[];
) => A.AstImport[];
};

export const defaultParser = "new";

export const getParser = (ast: FactoryAst, version: "old" | "new"): Parser => {
export const getParser = (
ast: A.FactoryAst,
version: "old" | "new",
): Parser => {
if (version === "new") {
return getParserNext(ast);
} else {
Expand Down
Loading

0 comments on commit 8dbe087

Please sign in to comment.