Skip to content

Commit

Permalink
chore(ast): Create named union types for fields of AST nodes
Browse files Browse the repository at this point in the history
Addresses tact-lang#314
  • Loading branch information
byakuren-hijiri committed May 6, 2024
1 parent 8d13b97 commit 2cd8c1d
Showing 1 changed file with 53 additions and 39 deletions.
92 changes: 53 additions & 39 deletions src/grammar/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,37 +124,41 @@ export type ASTTypeRef = ASTTypeRefSimple | ASTTypeRefMap | ASTTypeRefBounced;
// Expressions
//

export type ASTBinaryOperations =
| "+"
| "-"
| "*"
| "/"
| "!="
| ">"
| "<"
| ">="
| "<="
| "=="
| "&&"
| "||"
| "%"
| "<<"
| ">>"
| "&"
| "|"
| "^";

export type ASTOpBinary = {
kind: "op_binary";
id: number;
op:
| "+"
| "-"
| "*"
| "/"
| "!="
| ">"
| "<"
| ">="
| "<="
| "=="
| "&&"
| "||"
| "%"
| "<<"
| ">>"
| "&"
| "|"
| "^";
op: ASTBinaryOperations;
left: ASTExpression;
right: ASTExpression;
ref: ASTRef;
};

export type ASTUnaryOperations = "+" | "-" | "!" | "!!";

export type ASTOpUnary = {
kind: "op_unary";
id: number;
op: "+" | "-" | "!" | "!!";
op: ASTUnaryOperations;
right: ASTExpression;
ref: ASTRef;
};
Expand Down Expand Up @@ -221,19 +225,20 @@ export type ASTConditional = {
// Program
//

export type ASTProgramEntry =
| ASTStruct
| ASTContract
| ASTPrimitive
| ASTFunction
| ASTNativeFunction
| ASTTrait
| ASTProgramImport
| ASTConstant;

export type ASTProgram = {
kind: "program";
id: number;
entries: (
| ASTStruct
| ASTContract
| ASTPrimitive
| ASTFunction
| ASTNativeFunction
| ASTTrait
| ASTProgramImport
| ASTConstant
)[];
entries: ASTProgramEntry[];
};

export type ASTProgramImport = {
Expand All @@ -254,14 +259,20 @@ export type ASTStruct = {
ref: ASTRef;
};

export type ASTTraitDeclarations =
| ASTField
| ASTFunction
| ASTReceive
| ASTConstant;

export type ASTTrait = {
kind: "def_trait";
origin: TypeOrigin;
id: number;
name: string;
traits: ASTString[];
attributes: ASTContractAttribute[];
declarations: (ASTField | ASTFunction | ASTReceive | ASTConstant)[];
declarations: ASTTraitDeclarations[];
ref: ASTRef;
};

Expand Down Expand Up @@ -296,20 +307,21 @@ export type ASTContractAttribute = {
ref: ASTRef;
};

export type ASTContractDeclarations =
| ASTField
| ASTFunction
| ASTInitFunction
| ASTReceive
| ASTConstant;

export type ASTContract = {
kind: "def_contract";
origin: TypeOrigin;
id: number;
name: string;
traits: ASTString[];
attributes: ASTContractAttribute[];
declarations: (
| ASTField
| ASTFunction
| ASTInitFunction
| ASTReceive
| ASTConstant
)[];
declarations: ASTContractDeclarations[];
ref: ASTRef;
};

Expand Down Expand Up @@ -431,10 +443,12 @@ export type ASTSTatementAssign = {
ref: ASTRef;
};

export type ASTAugmentedAssignOperations = "+" | "-" | "*" | "/" | "%";

export type ASTSTatementAugmentedAssign = {
kind: "statement_augmentedassign";
id: number;
op: "+" | "-" | "*" | "/" | "%";
op: ASTAugmentedAssignOperations;
path: ASTLvalueRef[];
expression: ASTExpression;
ref: ASTRef;
Expand Down

0 comments on commit 2cd8c1d

Please sign in to comment.