Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ast): Create named union types for fields of AST nodes #325

Merged
merged 6 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Refactor AST types to simplify access to third-party tools (#325)
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

## [1.3.0] - 2024-05-03
Expand Down
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 ASTBinaryOperation =
| "+"
| "-"
| "*"
| "/"
| "!="
| ">"
| "<"
| ">="
| "<="
| "=="
| "&&"
| "||"
| "%"
| "<<"
| ">>"
| "&"
| "|"
| "^";

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

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

export type ASTOpUnary = {
kind: "op_unary";
id: number;
op: "+" | "-" | "!" | "!!";
op: ASTUnaryOperation;
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 ASTTraitDeclaration =
| 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: ASTTraitDeclaration[];
ref: ASTRef;
};

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

export type ASTContractDeclaration =
| 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: ASTContractDeclaration[];
ref: ASTRef;
};

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

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

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