Skip to content

Instantly share code, notes, and snippets.

@abhi18av
Created August 22, 2017 16:44
Show Gist options
  • Save abhi18av/5a84b1172e18d2c1a15a3902d92098a9 to your computer and use it in GitHub Desktop.
Save abhi18av/5a84b1172e18d2c1a15a3902d92098a9 to your computer and use it in GitHub Desktop.
NodeJS php parser

PHP Script :

<?php
/**
 * Some namespace & file description
 */
  $phone = array();
  $phone["Andrew"] = "C49";
  $phone["Sally"] = "C46";
  $phone["Ken"] = "D52";
  $phone["Gordon"] = "C49";

AST Structure :

{
  "kind": "program",
  "children": [
    {
      "kind": "assign",
      "operator": "=",
      "left": {
        "kind": "variable",
        "name": "phone",
        "byref": false,
        "curly": false
      },
      "right": {
        "kind": "array",
        "items": [],
        "shortForm": false
      }
    },
    {
      "kind": "assign",
      "operator": "=",
      "left": {
        "kind": "offsetlookup",
        "what": {
          "kind": "variable",
          "name": "phone",
          "byref": false,
          "curly": false
        },
        "offset": {
          "kind": "string",
          "value": "Andrew",
          "isDoubleQuote": true
        }
      },
      "right": {
        "kind": "string",
        "value": "C49",
        "isDoubleQuote": true
      }
    },
    {
      "kind": "assign",
      "operator": "=",
      "left": {
        "kind": "offsetlookup",
        "what": {
          "kind": "variable",
          "name": "phone",
          "byref": false,
          "curly": false
        },
        "offset": {
          "kind": "string",
          "value": "Sally",
          "isDoubleQuote": true
        }
      },
      "right": {
        "kind": "string",
        "value": "C46",
        "isDoubleQuote": true
      }
    },
    {
      "kind": "assign",
      "operator": "=",
      "left": {
        "kind": "offsetlookup",
        "what": {
          "kind": "variable",
          "name": "phone",
          "byref": false,
          "curly": false
        },
        "offset": {
          "kind": "string",
          "value": "Ken",
          "isDoubleQuote": true
        }
      },
      "right": {
        "kind": "string",
        "value": "D52",
        "isDoubleQuote": true
      }
    },
    {
      "kind": "assign",
      "operator": "=",
      "left": {
        "kind": "offsetlookup",
        "what": {
          "kind": "variable",
          "name": "phone",
          "byref": false,
          "curly": false
        },
        "offset": {
          "kind": "string",
          "value": "Gordon",
          "isDoubleQuote": true
        }
      },
      "right": {
        "kind": "string",
        "value": "C49",
        "isDoubleQuote": true
      }
    }
  ],
  "errors": []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment