1 ;;; ob-ebnf.el --- Babel Functions for EBNF -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2013-2017 Free Software Foundation, Inc.
5 ;; Author: Michael Gauland
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs 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 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs 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. If not, see <https://www.gnu.org/licenses/>.
27 ;;; Org-Babel support for using ebnf2ps to generate encapsulated postscript
28 ;;; railroad diagrams. It recognizes these arguments:
30 ;;; :file is required; it must include the extension '.eps.' All the rules
31 ;;; in the block will be drawn in the same file. This is done by
32 ;;; inserting a '[<file>' comment at the start of the block (see the
33 ;;; documentation for ebnf-eps-buffer for more information).
35 ;;; :style specifies a value in ebnf-style-database. This provides the
36 ;;; ability to customize the output. The style can also specify the
37 ;;; grammar syntax (by setting ebnf-syntax); note that only ebnf,
38 ;;; iso-ebnf, and yacc are supported by this file.
46 ;; optionally declare default header arguments for this language
47 (defvar org-babel-default-header-args
:ebnf
'((:style . nil
)))
49 ;; Use ebnf-eps-buffer to produce an encapsulated postscript file.
51 (defun org-babel-execute:ebnf
(body params
)
52 "Execute a block of Ebnf code with org-babel. This function is
53 called by `org-babel-execute-src-block'"
55 (let* ((dest-file (cdr (assq :file params
)))
56 (dest-dir (file-name-directory dest-file
))
57 (dest-root (file-name-sans-extension
58 (file-name-nondirectory dest-file
)))
59 (style (cdr (assq :style params
)))
62 (when style
(ebnf-push-style style
))
64 (cond ((string= ebnf-syntax
'yacc
) "/*%s*/")
65 ((string= ebnf-syntax
'ebnf
) ";%s")
66 ((string= ebnf-syntax
'iso-ebnf
) "(*%s*)")
68 (format "EBNF error: format %s not supported."
70 (setq ebnf-eps-prefix dest-dir
)
71 (insert (format comment-format
(format "[%s" dest-root
)))
75 (insert (format comment-format
(format "]%s" dest-root
)))
77 (when style
(ebnf-pop-style))))
81 ;;; ob-ebnf.el ends here