|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright (C) 2009 Yuto Hayamizu <[email protected]> |
| 4 | +# |
| 5 | +# This library is free software; you can redistribute it and/or |
| 6 | +# modify it under the terms of the GNU Lesser General Public |
| 7 | +# License version 2.1 as published by the Free Software Foundation. |
| 8 | +# |
| 9 | +# This library is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | +# Lesser General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU Lesser General Public |
| 15 | +# License along with this library; if not, write to the Free Software |
| 16 | +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | + |
| 18 | +# |
| 19 | +# This script expects "groonga.h" as a first argument, extracts the |
| 20 | +# 'grn_operator', and write 'rb_define_const's of 'grn_operator' to |
| 21 | +# standard outout. |
| 22 | +# |
| 23 | +# Usage: |
| 24 | +# ruby grnop2ruby.rb /path/to/groonga.h |
| 25 | +# |
| 26 | + |
| 27 | +replace_dictionary = { |
| 28 | + "VAR" => "VARIABLE", |
| 29 | + "EXPR" => "EXPRESSION", |
| 30 | + "NOP" => "NO_OPERATION", |
| 31 | + "REF" => "REFERENCE", |
| 32 | + "OBJ" => "OBJECT", |
| 33 | + "INCR" => "INCREMENT", |
| 34 | + "DECR" => "DECREMENT", |
| 35 | + "MOD" => "MODULO", |
| 36 | + "LCP" => "LONGEST_COMMON_PREFIX", |
| 37 | +} |
| 38 | + |
| 39 | +ARGF.each_line do |line| |
| 40 | + case line |
| 41 | + when /\A\s+(GRN_OP_\w+)/ |
| 42 | + operator = $1 |
| 43 | + rb_operator = operator.gsub(/\AGRN_OP_/, "").split("_").map{ |word| |
| 44 | + replace_dictionary[word] || word |
| 45 | + }.join("_") |
| 46 | + puts " rb_define_const(rb_mGrnOperation, \"%s\", |
| 47 | + UINT2NUM(%s));" % [rb_operator, operator] |
| 48 | + end |
| 49 | +end |
0 commit comments