X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/b373b41907150c91992d02976dfe32a7b4461800..1aaf8a45eea127b3213868db2d2cbb75e5c0e4b0:/lisp/progmodes/ebnf-yac.el diff --git a/lisp/progmodes/ebnf-yac.el b/lisp/progmodes/ebnf-yac.el index 7140091774..c7bf0e3154 100644 --- a/lisp/progmodes/ebnf-yac.el +++ b/lisp/progmodes/ebnf-yac.el @@ -1,12 +1,13 @@ ;;; ebnf-yac.el --- parser for Yacc/Bison -;; Copyright (C) 1999, 2000, 2001 Free Sofware Foundation, Inc. +;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 +;; Free Sofware Foundation, Inc. -;; Author: Vinicius Jose Latorre -;; Maintainer: Vinicius Jose Latorre +;; Author: Vinicius Jose Latorre +;; Maintainer: Vinicius Jose Latorre +;; Time-stamp: <2004/04/03 16:50:46 vinicius> ;; Keywords: wp, ebnf, PostScript -;; Time-stamp: <2002-07-09 11:43:10 jbarranquero> -;; Version: 1.2 +;; Version: 1.3 ;; This file is part of GNU Emacs. @@ -42,7 +43,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 +68,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. ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -93,7 +109,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Syntatic analyzer +;; Syntactic analyzer ;;; YACC = { YACC-Definitions }* "%%" { YACC-Rule }* [ "%%" [ YACC-Code ] ]. @@ -126,7 +142,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 +153,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 +167,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 +218,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 @@ -360,9 +374,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) @@ -491,4 +509,5 @@ See documentation for variable `ebnf-yac-lex'." (provide 'ebnf-yac) +;;; arch-tag: 8a96989c-0b1d-42ba-a020-b2901f9a2a4d ;;; ebnf-yac.el ends here