[Groonga-commit] groonga/groonga-command at 9f121f8 [fix-travis-ci-error] Support comment

アーカイブの一覧に戻る

Kouhei Sutou null+****@clear*****
Wed Jan 13 17:18:38 JST 2016


Kouhei Sutou	2012-11-27 16:31:57 +0900 (Tue, 27 Nov 2012)

  New Revision: 9f121f876ef3fbce441288d25c527932ed6f3172
  https://github.com/groonga/groonga-command/commit/9f121f876ef3fbce441288d25c527932ed6f3172

  Message:
    Support comment

  Modified files:
    lib/groonga/command/parser.rb
    test/test-parser.rb

  Modified: lib/groonga/command/parser.rb (+29 -6)
===================================================================
--- lib/groonga/command/parser.rb    2012-11-27 11:18:17 +0900 (c947345)
+++ lib/groonga/command/parser.rb    2012-11-27 16:31:57 +0900 (705d137)
@@ -68,6 +68,9 @@ module Groonga
           parser.on_load_complete do |command|
             yield(:on_load_complete, command)
           end
+          parser.on_comment do |comment|
+            yield(:on_comment, comment)
+          end
 
           consume_data(parser, data)
         end
@@ -118,7 +121,7 @@ module Groonga
           raise ParseError, "not completed"
         else
           catch do |tag|
-            consume_command(tag, @buffer)
+            parse_line(@buffer)
           end
         end
       end
@@ -163,6 +166,16 @@ module Groonga
         end
       end
 
+      # @overload on_comment(comment)
+      # @overload on_comment {|comment| }
+      def on_comment(*arguments, &block)
+        if block_given?
+          @on_comment_hook = block
+        else
+          @on_comment_hook.call(*arguments) if @on_comment_hook
+        end
+      end
+
       private
       def consume_buffer
         catch do |tag|
@@ -170,7 +183,7 @@ module Groonga
             if @loading
               consume_load_values(tag)
             else
-              consume_command(tag, consume_line(tag))
+              parse_line(consume_line(tag))
             end
           end
         end
@@ -248,9 +261,19 @@ module Groonga
         end
       end
 
-      def consume_command(tag, line)
-        @command = parse(line)
-        @command.original_source = line
+      def parse_line(line)
+        case line
+        when /\A\s*\z/
+        when /\A\#/
+          on_comment($POSTMATCH)
+        else
+          @command = parse_command(line)
+          @command.original_source = line
+          process_command
+        end
+      end
+
+      def process_command
         if****@comma***** == "load"
           on_load_start(@command)
           if @command[:values]
@@ -270,7 +293,7 @@ module Groonga
         end
       end
 
-      def parse(input)
+      def parse_command(input)
         if input.start_with?("/d/")
           parse_uri_path(input)
         else

  Modified: test/test-parser.rb (+26 -0)
===================================================================
--- test/test-parser.rb    2012-11-27 11:18:17 +0900 (ee4a49b)
+++ test/test-parser.rb    2012-11-27 16:31:57 +0900 (6d617bd)
@@ -193,6 +193,32 @@ EOC
           assert_equal(expected_events, @events)
         end
       end
+
+      class CommentTest < self
+        def test_newline
+          parsed_comment = nil
+          @parser.on_comment do |comment|
+            parsed_comment = comment
+          end
+
+          @parser << "# status"
+          assert_nil(parsed_comment)
+          @parser << "\n"
+          assert_equal(" status", parsed_comment)
+        end
+
+        def test_finish
+          parsed_comment = nil
+          @parser.on_comment do |comment|
+            parsed_comment = comment
+          end
+
+          @parser << "# status"
+          assert_nil(parsed_comment)
+          @parser.finish
+          assert_equal(" status", parsed_comment)
+        end
+      end
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る