emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/emacs-23 r100200: * lisp/emacs-lisp/smie.el


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/emacs-23 r100200: * lisp/emacs-lisp/smie.el (smie-prec2->grammar): Obey equality constraints
Date: Thu, 11 Nov 2010 20:33:28 -0500
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 100200
committer: Stefan Monnier <address@hidden>
branch nick: emacs-23
timestamp: Thu 2010-11-11 20:33:28 -0500
message:
  * lisp/emacs-lisp/smie.el (smie-prec2->grammar): Obey equality constraints
  when filling the remaining "unconstrained" values.
modified:
  lisp/ChangeLog
  lisp/emacs-lisp/smie.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-11-11 22:19:01 +0000
+++ b/lisp/ChangeLog    2010-11-12 01:33:28 +0000
@@ -1,3 +1,8 @@
+2010-11-12  Stefan Monnier  <address@hidden>
+
+       * emacs-lisp/smie.el (smie-prec2->grammar): Obey equality constraints
+       when filling the remaining "unconstrained" values.
+
 2010-11-11  Stefan Monnier  <address@hidden>
 
        * emacs-lisp/bytecomp.el (byte-compile-warnings): Simplify the

=== modified file 'lisp/emacs-lisp/smie.el'
--- a/lisp/emacs-lisp/smie.el   2010-11-11 05:08:25 +0000
+++ b/lisp/emacs-lisp/smie.el   2010-11-12 01:33:28 +0000
@@ -74,11 +74,21 @@
 ;;   IF=ELSE and ELSE=END, we could turn them into IF<ELSE and ELSE>END
 ;;   and IF=END,
 
+;; TODO & BUGS:
+;;
+;; - FIXME: I think the behavior on empty lines is wrong.  It shouldn't
+;;   look at the next token on subsequent lines.
+;; - Using the structural information SMIE gives us, it should be possible to
+;;   implement a `smie-align' command that would automatically figure out what
+;;   there is to align and how to do it (something like: align the token of
+;;   lowest precedence that appears the same number of times on all lines,
+;;   and then do the same on each side of that token).
+;; - Maybe accept two juxtaposed non-terminals in the BNF under the condition
+;;   that the first always ends with a terminal, or that the second always
+;;   starts with a terminal.
+
 ;;; Code:
 
-;; FIXME: I think the behavior on empty lines is wrong.  It shouldn't
-;; look at the next token on subsequent lines.
-
 (eval-when-compile (require 'cl))
 
 (defgroup smie nil
@@ -401,6 +411,18 @@
      (append names (list (car names)))
      " < ")))
 
+;; (defun smie-check-grammar (grammar prec2 &optional dummy)
+;;   (maphash (lambda (k v)
+;;              (when (consp k)
+;;                (let ((left (nth 2 (assoc (car k) grammar)))
+;;                      (right (nth 1 (assoc (cdr k) grammar))))
+;;                  (when (and left right)
+;;                    (cond
+;;                     ((< left right) (assert (eq v '<)))
+;;                     ((> left right) (assert (eq v '>)))
+;;                     (t (assert (eq v '=))))))))
+;;            prec2))
+
 (put 'smie-prec2->grammar 'pure t)
 (defun smie-prec2->grammar (prec2)
   "Take a 2D precedence table and turn it into an alist of precedence levels.
@@ -469,6 +491,7 @@
               ;; left = right).
               (unless (caar cst)
                 (setcar (car cst) i)
+                ;; (smie-check-grammar table prec2 'step1)
                 (incf i))
               (setq csts (delq cst csts))))
           (unless progress
@@ -478,8 +501,19 @@
         (incf i 10))
       ;; Propagate equalities back to their source.
       (dolist (eq (nreverse eqs))
-        (assert (or (null (caar eq)) (eq (car eq) (cdr eq))))
-        (setcar (car eq) (cadr eq)))
+        (when (null (cadr eq))
+          ;; There's an equality constraint, but we still haven't given
+          ;; it a value: that means it binds tighter than anything else,
+          ;; and it can't be an opener/closer (those don't have equality
+          ;; constraints).
+          ;; So set it here rather than below since doing it below
+          ;; makes it more difficult to obey the equality constraints.
+          (setcar (cdr eq) i)
+          (incf i))
+        (assert (or (null (caar eq)) (eq (caar eq) (cadr eq))))
+        (setcar (car eq) (cadr eq))
+        ;; (smie-check-grammar table prec2 'step2)
+        )
       ;; Finally, fill in the remaining vars (which only appeared on the
       ;; right side of the < constraints).
       (let ((classification-table (gethash :smie-open/close-alist prec2)))
@@ -500,6 +534,7 @@
             (incf i)))))                ;See other (incf i) above.
     (let ((ca (gethash :smie-closer-alist prec2)))
       (when ca (push (cons :smie-closer-alist ca) table)))
+    ;; (smie-check-grammar table prec2 'step3)
     table))
 
 ;;; Parsing using a precedence level table.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]