X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/984ae001715c945ef1e81fba2d80607f486332f2..199143f1fbc4f791ba20405ed1767e1cac099066:/lisp/progmodes/ebnf-iso.el diff --git a/lisp/progmodes/ebnf-iso.el b/lisp/progmodes/ebnf-iso.el index 2008685a78..f36065bd55 100644 --- a/lisp/progmodes/ebnf-iso.el +++ b/lisp/progmodes/ebnf-iso.el @@ -1,21 +1,22 @@ -;;; ebnf-iso --- Parser for ISO EBNF +;;; ebnf-iso.el --- parser for ISO EBNF -;; Copyright (C) 1999 Vinicius Jose Latorre +;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 +;; Free Software Foundation, Inc. -;; Author: Vinicius Jose Latorre -;; Maintainer: Vinicius Jose Latorre -;; Keywords: wp, ebnf, PostScript -;; Time-stamp: <99/11/20 18:04:11 vinicius> -;; Version: 1.4 +;; Author: Vinicius Jose Latorre +;; Maintainer: Vinicius Jose Latorre +;; Time-stamp: <2004/04/03 16:48:52 vinicius> +;; Keywords: wp, ebnf, PostScript +;; Version: 1.8 -;; This file is *NOT* (yet?) part of GNU Emacs. +;; This file is part of GNU Emacs. -;; This program is free software; you can redistribute it and/or modify +;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. -;; This program is distributed in the hope that it will be useful, +;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. @@ -112,12 +113,13 @@ ;; ISO EBNF accepts the characters given by production above, ;; HORIZONTAL TAB (^I), VERTICAL TAB (^K), NEWLINE (^J or ^M) and FORM FEED ;; (^L), any other characters are illegal. But ebnf2ps accepts also the -;; european 8-bit accentuated characters (from \240 to \377). +;; european 8-bit accentuated characters (from \240 to \377) and underscore +;; (_). ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; code: +;;; Code: (require 'ebnf-otz) @@ -127,11 +129,12 @@ "Value returned by `ebnf-iso-lex' function.") -(defconst ebnf-no-meta-identifier nil) +(defvar ebnf-no-meta-identifier nil + "Used by `ebnf-iso-term' and `ebnf-iso-lex' functions.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Syntatic analyzer +;; Syntactic analyzer ;;; ISO EBNF = syntax rule, {syntax rule}; @@ -145,7 +148,7 @@ (goto-char start) (setq token (ebnf-iso-lex)) (and (eq token 'end-of-input) - (error "Invalid ISO EBNF file format.")) + (error "Invalid ISO EBNF file format")) (while (not (eq token 'end-of-input)) (ebnf-message-float "Parsing...%s%%" @@ -167,12 +170,12 @@ body) (setq ebnf-action nil) (or (eq token 'non-terminal) - (error "Invalid meta identifier syntax rule.")) + (error "Invalid meta identifier syntax rule")) (or (eq (ebnf-iso-lex) 'equal) - (error "Invalid syntax rule: missing `='.")) + (error "Invalid syntax rule: missing `='")) (setq body (ebnf-iso-definition-list)) (or (eq (car body) 'period) - (error "Invalid syntax rule: missing `;' or `.'.")) + (error "Invalid syntax rule: missing `;' or `.'")) (setq body (cdr body)) (ebnf-eps-add-production header) (cons (ebnf-iso-lex) @@ -200,17 +203,9 @@ (eq token 'catenate)) (setq seq (cons term seq))) (cons token - (cond - ;; null sequence - ((null seq) - term) - ;; sequence with only one element - ((and (null term) (= (length seq) 1)) - (car seq)) - ;; a real sequence - (t - (ebnf-make-sequence (nreverse (cons term seq)))) - )))) + (ebnf-token-sequence (if term + (cons term seq) + seq))))) ;;; term = factor, ['-', exception]; @@ -233,7 +228,7 @@ (if (eq token 'integer) (let ((times ebnf-iso-lex)) (or (eq (ebnf-iso-lex) 'repeat) - (error "Missing `*'.")) + (error "Missing `*'")) (ebnf-token-repeat times (ebnf-iso-primary (ebnf-iso-lex)))) (ebnf-iso-primary token))) @@ -273,20 +268,20 @@ ((eq token 'begin-group) (let ((body (ebnf-iso-definition-list))) (or (eq (car body) 'end-group) - (error "Missing `)'.")) + (error "Missing `)'")) (cdr body))) ;; optional sequence ((eq token 'begin-optional) (let ((body (ebnf-iso-definition-list))) (or (eq (car body) 'end-optional) - (error "Missing `]' or `/)'.")) + (error "Missing `]' or `/)'")) (ebnf-token-optional (cdr body)))) ;; repeated sequence ((eq token 'begin-zero-or-more) (let* ((body (ebnf-iso-definition-list)) (repeat (cdr body))) (or (eq (car body) 'end-zero-or-more) - (error "Missing `}' or `:)'.")) + (error "Missing `}' or `:)'")) (ebnf-make-zero-or-more repeat))) ;; empty (t @@ -345,6 +340,7 @@ ;; Override form feed character: (aset table ?\f 'form-feed) ; [FF] form feed ;; Override other lexical characters: + (aset table ?_ 'non-terminal) (aset table ?\" 'double-terminal) (aset table ?\' 'single-terminal) (aset table ?\? 'special) @@ -387,6 +383,11 @@ (aset ebnf-iso-token-table ?. 'character))) +;; replace the range "\240-\377" (see `ebnf-range-regexp'). +(defconst ebnf-iso-non-terminal-chars + (ebnf-range-regexp " 0-9A-Za-z_" ?\240 ?\377)) + + (defun ebnf-iso-lex () "Lexical analyser for ISO EBNF. @@ -426,16 +427,16 @@ See documentation for variable `ebnf-iso-lex'." 'end-of-input) ;; error ((eq token 'error) - (error "Illegal character.")) + (error "Illegal character")) ;; integer ((eq token 'integer) (setq ebnf-iso-lex (ebnf-buffer-substring "0-9")) 'integer) ;; special: ?special? ((eq token 'special) - (setq ebnf-iso-lex (concat "?" + (setq ebnf-iso-lex (concat (and ebnf-special-show-delimiter "?") (ebnf-string " ->@-~" ?\? "special") - "?")) + (and ebnf-special-show-delimiter "?"))) 'special) ;; terminal: "string" ((eq token 'double-terminal) @@ -447,11 +448,12 @@ See documentation for variable `ebnf-iso-lex'." 'terminal) ;; non-terminal ((eq token 'non-terminal) - (setq ebnf-iso-lex (ebnf-iso-normalize - (ebnf-trim-right - (ebnf-buffer-substring " 0-9A-Za-z\240-\377")))) + (setq ebnf-iso-lex + (ebnf-iso-normalize + (ebnf-trim-right + (ebnf-buffer-substring ebnf-iso-non-terminal-chars)))) (and ebnf-no-meta-identifier - (error "Exception sequence should not contain a meta identifier.")) + (error "Exception sequence should not contain a meta identifier")) 'non-terminal) ;; begin optional, begin list or begin group ((eq token 'left-parenthesis) @@ -489,7 +491,9 @@ See documentation for variable `ebnf-iso-lex'." )))) -(defconst ebnf-iso-comment-chars "^*(\000-\010\016-\037\177-\237") +;; replace the range "\177-\237" (see `ebnf-range-regexp'). +(defconst ebnf-iso-comment-chars + (ebnf-range-regexp "^*(\000-\010\016-\037" ?\177 ?\237)) (defun ebnf-iso-skip-comment () @@ -509,7 +513,7 @@ See documentation for variable `ebnf-iso-lex'." (while (> pair 0) (skip-chars-forward ebnf-iso-comment-chars ebnf-limit) (cond ((>= (point) ebnf-limit) - (error "Missing end of comment: `*)'.")) + (error "Missing end of comment: `*)'")) ((= (following-char) ?*) (skip-chars-forward "*" ebnf-limit) (when (= (following-char) ?\)) @@ -523,7 +527,7 @@ See documentation for variable `ebnf-iso-lex'." (forward-char) (setq pair (1+ pair)))) (t - (error "Illegal character.")) + (error "Illegal character")) )))) @@ -604,4 +608,5 @@ See documentation for variable `ebnf-iso-lex'." (provide 'ebnf-iso) +;;; arch-tag: 03315eef-8f64-404a-bf9d-256d42442ee3 ;;; ebnf-iso.el ends here