Permalink
Browse files

Include patch that fixes parsing of multiline constant values.

  • Loading branch information...
1 parent 3a2ae66 commit 12b72ad2f68a9ebccbc2923c1681d1e93d74a7f1 designingpatts committed Sep 23, 2008
Showing with 58 additions and 5 deletions.
  1. +2 −1 History.txt
  2. +3 −3 lib/rdoc/parser/ruby.rb
  3. +53 −1 test/test_rdoc_parser_ruby.rb
View
@@ -9,10 +9,11 @@ to polish RDoc for Ruby 1.9.1.
* Z Bug Fixes
* Explicitly set the html template's text color, so that the generated
documentation will display correctly on browsers with custom text and
- background color settings (thanks to Luther Thompson).
+ background color settings (patch by Luther Thompson).
* Ensure that RDoc correctly will associate an alias and a method, even
if it encounters the alias first because the alias lives in a different
file.
+ * Fix the parsing of multiline constants (patch by Chris Alfeld and Joel VanderWerf)
=== 2.2.0 / 2008-09-19
This version includes some significant enhancements to ri. See RI.txt for
View
@@ -1945,17 +1945,17 @@ def parse_constant(container, single, tk, comment)
case tk
when TkSEMICOLON
break
- when TkLPAREN, TkfLPAREN
+ when TkLPAREN, TkfLPAREN, TkLBRACE, TkLBRACK, TkDO
nest += 1
- when TkRPAREN
+ when TkRPAREN, TkRBRACE, TkRBRACK, TkEND
nest -= 1
when TkCOMMENT
if nest <= 0 && @scanner.lex_state == EXPR_END
unget_tk(tk)
break
end
when TkNL
- if (@scanner.lex_state == EXPR_END and nest <= 0) || !@scanner.continue
+ if (nest <= 0) && ((@scanner.lex_state == EXPR_END) || (!@scanner.continue))
unget_tk(tk)
break
end
@@ -535,7 +535,59 @@ def foo()
assert_equal 'foo4', foo4.name
assert_equal 'foo', foo4.is_alias_for.name
- assert_equal @top_level.classes.first.aliases[0].old_name, "unknown"
+ assert_equal 'unknown', @top_level.classes.first.aliases[0].old_name
+ end
+
+ def test_parse_statements_identifier_constant
+ content = <<-EOF
+class Foo
+ FIRST_CONSTANT = 5
+
+ SECOND_CONSTANT = [
+ 1,
+ 2,
+ 3
+ ]
+
+ THIRD_CONSTANT = {
+ :foo => 'bar',
+ :x => 'y'
+ }
+
+ FOURTH_CONSTANT = SECOND_CONSTANT.map do |element|
+ element + 1
+ element + 2
+ end
+
+ FIFTH_CONSTANT = SECOND_CONSTANT.map { |element| element + 1 }
+end
+EOF
+
+ util_parser content
+
+ @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
+
+ constants = @top_level.classes.first.constants
+
+ constant = constants[0]
+ assert_equal 'FIRST_CONSTANT', constant.name
+ assert_equal '5', constant.value
+
+ constant = constants[1]
+ assert_equal 'SECOND_CONSTANT', constant.name
+ assert_equal '[ 1, 2, 3 ]', constant.value
+
+ constant = constants[2]
+ assert_equal 'THIRD_CONSTANT', constant.name
+ assert_equal "{ :foo => 'bar', :x => 'y' }", constant.value
+
+ constant = constants[3]
+ assert_equal 'FOURTH_CONSTANT', constant.name
+ assert_equal 'SECOND_CONSTANT.map do |element| element + 1 element + 2 end', constant.value
+
+ constant = constants.last
+ assert_equal 'FIFTH_CONSTANT', constant.name
+ assert_equal 'SECOND_CONSTANT.map { |element| element + 1 }', constant.value
end
def test_parse_statements_identifier_attr

0 comments on commit 12b72ad

Please sign in to comment.