Sync to HEAD
[bpt/emacs.git] / lisp / progmodes / ebnf-yac.el
index 4aa7fb1..c7bf0e3 100644 (file)
@@ -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 <vinicius@cpqd.com.br>
-;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br>
+;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
+;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
+;; Time-stamp: <2004/04/03 16:50:46 vinicius>
 ;; Keywords: wp, ebnf, PostScript
-;; Time-stamp: <2003-02-10 10:47:04 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"
 ;;                  .
 ;;
 ;; 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 <junker@alum.mit.edu> for the suggestion to deal
+;; with %right, %left and %prec pragmas.  His suggestion was extended to deal
+;; with %nonassoc pragma too.
 ;;
 ;;
 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     syntax-list))
 
 
-;;; YACC-Definitions = "%token" [ "<" Name ">" ] Name-List
+;;; YACC-Definitions = ( "%token" | "%left" | "%right" | "%nonassoc" )
+;;;                    [ "<" Name ">" ] Name-List
+;;;                  | "%prec" Name
 ;;;                  | "any other Yacc definition"
 ;;;                  .
 
     (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)
                    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))
             )))
                 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