Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/Tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ having exactly those 3 elements) would be listed as: `Array(String, Fixnum, Hash
Some literals are accepted by virtue of being Ruby literals, but also by YARD
conventions. Here is a non-exhaustive list of certain accepted literal values:

* `true`, `false`, `nil` — used when a method returns these explicit literal
values. Note that if your method returns both `true` or `false`, you should use
the `Boolean` conventional type instead.
* `true`, `false`, `nil`, `:foo` — used when a method returns
these explicit literal values. Note that if your method returns both
`true` or `false`, you should use the `Boolean` conventional type
instead.
* `self` — has the same meaning as Ruby's "self" keyword in the context of
parameters or return types. Recommended mostly for {tag:return} tags that are
chainable.
Expand Down Expand Up @@ -280,4 +281,3 @@ Note that you might not need a tag title if you are hiding it. The title
part can be omitted.

{yard:include_tags}

6 changes: 4 additions & 2 deletions lib/yard/code_objects/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def push(value)
# Regular expression to match namespaces (const A or complex path A::B)
NAMESPACEMATCH = /(?:(?:#{NSEPQ}\s*)?#{CONSTANTMATCH})+/

# Regular expression to match a method name
METHODNAMEMATCH = %r{[a-zA-Z_]\w*[!?=]?|[-+~]\@|<<|>>|=~|===?|![=~]?|<=>|[<>]=?|\*\*|[-/+%^&*~`|]|\[\]=?}
# Regular expression to match an identifier like a variable or method name
IDENTIFIERMATCH = %r{[a-zA-Z_]\w*[!?=]?|[-+~]\@|<<|>>|=~|===?|![=~]?|<=>|[<>]=?|\*\*|[-/+%^&*~`|]|\[\]=?}

METHODNAMEMATCH = IDENTIFIERMATCH

# Regular expression to match a fully qualified method def (self.foo, Class.foo).
METHODMATCH = /(?:(?:#{NAMESPACEMATCH}|[a-z]\w*)\s*(?:#{CSEPQ}|#{NSEPQ})\s*)?#{METHODNAMEMATCH}/
Expand Down
3 changes: 2 additions & 1 deletion lib/yard/tags/types_explainer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Parser
:fixed_collection_start => /\(/,
:fixed_collection_end => /\)/,
:type_name => /#{ISEP}#{METHODNAMEMATCH}|#{NAMESPACEMATCH}|\w+/,
:symbol => /:#{IDENTIFIERMATCH}/,
:type_next => /[,;]/,
:whitespace => /\s+/,
:hash_collection_start => /\{/,
Expand Down Expand Up @@ -130,7 +131,7 @@ def parse
next unless (match.nil? && @scanner.eos?) || (match && token = @scanner.scan(match))
found = true
case token_type
when :type_name
when :type_name, :symbol
raise SyntaxError, "expecting END, got name '#{token}'" if name
name = token
when :type_next
Expand Down
9 changes: 9 additions & 0 deletions spec/docstring_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ def foo(a) end
eof
end

it "does not warn on constant values" do
expect(log).to_not receive(:warn)
YARD.parse_string <<-eof
# @param [false, true, nil, 4, :foo] a
# @return [void]
def self.bar(a); end
eof
end

it "warns on mismatching param with inline method modifier" do
expect(log).to receive(:warn).with(/@param tag has unknown parameter name: notaparam/)
YARD.parse_string <<-eof
Expand Down
7 changes: 6 additions & 1 deletion spec/tags/types_explainer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def parse_fail(types)
end

it "works for a constant value" do
['false', 'true', 'nil', '4'].each do |name|
['false', 'true', 'nil', '4', ':foo'].each do |name|
@t.name = name
expect(@t.to_s).to eq name
expect(@t.to_s(false)).to eq name
Expand Down Expand Up @@ -154,6 +154,11 @@ def parse_fail(types)
expect(type.first.name).to eq "Hash"
end

it "parses constant values" do
type = parse("false, true, nil, 4, :foo")
expect(type.map(&:name)).to eq ['false', 'true', 'nil', '4', ':foo']
end

it "does not accept two commas in a row" do
parse_fail "A,,B"
end
Expand Down
Loading