PageRenderTime 64ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/ob-brainfuck.el

https://bitbucket.org/ArneBab/.emacs.d
Emacs Lisp | 77 lines | 34 code | 14 blank | 29 comment | 0 complexity | 4284adff5d2f138f055e639bb93f8861 MD5 | raw file
Possible License(s): GPL-2.0
  1. ;;; ob-brainfuck.el --- org-babel functions for brainfuck evaluation
  2. ;; Copyright (C) 2009-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric Schulte and Arne Babenhauserheide
  4. ;; Keywords: literate brainfuck
  5. ;; Homepage: http://draketo.de
  6. ;; Version: 0.01
  7. ;;; License:
  8. ;; This program is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 3, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;; Commentary:
  23. ;; This code is heavily based on ob-dot.el from org-mode. Heavily
  24. ;; based as in (query-replace dot brainfuck) + some deleted lines and
  25. ;; removed options.
  26. ;;; Requirements:
  27. ;; dev-lang/bff - a brainfuck interpreter named bff
  28. ;;; Code:
  29. (require 'ob)
  30. (require 'ob-eval)
  31. (defvar org-babel-default-header-args:brainfuck
  32. '((:results . "output") (:exports . "results"))
  33. "Default arguments to use when evaluating a brainfuck source block.")
  34. (defun org-babel-expand-body:brainfuck (body params)
  35. "Expand BODY according to PARAMS, return the expanded body."
  36. (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
  37. (mapc
  38. (lambda (pair)
  39. (let ((name (symbol-name (car pair)))
  40. (value (cdr pair)))
  41. (setq body
  42. (replace-regexp-in-string
  43. (concat "\$" (regexp-quote name))
  44. (if (stringp value) value (format "%S" value))
  45. body))))
  46. vars)
  47. body))
  48. (defun org-babel-execute:brainfuck (body params)
  49. "Execute a block of Brainfuck code with org-babel.
  50. This function is called by `org-babel-execute-src-block'."
  51. (let* ((result-params (cdr (assoc :result-params params)))
  52. (cmd (or (cdr (assoc :cmd params)) "bff"))
  53. (in-file (org-babel-temp-file "brainfuck-")))
  54. (with-temp-file in-file
  55. (insert (org-babel-expand-body:brainfuck body params)))
  56. (org-babel-eval
  57. (concat cmd
  58. " " (org-babel-process-file-name in-file)) "")))
  59. (defun org-babel-prep-session:brainfuck (session params)
  60. "Return an error because Brainfuck does not support sessions."
  61. (error "Brainfuck does not support sessions"))
  62. (provide 'ob-brainfuck)
  63. ;;; ob-brainfuck.el ends here