Giter Club home page Giter Club logo

doc-parser's Introduction

DocBlock & Annotations Parser

npm version Build Status Coverage Status XO code style Gitter

This library is a javascript LALR(1) parser that parses docblocks and extracts annotations under an structured syntax tree.

Install

npm install doc-parser --save

And simple usage :

var DocParser = require('doc-parser');
var reader = new DocParser();
var data = reader.parse('/** @hello world */');

Supported syntaxes

/**
 * Some description
 * @return boolean
 * @return map<string, SomeClass>
 * @author Ioan CHIRIAC <[email protected]>
 * @throws Exception
 * @deprecated
 * @table('tableName', true)
 * @table(
 *   name='tableName',
 *   primary=true
 * )
 * @annotation1 @annotation2
 * @Target(["METHOD", "PROPERTY"])
 * @Attributes([
 *   @Attribute("stringProperty", type = "string"),
 *   @Attribute("annotProperty",  type = "SomeAnnotationClass"),
 * ])
 * @json({
 *   "key": "value",
 *   "object": { "inner": true },
 *   "list": [1, 2, 3]
 * })
 * <node>
 * Some inner multi line content
 * </node>
 */

AST structure

{
  kind: 'doc',
  summary: 'Some description retrieved from the first line of the coment',
  body: [
    {
      kind: 'return',
      type: 'void',
      description: 'Some extra informations'
    }
  ]
}

Declaring custom doc blocks

By default, doc-parser supports @return,@param,@throws and @deprecated doc blocks.

You can extend the support to any doc block :

// lets handle @global (type) (var) (description)
var DocParser = require('doc-parser');
var reader = new DocParser({
  'global': [
    {
      property: 'type',
      parser: 'type',
      optional: true
    },
    {
      property: 'what',
      parser: 'variable',
      optional: true
    },
    {
      property: 'description',
      parser: 'text',
      optional: true,
      default: ''
    }
  ]
});
var data = reader.parse('/** @global string some description */');

This will result in a new kind of doc block with the specified properties. Here a list of supported parsers :

  • type : a simple type, class name, or array of types
  • variable : a variable name
  • text : a line of text (will eat every token until the current line ends)
  • version: a semantic version
  • array : an array of items
  • object : a json object definition
  • boolean : a boolean
  • number : a number (integer or float)
  • string : a simple or double quoted text

Misc

This library is released under BSD-3 license clause.

doc-parser's People

Contributors

ichiriac 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.