Skip to content

Instantly share code, notes, and snippets.

@cgewecke
Last active January 24, 2017 06:01
Show Gist options
  • Save cgewecke/9faa561c644eaa9d2d455c1b1bb96198 to your computer and use it in GitHub Desktop.
Save cgewecke/9faa561c644eaa9d2d455c1b1bb96198 to your computer and use it in GitHub Desktop.
function-body

Proposed AST

Example 1 - Function body

function a(){
  uint x = 5
}
{
 "type": "FunctionDeclaration",
 "name": "a",
 "params": null,
 "modifiers": null,
 "body": {
  "type": "BlockStatement",
  "body": [
   {
    "type": "ExpressionStatement",
    "expression": {
     "type": "DeclarativeExpression",
     "name": "x",
     "literal": {
      "type": "Type",
      "literal": "uint",
      "members": [],
      "array_parts": [],
      "start": 8306,
      "end": 8310
     },
     "storage_location": null,
     "start": 8306,
     "end": 8312
    },
    "start": 8306,
    "end": 8313
   }
  ],
  "start": 8300,
  "end": 8317
 },
 "is_abstract": false,
 "start": 8288,
 "end": 8317
}

Example 2: Function body, extra spaces

function spaces()   {
    uint y;
}
{
 "type": "FunctionDeclaration",
 "name": "spaces",
 "params": null,
 "modifiers": null,
 "body": {
  "type": "BlockStatement",
  "body": [
   {
    "type": "ExpressionStatement",
    "expression": {
     "type": "DeclarativeExpression",
     "name": "y",
     "literal": {
      "type": "Type",
      "literal": "uint",
      "members": [],
      "array_parts": [],
      "start": 8346,
      "end": 8350
     },
     "storage_location": null,
     "start": 8346,
     "end": 8352
    },
    "start": 8346,
    "end": 8353
   }
  ],
  "start": 8340,
  "end": 8357
 },
 "is_abstract": false,
 "start": 8320,
 "end": 8357
}

Example 3: Abstract

function abstract();
{
 "type": "FunctionDeclaration",
 "name": "abstract",
 "params": null,
 "modifiers": null,
 "body": null,
 "is_abstract": true,
 "start": 8360,
 "end": 8380
}

Current AST

function a(){
  var x = 5;
}
{
  "type": "FunctionDeclaration",
   "name": "a",
   "params": null,
   "modifiers": null,
   "body": {
    "type": "BlockStatement",
    "body": [
     {
      "type": "VariableDeclaration",
      "declarations": [
       {
        "type": "VariableDeclarator",
        "id": {
         "type": "Identifier",
         "name": "x",
         "start": 8049,
         "end": 8050
        },
        "init": {
         "type": "Literal",
         "value": 5,
         "start": 8053,
         "end": 8054
        },
        "start": 8049,
        "end": 8054
       }
      ],
      "start": 8045,
      "end": 8055
     }
    ],
    "start": 8045,
    "end": 8055
   },
   "is_abstract": false,
   "start": 8027,
   "end": 8059
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment