Code Monkey home page Code Monkey logo

nodes's People

Contributors

kamicane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

kentaromiura

nodes's Issues

Would you consider working together towards a standard syntax for AST type description?

I've gotten a lot of mileage out of the def syntax I developed for my ast-types library: https://github.com/benjamn/ast-types/blob/master/def/core.js. It's definitely similar in spirit to your describe function, but I believe it has some advantages:

  • Multiple interface inheritance, so that e.g. a FunctionDeclaration can count as both a Function (a subtype of Node that serves as the common supertype of FunctionDeclaration, FunctionExpression, and ArrowFunctionExpression) and a Declaration (a subtype of Statement). This means instanceof no longer works, but it also means we can check subtype relationships in constant time, rather than having to traverse the prototype chain.
  • A single namespace for AST types, so that types can be more easily forward- and/or recursively-declared. For example, def("Identifier") is used many times before it is finally defined. Types are referred to by their string names using the def function, e.g. def("ObjectExpression"), and those types are cached by name, so you don't have to worry about passing around references to types, or accidentally creating multiple types with the same name.
  • The ability to define types incrementally, across multiple files. For example, the def("Function") type has only id, params, and body fields when first defined, but it incrementally acquires additional fields if you include the lib/es6.js or lib/es7.js files.
  • A way of providing defaults for properties that may be missing. For example, a TryStatement can have either a handler or handlers field, since there was some confusion between the Mozilla Parser API and Esprima about which was correct, and the other field will be automatically generated if need be.
  • Automatic generation of type-checked node builder functions (require("ast-types").builders), type checking functions (require("ast-types").namedTypes), and (hopefully soon) documentation. The sky is the limit here, once you have a good declarative syntax for defining the grammar.

The reason I think it would be worthwhile to settle on a standard syntax we can both use is that we have the opportunity to provide the only truly machine-executable specification of the ES6+ grammar. Esprima certainly doesn't capture all the necessary type requirements, the Mozilla Parser API is pretty far out of date at this point, and the ES6 grammar is scattered all over the specification document, is not directly useful for programming purposes, and doesn't really match the Esprima AST type system.

If we can settle on a common syntax (I'm happy to call it describe instead of def, if you prefer), and perhaps move the type descriptions into a standalone project, I'm confident our specification will become the most complete and useful reference for the grammar as it continues evolving.

What do you think?

All nodes

I need to have a list with all nodes or, alternatively, be able to query by position in the code, for example all the nodes which start between line 10 and 25.
It's possible to have any of these things?

Anyway thank you for this library!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.