GithubHelp home page GithubHelp logo

iwatakeshi / mr-doc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mr-doc/mr-doc

1.0 2.0 0.0 4.39 MB

A personal source documenter at your service

Home Page: https://mr-doc.github.io/

License: MIT License

JavaScript 60.64% TypeScript 38.19% ANTLR 1.17%
language documentation generator comments typescript javascript grammar lexer parser scanner es5 documentation-tool

mr-doc's Introduction

Mr. Doc by Ben Matsuya

Artwork by Ben Matsuya.

Deps npm Build GitHub license npm

Mr. Doc

A personal source documenter at your service.

Updates

See UPDATES.md for recents updates about this project.

Architecture

1. Core Components

  • Berman (dependency generator/engine)
  • Tom (documentation syntax scanner and parser)
  • Mr. Doc (documentation generator)

2. Process

The goal of Mr. Doc is to simply generate documentation from a source. In addition, we want to make sure that only sources that are not listed as private are generated. As mentioned in the README, Mr. Doc will be using a familiar syntax for documenting your code.

To do so, we will use Berman to generate a dependecy graph and check whether a certain file should be included. This will also help us generate the hyperlinks between sources as well as generating a visual graph if needed. Once the graph is complete, we then proceed to Tom.

Tom will then generate an array of ASTs from the documentation syntax in the source codes and will pass that information to Mr. Doc.

Mr. Doc will have a compiler that will parse the source (i.e. Javascript) and will output the documentation (i.e. HTML). Note that the parser in Mr. Doc. is not the same as Tom. Tom only parses the documentation syntax which we can call it XDoc for now. Mr. Doc parses the actual source code and trims the code in question.

Mr. Doc

Berman

The logic behind Berman is to look each source file's import statements and determine which files does the source depend on. Using the dependency graph allows us to generate links between files.

Tom

Background

The concept of @ remains but the syntax will be a little different from JSDoc.

I've seen some pretty confusing (in my opinion) syntax such as @type {Array.<MyClass>} or @param {*} somebody and thought that there should be a natural way to express a type of array containing the instances of MyClass or a parameter named somebody that is a type of "whatever", respectively. So, I eventually came up with a syntax inspired by TypeScript and Swift, which is to define a type after a colon. Basically, adding the notion of a type-denoter to JSDoc/JavaDoc. Thus, we can convert our JSDoc comments to the following format:

/*
  @param {Array.<string>} names         → @param names: string[]
  @param {*} name                       → @param name: any
  @param {(any|string)} name            → @param name: any | string
  @param {string} [name]                → @param name?: string
  @param {???} [name = "Joe"]           → @param somebody: any | (string & number) = "Joe"
*/

Writing Documentation

The way documentation is written is mostly inspired by Rust. Proper and consistent documentation leads to better understanding of one's code and the purpose of the code. In Mr. Doc, we will follow Rust's concept of writing the documentation using Markdown. The documentation must begin with a summary or a short description of the code. It should also be punctuated properly.

[Use a single star block comment]
/*
    A car class.
    
    # API
    
    ```

    @class Car.
    @param make?: string - The maker of the car.
    @param year?: string - The year of the car.
    ```

    # Examples

    ```
    const car = new Car("Honda", "2019");
    car.honk();
    ```

*/

class Car {
    constructor(make, year) {
        this.make = make ? make : "";
        this.year = year ? year : "";
    }
    /*
        Moves the car toward a certain direction.

        # API
        
        ```
        @method run
        @param x: Number - The distance towards "x".
        @param y: Number - The distance towards "y".
        @param speed: Number - The speed of the car.
        ```
        
        # Examples

        ```
        car.run(10, 10, 50);
        ```

    */
    run (x, y, speed) {
        // ...
    }
    /*
      Slows down the car.

      # API

      ```
      @method brake
      @param pressure?: Number - The pressure to apply on the brake.
      ```

      # Examples

      ```
      car.brake(10)
      ```

      # Remark

      When no argument is passed, the default brake pressure is 5.
    */

   brake(pressure) {
     // ...
   }

}


/*
    An improved version of Car.
*/
class MySuperCar extends Car {

}

Grammar (Rough Draft)

See TomLexer.g4 and TomParser.g4 for a complete grammar.

mr-doc's People

Contributors

iwatakeshi avatar fgribreau avatar mattmcmanus avatar sdepold avatar scottnath avatar cliftonc avatar drewloomer avatar tarqd avatar jlauemoeller avatar orweinberger avatar hiddentao avatar seangarner avatar wojciak avatar llamerr avatar andban avatar evertton avatar leejt489 avatar trusktr avatar wondersloth avatar nicolasbrugneaux avatar rogernoble avatar gwagroves avatar jharwig avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

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.