@solidity-parser/parser
Advanced tools
Comparing version 0.13.3-rc.1 to 0.14.0
@@ -18,2 +18,3 @@ import { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener"; | ||
import { CustomErrorDefinitionContext } from "./SolidityParser"; | ||
import { TypeDefinitionContext } from "./SolidityParser"; | ||
import { UsingForDeclarationContext } from "./SolidityParser"; | ||
@@ -265,2 +266,12 @@ import { StructDefinitionContext } from "./SolidityParser"; | ||
/** | ||
* Enter a parse tree produced by `SolidityParser.typeDefinition`. | ||
* @param ctx the parse tree | ||
*/ | ||
enterTypeDefinition?: (ctx: TypeDefinitionContext) => void; | ||
/** | ||
* Exit a parse tree produced by `SolidityParser.typeDefinition`. | ||
* @param ctx the parse tree | ||
*/ | ||
exitTypeDefinition?: (ctx: TypeDefinitionContext) => void; | ||
/** | ||
* Enter a parse tree produced by `SolidityParser.usingForDeclaration`. | ||
@@ -267,0 +278,0 @@ * @param ctx the parse tree |
@@ -18,2 +18,3 @@ import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor"; | ||
import { CustomErrorDefinitionContext } from "./SolidityParser"; | ||
import { TypeDefinitionContext } from "./SolidityParser"; | ||
import { UsingForDeclarationContext } from "./SolidityParser"; | ||
@@ -204,2 +205,8 @@ import { StructDefinitionContext } from "./SolidityParser"; | ||
/** | ||
* Visit a parse tree produced by `SolidityParser.typeDefinition`. | ||
* @param ctx the parse tree | ||
* @return the visitor result | ||
*/ | ||
visitTypeDefinition?: (ctx: TypeDefinitionContext) => Result; | ||
/** | ||
* Visit a parse tree produced by `SolidityParser.usingForDeclaration`. | ||
@@ -206,0 +213,0 @@ * @param ctx the parse tree |
@@ -36,3 +36,3 @@ interface Location { | ||
} | ||
export declare const astNodeTypes: readonly ["SourceUnit", "PragmaDirective", "ImportDirective", "ContractDefinition", "InheritanceSpecifier", "StateVariableDeclaration", "UsingForDeclaration", "StructDefinition", "ModifierDefinition", "ModifierInvocation", "FunctionDefinition", "EventDefinition", "CustomErrorDefinition", "RevertStatement", "EnumValue", "EnumDefinition", "VariableDeclaration", "UserDefinedTypeName", "Mapping", "ArrayTypeName", "FunctionTypeName", "Block", "ExpressionStatement", "IfStatement", "WhileStatement", "ForStatement", "InlineAssemblyStatement", "DoWhileStatement", "ContinueStatement", "Break", "Continue", "BreakStatement", "ReturnStatement", "EmitStatement", "ThrowStatement", "VariableDeclarationStatement", "ElementaryTypeName", "FunctionCall", "AssemblyBlock", "AssemblyCall", "AssemblyLocalDefinition", "AssemblyAssignment", "AssemblyStackAssignment", "LabelDefinition", "AssemblySwitch", "AssemblyCase", "AssemblyFunctionDefinition", "AssemblyFunctionReturns", "AssemblyFor", "AssemblyIf", "SubAssembly", "TupleExpression", "TypeNameExpression", "NameValueExpression", "BooleanLiteral", "NumberLiteral", "Identifier", "BinaryOperation", "UnaryOperation", "NewExpression", "Conditional", "StringLiteral", "HexLiteral", "HexNumber", "DecimalNumber", "MemberAccess", "IndexAccess", "IndexRangeAccess", "NameValueList", "UncheckedStatement", "TryStatement", "CatchClause", "FileLevelConstant", "AssemblyMemberAccess"]; | ||
export declare const astNodeTypes: readonly ["SourceUnit", "PragmaDirective", "ImportDirective", "ContractDefinition", "InheritanceSpecifier", "StateVariableDeclaration", "UsingForDeclaration", "StructDefinition", "ModifierDefinition", "ModifierInvocation", "FunctionDefinition", "EventDefinition", "CustomErrorDefinition", "RevertStatement", "EnumValue", "EnumDefinition", "VariableDeclaration", "UserDefinedTypeName", "Mapping", "ArrayTypeName", "FunctionTypeName", "Block", "ExpressionStatement", "IfStatement", "WhileStatement", "ForStatement", "InlineAssemblyStatement", "DoWhileStatement", "ContinueStatement", "Break", "Continue", "BreakStatement", "ReturnStatement", "EmitStatement", "ThrowStatement", "VariableDeclarationStatement", "ElementaryTypeName", "FunctionCall", "AssemblyBlock", "AssemblyCall", "AssemblyLocalDefinition", "AssemblyAssignment", "AssemblyStackAssignment", "LabelDefinition", "AssemblySwitch", "AssemblyCase", "AssemblyFunctionDefinition", "AssemblyFunctionReturns", "AssemblyFor", "AssemblyIf", "SubAssembly", "TupleExpression", "TypeNameExpression", "NameValueExpression", "BooleanLiteral", "NumberLiteral", "Identifier", "BinaryOperation", "UnaryOperation", "NewExpression", "Conditional", "StringLiteral", "HexLiteral", "HexNumber", "DecimalNumber", "MemberAccess", "IndexAccess", "IndexRangeAccess", "NameValueList", "UncheckedStatement", "TryStatement", "CatchClause", "FileLevelConstant", "AssemblyMemberAccess", "TypeDefinition"]; | ||
export declare type ASTNodeTypeString = typeof astNodeTypes[number]; | ||
@@ -109,2 +109,7 @@ export interface PragmaDirective extends BaseASTNode { | ||
} | ||
export interface TypeDefinition extends BaseASTNode { | ||
type: 'TypeDefinition'; | ||
name: string; | ||
definition: ElementaryTypeName; | ||
} | ||
export interface RevertStatement extends BaseASTNode { | ||
@@ -419,3 +424,3 @@ type: 'RevertStatement'; | ||
} | ||
export declare type ASTNode = SourceUnit | PragmaDirective | ImportDirective | ContractDefinition | InheritanceSpecifier | StateVariableDeclaration | UsingForDeclaration | StructDefinition | ModifierDefinition | ModifierInvocation | FunctionDefinition | EventDefinition | CustomErrorDefinition | EnumValue | EnumDefinition | VariableDeclaration | TypeName | UserDefinedTypeName | Mapping | FunctionTypeName | Block | Statement | ElementaryTypeName | AssemblyBlock | AssemblyCall | AssemblyLocalDefinition | AssemblyAssignment | AssemblyStackAssignment | LabelDefinition | AssemblySwitch | AssemblyCase | AssemblyFunctionDefinition | AssemblyFunctionReturns | AssemblyFor | AssemblyIf | AssemblyLiteral | SubAssembly | TupleExpression | TypeNameExpression | BinaryOperation | Conditional | IndexAccess | IndexRangeAccess | AssemblyItem | Expression | NameValueList | AssemblyMemberAccess | CatchClause | FileLevelConstant; | ||
export declare type ASTNode = SourceUnit | PragmaDirective | ImportDirective | ContractDefinition | InheritanceSpecifier | StateVariableDeclaration | UsingForDeclaration | StructDefinition | ModifierDefinition | ModifierInvocation | FunctionDefinition | EventDefinition | CustomErrorDefinition | EnumValue | EnumDefinition | VariableDeclaration | TypeName | UserDefinedTypeName | Mapping | FunctionTypeName | Block | Statement | ElementaryTypeName | AssemblyBlock | AssemblyCall | AssemblyLocalDefinition | AssemblyAssignment | AssemblyStackAssignment | LabelDefinition | AssemblySwitch | AssemblyCase | AssemblyFunctionDefinition | AssemblyFunctionReturns | AssemblyFor | AssemblyIf | AssemblyLiteral | SubAssembly | TupleExpression | TypeNameExpression | BinaryOperation | Conditional | IndexAccess | IndexRangeAccess | AssemblyItem | Expression | NameValueList | AssemblyMemberAccess | CatchClause | FileLevelConstant | TypeDefinition; | ||
export declare type AssemblyItem = Identifier | AssemblyBlock | AssemblyExpression | AssemblyLocalDefinition | AssemblyAssignment | AssemblyStackAssignment | LabelDefinition | AssemblySwitch | AssemblyFunctionDefinition | AssemblyFor | AssemblyIf | Break | Continue | SubAssembly | NumberLiteral | StringLiteral | HexNumber | HexLiteral | DecimalNumber; | ||
@@ -422,0 +427,0 @@ export declare type AssemblyExpression = AssemblyCall | AssemblyLiteral; |
@@ -47,2 +47,3 @@ import { ParserRuleContext } from 'antlr4ts'; | ||
visitCustomErrorDefinition(ctx: SP.CustomErrorDefinitionContext): AST.CustomErrorDefinition & WithMeta; | ||
visitTypeDefinition(ctx: SP.TypeDefinitionContext): AST.TypeDefinition & WithMeta; | ||
visitRevertStatement(ctx: SP.RevertStatementContext): AST.RevertStatement & WithMeta; | ||
@@ -49,0 +50,0 @@ visitFunctionCall(ctx: SP.FunctionCallContext): AST.FunctionCall & WithMeta; |
@@ -20,4 +20,3 @@ import { ASTNode, ASTVisitor, SourceUnit } from './ast-types'; | ||
export declare function parse(input: string, options?: ParseOptions): ParseResult; | ||
export declare function visitAll(node: unknown, cb: (node: ASTNode, nodeParent?: ASTNode) => boolean, nodeParent?: ASTNode): void; | ||
export declare function visit(node: unknown, visitor: ASTVisitor, nodeParent?: ASTNode): void; | ||
export {}; |
{ | ||
"name": "@solidity-parser/parser", | ||
"version": "0.13.3-rc.1", | ||
"version": "0.14.0", | ||
"description": "A Solidity parser built from a robust ANTLR 4 grammar", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js", |
@@ -22,2 +22,3 @@ // Generated from antlr/Solidity.g4 by ANTLR 4.9.0-SNAPSHOT | ||
import { CustomErrorDefinitionContext } from "./SolidityParser"; | ||
import { TypeDefinitionContext } from "./SolidityParser"; | ||
import { UsingForDeclarationContext } from "./SolidityParser"; | ||
@@ -287,2 +288,13 @@ import { StructDefinitionContext } from "./SolidityParser"; | ||
/** | ||
* Enter a parse tree produced by `SolidityParser.typeDefinition`. | ||
* @param ctx the parse tree | ||
*/ | ||
enterTypeDefinition?: (ctx: TypeDefinitionContext) => void; | ||
/** | ||
* Exit a parse tree produced by `SolidityParser.typeDefinition`. | ||
* @param ctx the parse tree | ||
*/ | ||
exitTypeDefinition?: (ctx: TypeDefinitionContext) => void; | ||
/** | ||
* Enter a parse tree produced by `SolidityParser.usingForDeclaration`. | ||
@@ -289,0 +301,0 @@ * @param ctx the parse tree |
@@ -22,2 +22,3 @@ // Generated from antlr/Solidity.g4 by ANTLR 4.9.0-SNAPSHOT | ||
import { CustomErrorDefinitionContext } from "./SolidityParser"; | ||
import { TypeDefinitionContext } from "./SolidityParser"; | ||
import { UsingForDeclarationContext } from "./SolidityParser"; | ||
@@ -226,2 +227,9 @@ import { StructDefinitionContext } from "./SolidityParser"; | ||
/** | ||
* Visit a parse tree produced by `SolidityParser.typeDefinition`. | ||
* @param ctx the parse tree | ||
* @return the visitor result | ||
*/ | ||
visitTypeDefinition?: (ctx: TypeDefinitionContext) => Result; | ||
/** | ||
* Visit a parse tree produced by `SolidityParser.usingForDeclaration`. | ||
@@ -228,0 +236,0 @@ * @param ctx the parse tree |
@@ -122,2 +122,3 @@ // Base on the original type definitions for solidity-parser-antlr 0.2 | ||
'AssemblyMemberAccess', | ||
'TypeDefinition' | ||
] as const | ||
@@ -192,2 +193,3 @@ | ||
} | ||
export interface CustomErrorDefinition extends BaseASTNode { | ||
@@ -198,2 +200,9 @@ type: 'CustomErrorDefinition' | ||
} | ||
export interface TypeDefinition extends BaseASTNode { | ||
type: 'TypeDefinition' | ||
name: string | ||
definition: ElementaryTypeName | ||
} | ||
export interface RevertStatement extends BaseASTNode { | ||
@@ -620,2 +629,3 @@ type: 'RevertStatement' | ||
| FileLevelConstant | ||
| TypeDefinition | ||
@@ -622,0 +632,0 @@ export type AssemblyItem = |
@@ -733,2 +733,14 @@ import { ParserRuleContext } from 'antlr4ts' | ||
public visitTypeDefinition( | ||
ctx: SP.TypeDefinitionContext | ||
): AST.TypeDefinition & WithMeta { | ||
const node: AST.TypeDefinition = { | ||
type: 'TypeDefinition', | ||
name: this._toText(ctx.identifier()), | ||
definition: this.visitElementaryTypeName(ctx.elementaryTypeName()) | ||
} | ||
return this._addMeta(node, ctx) | ||
} | ||
public visitRevertStatement( | ||
@@ -735,0 +747,0 @@ ctx: SP.RevertStatementContext |
@@ -107,26 +107,2 @@ import { ANTLRInputStream, CommonTokenStream } from 'antlr4ts' | ||
export function visitAll(node: unknown, cb: (node: ASTNode, nodeParent?: ASTNode) => boolean, nodeParent?: ASTNode): void { | ||
if (Array.isArray(node)) { | ||
node.forEach((child) => visitAll(child, cb, nodeParent)) | ||
} | ||
if (!_isASTNode(node)) return | ||
if (node.loc === undefined) { | ||
console.trace() | ||
process.exit(1) | ||
} | ||
const cont = cb(node, nodeParent) | ||
if (cont === false) return | ||
for (const prop in node) { | ||
if (Object.prototype.hasOwnProperty.call(node, prop)) { | ||
// TODO can we avoid this `as any` | ||
visitAll((node as any)[prop], cb, node) | ||
} | ||
} | ||
} | ||
export function visit(node: unknown, visitor: ASTVisitor, nodeParent?: ASTNode): void { | ||
@@ -133,0 +109,0 @@ if (Array.isArray(node)) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9193845
97897