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

peg-cmake

v0.0.8

Published

PEG.js CMake parser

Downloads

7

Readme

peg-cmake

peg-cmake is a simple CMake parser written in javascript. It aims to provide a core lib for tools such as formatting, refactoring, etc...

The library is under developement and not stable.

Usage

npm install peg-cmake

var CMake = require('peg-cmake');
var fs = require('fs');

function traversAST(ast, matcher) {
   ast.forEach((element)=>{
       if(matcher[element.type])
       matcher[element.type](element);
   });
}

fs.readFile('CMakeLists.txt', 'utf8', function (err,data) {
 if (!err) {
   try {
       var ast = CMake.parse(data);
       // print all functions defined in the script
       function FunctionsVisitor() {
             this._func = (elt)=>{
              console.log("- " +elt.identifier + " : line:" + elt.location.start.line )
             }
             this.macro = this._func;
             this.function = this._func;
             this.if=(elt)=>{
               traversAST(elt.body, this);
               elt.elseif.foreach((e)=>{traversAST(elt.body, this);});      
               if(elt.else)traversAST(elt.else.body, this);
             }
       };
       traversAST(result, new FindFunctions());
   }catch(e) {
       console.log(e.name + " line " + e.location.start.line 
       + ", " + e.location.start.column
       + "\n"+ e.message);
   }
 }
});

AST

The the parse result is an array of node. Each node owns at least a type which can be one of the following :

  • "bracket_argument"
  • "bracket_comment"
  • "command_invocation"
  • "foreach"
  • "function"
  • "identifier"
  • "if"
  • "line_comment"
  • "macro"
  • "newline"
  • "quoted_argument"
  • "script"
  • "unquoted_argument"
  • "while"

and a location :

   {
       "start": {
           "offset": 31,
           "line": 1,
           "column": 32
       },
      "end": {
           "offset": 43,
           "line": 1,
           "column": 44
       }
   }

message("1st Arg\n" #[[Bracket Comment]] "2nd Arg")

Release notes

0.0.6

  • fix :
CMake versions prior to 2.8.12 silently accept an Unquoted Argument or a Quoted Argument immediately following a Quoted Argument and not separated by any whitespace. For compatibility, CMake 2.8.12 and higher accept such code but produce a warning.
  • add experimental cmake formater

Known Issues

  • Thes buffer must end with "\n", as a workaround the parse function append a new line to the buffer passed as argument.