去除C语言注释

2015-06-23 0 141
去除C语言注释
require 'strscan'

lex = [/"[^\\"]*(?:\\.[^\\"]*)*"/m,    # string
       /'[^\\']*(?:\\.[^\\']*)*'/m,    # char
       /\/\*.*?\*\//m,                 # multi-line
       /\/\/(?:.*?\\(?:\r?\n|\r))*.*/, # single-line
       /.|\s+/]                        # rest

ARGV.each do |source|
  stream = StringScanner.new File.read source
  until stream.eos? do
    code = stream.scan lex.find {|regex| stream.match? regex}
    print code unless code.start_with?('//') || code.start_with?('/*')
  end
end

遇见资源网 ruby 去除C语言注释 http://www.ox520.com/16375.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务