UNPKG

6.29 kBMarkdownView Raw
1doctrine ([doctrine](http://github.com/Constellation/doctrine)) is JSDoc parser. [![Build Status](https://secure.travis-ci.org/Constellation/doctrine.png)](http://travis-ci.org/Constellation/doctrine)
2
3It is now used by content assist system of [Eclipse Orion](http://www.eclipse.org/orion/) ([detail](http://planetorion.org/news/2012/10/orion-1-0-release/))
4
5Doctrine can be used in a web browser:
6
7 <script src="doctrine.js"></script>
8
9or in a Node.js application via the package manager:
10
11 npm install doctrine
12
13simple example:
14
15 doctrine.parse(
16 [
17 "/**",
18 " * This function comment is parsed by doctrine",
19 " * @param {{ok:String}} userName",
20 "*/"
21 ].join('\n'), { unwrap: true });
22
23and gets following information
24
25 {
26 "description": "This function comment is parsed by doctrine",
27 "tags": [
28 {
29 "title": "param",
30 "description": null,
31 "type": {
32 "type": "RecordType",
33 "fields": [
34 {
35 "type": "FieldType",
36 "key": "ok",
37 "value": {
38 "type": "NameExpression",
39 "name": "String"
40 }
41 }
42 ]
43 },
44 "name": "userName"
45 }
46 ]
47 }
48
49see [demo page](http://constellation.github.com/doctrine/demo/index.html) more detail.
50
51### Options
52
53#### doctrine.parse
54We can pass options to `doctrine.parse(comment, options)`.
55```js
56{
57 unwrap: boolean, // default: false
58 tags: [ string ] | null, // default: null
59 recoverable: boolean, // default: false
60 sloppy: boolean, // default: false
61 lineNumbers: boolean // default: false
62}
63```
64
65##### unwrap
66
67When `unwrap` is `true`, doctrine attempt to unwrap comment specific string from a provided comment text. (removes `/**`, `*/` and `*`)
68For example, `unwrap` transforms
69```
70/**
71 * @param use
72 */
73```
74to
75```
76@param use
77```
78If a provided comment has these comment specific strings, you need to specify this `unwrap` option to `true`.
79
80##### tags
81
82When `tags` array is specified, doctrine only produce tags that is specified in this array.
83For example, if you specify `[ 'param' ]`, doctrine only produces `param` tags.
84If null is specified, doctrine produces all tags that doctrine can recognize.
85
86##### recoverable
87
88When `recoverable` is `true`, doctrine becomes `recoverable` - When failing to parse jsdoc comment, doctrine recovers its state and attempt to continue parsing.
89
90##### sloppy
91
92When `sloppy` is `true`,
93```
94@param String [foo]
95```
96's `[foo]` is interpreted as a optional parameter, not interpreted as a name of this `@param`.
97
98##### lineNumbers
99
100When `lineNumbers` is `true`, parsed tags will include a `lineNumber` property indicating the line (relative to the start of the comment block) where each tag is located in the source. So, given the following comment:
101```
102/**
103 * @param {String} foo
104 * @return {number}
105 */
106```
107The `@param` tag will have `lineNumber: 1`, and the `@return` tag will have `lineNumber: 2`.
108
109
110### License
111
112#### doctrine
113
114Copyright (C) 2012 [Yusuke Suzuki](http://github.com/Constellation)
115 (twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors.
116
117Redistribution and use in source and binary forms, with or without
118modification, are permitted provided that the following conditions are met:
119
120 * Redistributions of source code must retain the above copyright
121 notice, this list of conditions and the following disclaimer.
122
123 * Redistributions in binary form must reproduce the above copyright
124 notice, this list of conditions and the following disclaimer in the
125 documentation and/or other materials provided with the distribution.
126
127THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
128AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
129IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
130ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
131DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
132(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
133LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
134ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
135(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
136THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
137
138#### esprima
139
140some of functions is derived from esprima
141
142Copyright (C) 2012, 2011 [Ariya Hidayat](http://ariya.ofilabs.com/about)
143 (twitter: [@ariyahidayat](http://twitter.com/ariyahidayat)) and other contributors.
144
145Redistribution and use in source and binary forms, with or without
146modification, are permitted provided that the following conditions are met:
147
148 * Redistributions of source code must retain the above copyright
149 notice, this list of conditions and the following disclaimer.
150
151 * Redistributions in binary form must reproduce the above copyright
152 notice, this list of conditions and the following disclaimer in the
153 documentation and/or other materials provided with the distribution.
154
155THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
156AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
157IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
158ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
159DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
160(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
161LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
162ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
163(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
164THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
165
166
167#### closure-compiler
168
169some of extensions is derived from closure-compiler
170
171Apache License
172Version 2.0, January 2004
173http://www.apache.org/licenses/