File indexing completed on 2024-05-19 08:27:31
0001 ## 0002 # This file is part of KDevelop 0003 # Copyright (C) 2011-2015 Miquel Sabaté Solà <mikisabate@gmail.com> 0004 # 0005 # This program is free software: you can redistribute it and/or modify 0006 # it under the terms of the GNU General Public License as published by 0007 # the Free Software Foundation, either version 3 of the License, or 0008 # (at your option) any later version. 0009 # 0010 # This program is distributed in the hope that it will be useful, 0011 # but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 # GNU General Public License for more details. 0014 # 0015 # You should have received a copy of the GNU General Public License 0016 # along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 0018 0019 #!/usr/bin/env ruby 0020 0021 # 0022 # Prints the output of the parser in a "fancy" way, translating the numbers 0023 # shown at the expected output of the tests to words for mere mortals. This 0024 # script does the job by executing the parser on a given test and flushing 0025 # its output to a temporary file. Then it does the transalation in a simple way 0026 # and shows the output to the user. 0027 # NOTE: To use it, for example, just type "ruby fancy.rb test.rb" 0028 # to execute "tests/test.rb" ;) 0029 # 0030 0031 # Only execute this script if the user provided a name 0032 exit if ARGV[0].nil? 0033 0034 translate = [ 0035 'whitespace', 'comment', 'plus', 'minus', 'mul', 'pow', 'div', 'mod', 'bit_and', 'bit_or', 'bit_xor', 0036 'kw_and', 'kw_or', 'kw_not', 'or', 'and', 'lshift', 'rshift', 'neg', 'not', 'unary_plus', 0037 'unay_minus', 'assign', 'op_assign', 'assoc', 'cmp', 'eq', 'neq', 'eqq', 'match', 'nmatch', 0038 'greater', 'geq', 'lesser', 'leq', 'dot2', 'dot3', 'ternary', 'if', 'unless', 'while', 0039 'until', 'case', 'when', 'BEGIN', 'END', 'for', 'begin', 'rescue_arg', 'rescue', 'ensure', 0040 'object', 'numeric', 'symbol', 'body', 'function', 'module', 'class', 'singleton_class', 'super', 'string', 0041 'regexp', 'key', 'array', 'hash', 'block', 'method_call', 'heredoc', 'break', 'redo', 'retry', 0042 'next', 'return', 'yield', 'alias', 'defined', 'undef', 'array_value', '__END__', 'true', 'false', 0043 'nil', 'self', '__ENCODING__', '__FILE__', '__LINE__' 0044 ] 0045 0046 output = `../ruby-parser tests/#{ARGV.first}.rb` 0047 output.split("\n").each do |l| 0048 line = l.gsub(/[0-9]+(\[)/) { |m| "#{translate[m.to_i]}[" } 0049 puts line.gsub(/[0-9]+(\()/) { |m| "#{translate[m.to_i]}(" } 0050 end