1 ;;; ob-ebnf.el --- org-babel functions for ebnf evaluation
3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
5 ;; Author: Michael Gauland
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
12 ;; This program is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;;; Org-Babel support for using ebnf2ps to generate encapsulated postscript
30 ;;; railroad diagrams. It recogises these arguments:
32 ;;; :file is required; it must include the extension '.eps.' All the rules
33 ;;; in the block will be drawn in the same file. This is done by
34 ;;; inserting a '[<file>' comment at the start of the block (see the
35 ;;; documentation for ebnf-eps-buffer for more information).
37 ;;; :style specifies a value in ebnf-style-database. This provides the
38 ;;; ability to customise the output. The style can also specify the
39 ;;; grammar syntax (by setting ebnf-syntax); note that only ebnf,
40 ;;; iso-ebnf, and yacc are supported by this file.
48 ;; optionally declare default header arguments for this language
49 (defvar org-babel-default-header-args
:ebnf
'((:style . nil
)))
51 ;; Use ebnf-eps-buffer to produce an encapsulated postscript file.
53 (defun org-babel-execute:ebnf
(body params
)
54 "Execute a block of Ebnf code with org-babel. This function is
55 called by `org-babel-execute-src-block'"
57 (let* ((dest-file (cdr (assoc :file params
)))
58 (dest-dir (file-name-directory dest-file
))
59 (dest-root (file-name-sans-extension
60 (file-name-nondirectory dest-file
)))
61 (dest-ext (file-name-extension dest-file
))
62 (style (cdr (assoc :style params
)))
63 (current-dir default-directory
)
66 (when style
(ebnf-push-style style
))
68 (cond ((string= ebnf-syntax
'yacc
) "/*%s*/")
69 ((string= ebnf-syntax
'ebnf
) ";%s")
70 ((string= ebnf-syntax
'iso-ebnf
) "(*%s*)")
72 (format "EBNF error: format %s not supported."
74 (setq ebnf-eps-prefix dest-dir
)
75 (insert (format comment-format
(format "[%s" dest-root
)))
79 (insert (format comment-format
(format "]%s" dest-root
)))
81 (when style
(ebnf-pop-style))))
85 ;;; ob-ebnf.el ends here