From 00099849f687138f481142febb743636820f4210 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Mon, 4 Oct 2010 14:44:32 +0300 Subject: [PATCH] Initial parsing of doc-comments. Created DocComment class that strips all the asterisks from doc-comment, leaving only the real contents. --- doc.rb | 30 +++++++++++++++++++++++++++++- test.js | 1 - 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/doc.rb b/doc.rb index 08e48e92..5e26393e 100755 --- a/doc.rb +++ b/doc.rb @@ -42,7 +42,7 @@ class Lexer elsif @input.check(/\/\*\*/) then @tokens << { :type => :doc_comment, - :value => @input.scan_until(/\*\//) + :value => DocComment.new(@input.scan_until(/\*\//)) } elsif @input.check(/"/) then @tokens << { @@ -90,6 +90,33 @@ class Lexer end +class DocComment + def initialize(input) + @input = purify(input) + end + + # Extracts content inside /** ... */ + def purify(input) + result = [] + input.each_line do |line| + if line =~ /\A\/\*\*/ || line =~ /\*\/\Z/ then + # ignore first and last line + elsif line =~ /^ *\* ?(.*)\Z/ then + result << $1 + else + result << line + end + end + return result.join("\n") + end + + def to_s + @input + end +end + + + lex = Lexer.new($stdin.read) while !lex.empty? do if lex.look(:doc_comment) then @@ -106,6 +133,7 @@ while !lex.empty? do # name: function(){ puts "function " + lex.next end + puts else lex.next end diff --git a/test.js b/test.js index e2189fe8..16559d88 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,5 @@ /** * Creates new DateRange - * * @param {Date} beginDate * @param {Date} endDate */ -- GitLab