X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/ae16d111d8e4eb2aea52d94103b76e9f31ebcb52..f4ff3e5cc0e873be609cf6172386c56587a83f31:/lisp/progmodes/ebnf-yac.el diff --git a/lisp/progmodes/ebnf-yac.el b/lisp/progmodes/ebnf-yac.el index bff241a5e4..c1b00bdddf 100644 --- a/lisp/progmodes/ebnf-yac.el +++ b/lisp/progmodes/ebnf-yac.el @@ -1,18 +1,18 @@ ;;; ebnf-yac.el --- parser for Yacc/Bison -;; Copyright (C) 1999, 2000, 2001 Free Sofware Foundation, Inc. +;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 +;; Free Software Foundation, Inc. -;; Author: Vinicius Jose Latorre -;; Maintainer: Vinicius Jose Latorre +;; Author: Vinicius Jose Latorre +;; Maintainer: Vinicius Jose Latorre ;; Keywords: wp, ebnf, PostScript -;; Time-stamp: <2001/08/15 17:15:15 vinicius> -;; Version: 1.1 +;; Version: 1.4 ;; This file is part of GNU Emacs. ;; 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) +;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, @@ -22,8 +22,8 @@ ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. ;;; Commentary: @@ -42,7 +42,9 @@ ;; ;; YACC = { YACC-Definitions }* "%%" { YACC-Rule }* [ "%%" [ YACC-Code ] ]. ;; -;; YACC-Definitions = "%token" [ "<" Name ">" ] Name-List +;; YACC-Definitions = ( "%token" | "%left" | "%right" | "%nonassoc" ) +;; [ "<" Name ">" ] Name-List +;; | "%prec" Name ;; | "any other Yacc definition" ;; . ;; @@ -65,7 +67,20 @@ ;; Name = "[A-Za-z][A-Za-z0-9_.]*". ;; ;; Comment = "/*" "any character, but the sequence \"*/\"" "*/" -;; | "//" "any character" "\\n". +;; | "//" "any character, but the newline \"\\n\"" "\\n". +;; +;; +;; In other words, a valid Name begins with a letter (upper or lower case) +;; followed by letters, decimal digits, underscore (_) or point (.). For +;; example: this_is_a_valid.name, Another_EXAMPLE, mIxEd.CaSe. +;; +;; +;; Acknowledgements +;; ---------------- +;; +;; Thanks to Matthew K. Junker for the suggestion to deal +;; with %right, %left and %prec pragmas. His suggestion was extended to deal +;; with %nonassoc pragma too. ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -89,11 +104,11 @@ (defvar ebnf-yac-error nil - "Non-nil means \"error\" occured.") + "Non-nil means \"error\" occurred.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Syntatic analyzer +;; Syntactic analyzer ;;; YACC = { YACC-Definitions }* "%%" { YACC-Rule }* [ "%%" [ YACC-Code ] ]. @@ -126,7 +141,9 @@ syntax-list)) -;;; YACC-Definitions = "%token" [ "<" Name ">" ] Name-List +;;; YACC-Definitions = ( "%token" | "%left" | "%right" | "%nonassoc" ) +;;; [ "<" Name ">" ] Name-List +;;; | "%prec" Name ;;; | "any other Yacc definition" ;;; . @@ -135,7 +152,8 @@ (while (not (memq token '(yac-separator end-of-input))) (setq token (cond - ;; "%token" [ "<" Name ">" ] Name-List + ;; ( "%token" | "%left" | "%right" | "%nonassoc" ) + ;; [ "<" Name ">" ] Name-List ((eq token 'yac-token) (setq token (ebnf-yac-lex)) (when (eq token 'open-angle) @@ -148,7 +166,12 @@ ebnf-yac-token-list (nconc (cdr token) ebnf-yac-token-list)) (car token)) - ;; "any other Yacc definition" + ;; "%prec" Name + ((eq token 'yac-prec) + (or (eq (ebnf-yac-lex) 'non-terminal) + (error "Missing prec name")) + (ebnf-yac-lex)) + ;; "any other Yacc definition" (t (ebnf-yac-lex)) ))) @@ -194,20 +217,10 @@ factor (ebnf-yac-factor token)) (setq seq (cons factor seq))) (cons token - (cond - ;; ignore error recovery - ((and ebnf-yac-ignore-error-recovery ebnf-yac-error) - nil) - ;; null sequence - ((null seq) - (ebnf-make-empty)) - ;; sequence with only one element - ((= (length seq) 1) - (car seq)) - ;; a real sequence - (t - (ebnf-make-sequence (nreverse seq))) - )))) + (if (and ebnf-yac-ignore-error-recovery ebnf-yac-error) + ;; ignore error recovery + nil + (ebnf-token-sequence seq))))) ;;; Factor = Name @@ -298,7 +311,7 @@ (defun ebnf-yac-lex () - "Lexical analyser for Yacc/Bison. + "Lexical analyzer for Yacc/Bison. Return a lexical token. @@ -332,7 +345,7 @@ See documentation for variable `ebnf-yac-lex'." 'end-of-input) ;; error ((eq token 'error) - (error "Illegal character")) + (error "Invalid character")) ;; "string" ((eq token 'string) (setq ebnf-yac-lex (ebnf-get-string)) @@ -360,9 +373,13 @@ See documentation for variable `ebnf-yac-lex'." ((eq (following-char) ?%) (forward-char) 'yac-separator) - ;; %TOKEN - ((string= (upcase (ebnf-buffer-substring "0-9A-Za-z_")) "TOKEN") - 'yac-token) + ;; %TOKEN, %RIGHT, %LEFT, %PREC, %NONASSOC + ((cdr (assoc (upcase (ebnf-buffer-substring "0-9A-Za-z_")) + '(("TOKEN" . yac-token) + ("RIGHT" . yac-token) + ("LEFT" . yac-token) + ("NONASSOC" . yac-token) + ("PREC" . yac-prec))))) ;; other Yacc pragmas (t 'yac-pragma) @@ -383,14 +400,16 @@ See documentation for variable `ebnf-yac-lex'." (< (point) ebnf-limit)) +;; replace the range "\177-\377" (see `ebnf-range-regexp'). +(defconst ebnf-yac-skip-chars + (ebnf-range-regexp "^{}/'\"\000-\010\013\016-\037" ?\177 ?\377)) + + (defun ebnf-yac-skip-code () (forward-char) (let ((pair 1)) (while (> pair 0) - ;; replace the range "\177-\377" (see `ebnf-range-regexp'). - (skip-chars-forward (ebnf-range-regexp "^{}/'\"\000-\010\013\016-\037" - ?\177 ?\377) - ebnf-limit) + (skip-chars-forward ebnf-yac-skip-chars ebnf-limit) (cond ((= (following-char) ?{) (forward-char) @@ -405,7 +424,7 @@ See documentation for variable `ebnf-yac-lex'." ((= (following-char) ?\') (ebnf-string " -&(-~" ?\' "character")) (t - (error "Illegal character")) + (error "Invalid character")) ))) (ebnf-yac-skip-spaces)) @@ -440,6 +459,12 @@ See documentation for variable `ebnf-yac-lex'." ;; close EPS file ((and ebnf-eps-executing (= (following-char) ?\])) (ebnf-eps-remove-context (ebnf-yac-eps-filename))) + ;; EPS header + ((and ebnf-eps-executing (= (following-char) ?H)) + (ebnf-eps-header-comment (ebnf-yac-eps-filename))) + ;; EPS footer + ((and ebnf-eps-executing (= (following-char) ?F)) + (ebnf-eps-footer-comment (ebnf-yac-eps-filename))) ;; any other action in comment (t (setq ebnf-action (aref ebnf-comment-table (following-char)))) @@ -456,7 +481,7 @@ See documentation for variable `ebnf-yac-lex'." (forward-char) (setq not-end nil))) (t - (error "Illegal character")) + (error "Invalid character")) )))) @@ -489,4 +514,5 @@ See documentation for variable `ebnf-yac-lex'." (provide 'ebnf-yac) +;;; arch-tag: 8a96989c-0b1d-42ba-a020-b2901f9a2a4d ;;; ebnf-yac.el ends here