npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nid-parser

v0.0.5

Published

NID (Native Interface Definition) is a portable C/C++ API description format that parses into JSON format for convenient bindings generation

Downloads

349

Readme

Note: this is preliminary (version 0.0.1) and will undergo serious changes, breaking in format etc. Open issues for suggestions, bug reports etc.

Native Interface Definition

NID is a subset of C/C++ and the concept is inspired by tolua++ tool for the LUA language. The idea is to write a simplified C/C++ header with additional attributes which should convey the higher-level purpose of the API.

This software provides a parser component written in Node.JS which parses .nid files into a JSON structure.

Couple of rules

  • Comments are stripped.
  • No preprocessor but #include <header> will be parsed and shown in JSON.
  • Function and variable declarations are parsed.
  • C++11 attributes are shown in JSON and can be used to improve the bindings.

Usage

As executable:

# npm install -g nid-parser
# nid input.nid

As dependency:

# npm install --save nid-parser
var nid = require('nid');
nid.parse(fs.readFileSync('sample.nid').toString('utf8'));

Example (taken from tests)

#include <stdio.h>
#include <math.h>

FILE* stdin;
FILE* stdout;

int some_random_integer;

namespace std {

  double sqrt(double x);
  float sqrtf(float x);
  long double sqrtl(long double x);
}

[[handle,free(fclose)]] FILE* fopen(const char* filename, const char* mode);

size_t fread([[cast(char*)]] void* ptr, size_t size, size_t nmemb, [[handle]] FILE* stream);

[[destructor]] int fclose(FILE* f);

class Rect {

  Rect(int x, int y, int w, int h);

  [[get(x)]] int x();
  [[set(x)]] void setX(int x);
  [[get(y)]] int y();
  [[set(y)]] void setY(int y);

  [[get(width)]] int width();
  [[set(width)]] void setWidth(int width);
  
  [[get(height)]] int height();
  [[set(height)]] void setHeight(int height);

  int area();

  static int sharedArea(Rect a, Rect b);
};

{
  "declarations": [
    {
      "pragma": "#include <stdio.h>"
    },
    {
      "pragma": "#include <math.h>"
    },
    {
      "variable": {
        "type": "FILE",
        "pointer": "*",
        "attributes": {},
        "name": "stdin"
      }
    },
    {
      "variable": {
        "type": "FILE",
        "pointer": "*",
        "attributes": {},
        "name": "stdout"
      }
    },
    {
      "variable": {
        "type": "int",
        "name": "some_random_integer",
        "attributes": {}
      }
    },
    {
      "namespace": {
        "name": "std",
        "declarations": [
          {
            "function": {
              "type": "double",
              "name": "sqrt",
              "attributes": {},
              "parameters": [
                {
                  "type": "double",
                  "name": "x",
                  "attributes": {}
                }
              ]
            }
          },
          {
            "function": {
              "type": "float",
              "name": "sqrtf",
              "attributes": {},
              "parameters": [
                {
                  "type": "float",
                  "name": "x",
                  "attributes": {}
                }
              ]
            }
          },
          {
            "function": {
              "type": "double long",
              "name": "sqrtl",
              "attributes": {},
              "parameters": [
                {
                  "type": "double long",
                  "name": "x",
                  "attributes": {}
                }
              ]
            }
          }
        ]
      }
    },
    {
      "variable": {
        "type": "FILE",
        "pointer": "*",
        "attributes": {
          "handle": true,
          "free": "fclose"
        },
        "name": "fopen",
        "parameters": [
          {
            "type": "const char",
            "pointer": "*",
            "attributes": {},
            "name": "filename"
          },
          {
            "type": "const char",
            "pointer": "*",
            "attributes": {},
            "name": "mode"
          }
        ]
      }
    },
    {
      "function": {
        "type": "size_t",
        "name": "fread",
        "attributes": {},
        "parameters": [
          {
            "type": "void",
            "pointer": "*",
            "attributes": {
              "cast": "char*"
            },
            "name": "ptr"
          },
          {
            "type": "size_t",
            "name": "size",
            "attributes": {}
          },
          {
            "type": "size_t",
            "name": "nmemb",
            "attributes": {}
          },
          {
            "type": "FILE",
            "pointer": "*",
            "attributes": {
              "handle": true
            },
            "name": "stream"
          }
        ]
      }
    },
    {
      "function": {
        "type": "int",
        "name": "fclose",
        "attributes": {
          "destructor": true
        },
        "parameters": [
          {
            "type": "FILE",
            "pointer": "*",
            "attributes": {},
            "name": "f"
          }
        ]
      }
    },
    {
      "class": {
        "name": "Rect",
        "declarations": [
          {
            "constructor": {
              "name": "Rect",
              "attributes": {},
              "parameters": [
                {
                  "type": "int",
                  "name": "x",
                  "attributes": {}
                },
                {
                  "type": "int",
                  "name": "y",
                  "attributes": {}
                },
                {
                  "type": "int",
                  "name": "w",
                  "attributes": {}
                },
                {
                  "type": "int",
                  "name": "h",
                  "attributes": {}
                }
              ]
            }
          },
          {
            "function": {
              "type": "int",
              "name": "x",
              "attributes": {
                "get": "x"
              },
              "parameters": []
            }
          },
          {
            "function": {
              "type": "void",
              "name": "setX",
              "attributes": {
                "set": "x"
              },
              "parameters": [
                {
                  "type": "int",
                  "name": "x",
                  "attributes": {}
                }
              ]
            }
          },
          {
            "function": {
              "type": "int",
              "name": "y",
              "attributes": {
                "get": "y"
              },
              "parameters": []
            }
          },
          {
            "function": {
              "type": "void",
              "name": "setY",
              "attributes": {
                "set": "y"
              },
              "parameters": [
                {
                  "type": "int",
                  "name": "y",
                  "attributes": {}
                }
              ]
            }
          },
          {
            "function": {
              "type": "int",
              "name": "width",
              "attributes": {
                "get": "width"
              },
              "parameters": []
            }
          },
          {
            "function": {
              "type": "void",
              "name": "setWidth",
              "attributes": {
                "set": "width"
              },
              "parameters": [
                {
                  "type": "int",
                  "name": "width",
                  "attributes": {}
                }
              ]
            }
          },
          {
            "function": {
              "type": "int",
              "name": "height",
              "attributes": {
                "get": "height"
              },
              "parameters": []
            }
          },
          {
            "function": {
              "type": "void",
              "name": "setHeight",
              "attributes": {
                "set": "height"
              },
              "parameters": [
                {
                  "type": "int",
                  "name": "height",
                  "attributes": {}
                }
              ]
            }
          },
          {
            "function": {
              "type": "int",
              "name": "area",
              "attributes": {},
              "parameters": []
            }
          },
          {
            "function": {
              "type": "int static",
              "name": "sharedArea",
              "attributes": {},
              "parameters": [
                {
                  "type": "Rect",
                  "name": "a",
                  "attributes": {}
                },
                {
                  "type": "Rect",
                  "name": "b",
                  "attributes": {}
                }
              ]
            }
          }
        ]
      }
    }
  ]
}