ruby_sexpr_parser.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Flexlay - A Generic 2D Game Editor
  2. // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program 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
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include "lispreader.hpp"
  17. #include "ruby_sexpr_parser.hpp"
  18. VALUE
  19. build_py_sexpr(lisp_object_t* cur)
  20. {
  21. if (lisp_cons_p(cur))
  22. {
  23. VALUE lst = rb_ary_new();
  24. while (cur)
  25. {
  26. rb_ary_push(lst, build_py_sexpr(lisp_car(cur)));
  27. cur = lisp_cdr(cur);
  28. }
  29. return lst;
  30. }
  31. else if (lisp_string_p(cur))
  32. {
  33. return rb_str_new2(lisp_string(cur));
  34. }
  35. else if (lisp_symbol_p(cur))
  36. {
  37. return ID2SYM(rb_intern(lisp_symbol(cur)));
  38. }
  39. else if (lisp_integer_p(cur))
  40. {
  41. return INT2NUM(lisp_integer(cur));
  42. }
  43. else if (lisp_real_p(cur))
  44. {
  45. return rb_float_new(lisp_real(cur));
  46. }
  47. else if (lisp_boolean_p(cur))
  48. {
  49. if (lisp_boolean(cur))
  50. return Qtrue;
  51. else
  52. return Qfalse;
  53. }
  54. else
  55. {
  56. return Qnil;
  57. }
  58. }
  59. VALUE sexpr_read_from_file(const char* filename)
  60. {
  61. lisp_object_t* cur = lisp_read_from_file(filename);
  62. if (cur)
  63. {
  64. VALUE obj = build_py_sexpr(cur);
  65. lisp_free(cur);
  66. return obj;
  67. }
  68. else
  69. {
  70. return Qnil;
  71. }
  72. }
  73. /* EOF */