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

filbert

v0.1.20

Published

Python parser, Mozilla AST output

Downloads

4,730

Readme

Filbert

JavaScript-based Python parser. Outputs an abstract syntax tree as specified by the Mozilla Parser API.

This parser is a work in progress, adapted from the JavaScript parser Acorn.

Check out the demo page to see what Filbert can do.

Want to contribute?

Thank you, we really appreciate you taking the time to help!

Filbert is under active development at https://github.com/differentmatt/filbert. Please submit pull requests or file GitHub issues to that repository. You can also email Matt.

Installation

npm install filbert

Components

When run in a CommonJS (node.js) or AMD environment, exported values appear in the interfaces exposed by the individual files, as usual. When loaded in the browser without any kind of module management, a single global object filbert will be defined, and all the exported properties will be added to that.

filbert.js

This file contains the actual parser (and is what you get when you require("filbert") in node.js).

parse(input, options) is used to parse a Python program. The input parameter is a string, options can be undefined or an object setting some of the options listed below. The return value will be an abstract syntax tree object as specified by the Mozilla Parser API.

When encountering a syntax error, the parser will raise a SyntaxError object with a meaningful message. The error object will have a pos property that indicates the character offset at which the error occurred, and a loc object that contains a {line, column} object referring to that same position.

  • locations: When true, each node has a loc object attached with start and end subobjects, each of which contains the one-based line and zero-based column numbers in {line, column} form. Default is false.

  • ranges: To add a semi-standardized "range" property holding a [start, end] array with the same numbers, set the ranges option to true.

pythonRuntime holds an object required to execute JavaScript code that has been generated from the output AST. (e.g. the builtin len() function is not native to JavaScript). This object must be available if the AST output from parse will be used to generate and execute JavaScript code.

runtimeParamName name of the python runtime object that will be referenced in the output AST. (e.g. if set to '__pythonRuntime', AST nodes will have references to a '__pythonRuntime' object).

tokenize(input, options) exports a primitive interface to Filbert's tokenizer. The function takes an input string and options similar to parse, and returns a function that can be called repeatedly to read a single token, and returns a {start, end, type, value} object (with added startLoc and endLoc properties when the locations option is enabled). This object will be reused (updated) for each token, so you can't count on it staying stable.

tokTypes holds an object mapping names to the token type objects that end up in the type properties of tokens.

filbert_loose.js

This file implements an error-tolerant parser. It exposes a single function.

parse_dammit(input, options) takes the same arguments and returns the same syntax tree as the parse function in filbert.js, but never raises an error, and will do its best to parse syntactically invalid code in as meaningful a way as it can. It'll insert identifier nodes with name "✖" as placeholders in places where it can't make sense of the input. Depends on filbert.js, because it uses the same tokenizer.

Language Support

Python3 is the target language. Much of it is working, and the remaining pieces are outlined below.

Supported

Keywords:

False None True and break class continue def elif else for if in is not or pass return while

Built-ins:

abs() all() any() ascii() bool() chr() dict() enumerate() filter() float() hex() int() len() list() map() max() min() oct() ord() pow() print() range() repr() reversed() round() sorted() str() sum() tuple()

Coming Soon!

Keywords:

as assert del except finally from import global lambda nonlocal raise try with yield

Built-ins:

bin() bytearray() bytes() callable() classmethod() compile() complex() delattr() dir() divmod() eval() exec() format() frozenset() getattr() globals() hasattr() hash() help() id() input() isinstance() issubclass() iter() locals() memoryview() next() object() open() property() set() setattr() slice() staticmethod() super() type() vars() zip() _import_()

Testing

grunt test

Get in touch

Please use the GitHub issues, or email Matt