Module: solidityParser

This is the solidityParser interface

Methods

(inner) parse(input) → {Object}

Parses a string Solidity Contract

Parameters:
Name Type Description
input String

the Contract string

Returns:
Type
Object
Example
const input = `
 contract test {
 uint256 a;
 function f() {}
}`
const parsed = solidityParser.parse(input)
// Returns
// { type: 'SourceUnit',
//  children:
//   [ { type: 'ContractDefinition',
//      name: 'test',
//      baseContracts: [],
//      subNodes: [Array],
//      kind: 'contract' } ] }

(inner) parseEnum(input) → {Object}

Parses enums found in a string Solidity contract

Parameters:
Name Type Description
input String

the Contract string with Enums

Returns:
Type
Object
Example
const input = `
contract ErrorCodes {
     enum ErrorCodes {
         NULL,
         SUCCESS,
         ERROR,
         NOT_FOUND,
         EXISTS,
         RECURSIVE,
         INSUFFICIENT_BALANCE,
         UNAUTHORIZED
     }
 }`
 const parsed = parseEnum(input);
// Returns
// { '0': 'NULL',
//  '1': 'SUCCESS',
//  '2': 'ERROR',
//  '3': 'NOT_FOUND',
//  '4': 'EXISTS',
//  '5': 'RECURSIVE',
//  '6': 'INSUFFICIENT_BALANCE',
//  '7': 'UNAUTHORIZED',
//  NULL: 0,
//  SUCCESS: 1,
//  ERROR: 2,
//  NOT_FOUND: 3,
//  EXISTS: 4,
//  RECURSIVE: 5,
//  INSUFFICIENT_BALANCE: 6,
//  UNAUTHORIZED: 7 }

(inner) parseFields(input) → {Object}

Parses fields found in a string Solidity contract

Parameters:
Name Type Description
input String

the Contract string with Fields

Returns:
Type
Object
Example
const input = `
   contract test {
       uint256 a;
       uint256 b = 1234;
       string c = 'ABCD';
       function f() {}
   }`
 const parsed = parseFields(input);
// Returns
// { '1234': 'b', b: '1234', c: 'ABCD', ABCD: 'c' }