jsduck 3.11.2 → 4.0.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +0,0 @@
1
- module JsDuck
2
-
3
- # Takes output of JsLiteralParser and converts it to string
4
- class JsLiteralBuilder
5
-
6
- # Converts literal object definition to string
7
- def to_s(lit)
8
- if lit[:type] == :string
9
- '"' + lit[:value] + '"'
10
- elsif lit[:type] == :array
11
- "[" + lit[:value].map {|v| to_s(v) }.join(", ") + "]"
12
- elsif lit[:type] == :object
13
- "{" + lit[:value].map {|v| to_s(v[:key]) + ": " + to_s(v[:value]) }.join(", ") + "}"
14
- else
15
- lit[:value]
16
- end
17
- end
18
-
19
- end
20
-
21
- end
@@ -1,106 +0,0 @@
1
- require 'jsduck/lexer'
2
-
3
- module JsDuck
4
-
5
- # Parser for JavaScript literals: numbers, strings, booleans,
6
- # regexes, arrays, objects.
7
- #
8
- # Almost like a JSON parser, but regexes are also valid values and
9
- # object keys don't need to be quoted.
10
- class JsLiteralParser
11
- def initialize(input)
12
- @lex = Lexer.new(input)
13
- end
14
-
15
- # Parses a literal.
16
- #
17
- # Returns a Ruby hash representing this literal. For example parsing this:
18
- #
19
- # [5, "foo"]
20
- #
21
- # Returns the following structure:
22
- #
23
- # {:type => :array, :value => [
24
- # {:type => :number, :value => "5"},
25
- # {:type => :string, :value => "foo"}
26
- # ]}
27
- #
28
- def literal
29
- if look(:number)
30
- match(:number)
31
- elsif look(:string)
32
- match(:string)
33
- elsif look(:regex)
34
- match(:regex)
35
- elsif look("[")
36
- array_literal
37
- elsif look("{")
38
- object_literal
39
- elsif look(:ident) && (look("true") || look("false") || look("undefined") || look("null"))
40
- match(:ident)
41
- end
42
- end
43
-
44
- def array_literal
45
- match("[")
46
- r = []
47
- while (lit = literal)
48
- r << lit
49
- break unless look(",")
50
- match(",")
51
- end
52
- return unless look("]")
53
- match("]")
54
- return {:type => :array, :value => r}
55
- end
56
-
57
- def object_literal
58
- match("{")
59
- r = []
60
- while (look(:ident) || look(:string))
61
- lit = object_literal_pair
62
- return unless lit
63
- r << lit
64
- break unless look(",")
65
- match(",")
66
- end
67
-
68
- return unless look("}")
69
- match("}")
70
- return {:type => :object, :value => r}
71
- end
72
-
73
- def object_literal_pair
74
- if look(:ident)
75
- key = match(:ident)
76
- elsif look(:string)
77
- key = match(:string)
78
- end
79
-
80
- return unless look(":")
81
- match(":")
82
-
83
- value = literal
84
- return unless value
85
-
86
- return {:key => key, :value => value}
87
- end
88
-
89
- # Matches all arguments, returns the value of last match
90
- # When the whole sequence doesn't match, throws exception
91
- def match(*args)
92
- if look(*args)
93
- last = nil
94
- args.length.times { last = @lex.next(true) }
95
- last
96
- else
97
- throw "Expected: " + args.join(", ")
98
- end
99
- end
100
-
101
- def look(*args)
102
- @lex.look(*args)
103
- end
104
- end
105
-
106
- end
@@ -1,14 +0,0 @@
1
- require "jsduck/meta_tag"
2
-
3
- module JsDuck::Tag
4
- # Implementation of @chainable tag
5
- class Chainable < JsDuck::MetaTag
6
- def initialize
7
- @name = "chainable"
8
- @key = :chainable
9
- @signature = {:long => "chainable", :short => "&gt;"} # show small right-arrow
10
- @boolean = true
11
- end
12
- end
13
- end
14
-